From 62a8b65fa57daa0ab0dfa832b9c2a233d2c5a820 Mon Sep 17 00:00:00 2001 From: SirHall Date: Thu, 29 Dec 2022 15:54:29 +1000 Subject: [PATCH 1/6] Setup `physical_tile_size` that allows controlling how large the tile's will be rendered in-world, leaving `tile_size` to only specify the tile size in the source atlas --- examples/bench.rs | 13 +++++++- src/helpers/transform.rs | 5 ++-- src/lib.rs | 3 +- src/map.rs | 55 ++++++++++++++++++++++++++++++++-- src/render/chunk.rs | 25 +++++++++++++--- src/render/extract.rs | 43 +++++++++++++++----------- src/render/prepare.rs | 7 ++++- src/render/shaders/common.wgsl | 3 +- src/render/shaders/square.wgsl | 5 ++-- 9 files changed, 127 insertions(+), 32 deletions(-) diff --git a/examples/bench.rs b/examples/bench.rs index 3b3f9ffe..4022d47b 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -23,8 +23,18 @@ fn startup(mut commands: Commands, asset_server: Res) { &mut tile_storage, ); + let physical_size = 8.0; + let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; - let grid_size = tile_size.into(); + let grid_size = TilemapGridSize { + x: physical_size, + y: physical_size, + }; + let physical_tile_size = TilemapPhysicalTileSize { + x: physical_size, + y: physical_size, + }; + println!("{:#?}", grid_size); let map_type = TilemapType::default(); commands.entity(tilemap_entity).insert(TilemapBundle { @@ -34,6 +44,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), render_settings: TilemapRenderSettings { render_chunk_size: UVec2::new(256, 256), diff --git a/src/helpers/transform.rs b/src/helpers/transform.rs index 4d1cfe25..a1fb9b35 100644 --- a/src/helpers/transform.rs +++ b/src/helpers/transform.rs @@ -1,3 +1,4 @@ +use crate::prelude::TilemapPhysicalTileSize; use crate::tiles::TilePos; use crate::{TilemapGridSize, TilemapTileSize, TilemapType}; use bevy::math::{UVec2, Vec2, Vec3}; @@ -29,11 +30,11 @@ pub fn chunk_index_to_world_space( pub fn chunk_aabb( chunk_size: UVec2, grid_size: &TilemapGridSize, - tile_size: &TilemapTileSize, + physical_tile_size: &TilemapPhysicalTileSize, map_type: &TilemapType, ) -> Aabb { // The AABB minimum and maximum have to be modified by -border and +border respectively. - let border = Vec2::from(grid_size).max(tile_size.into()); + let border = Vec2::from(grid_size).max(physical_tile_size.into()); // For most map types, it would be sufficient to calculate c0 and c3. However, for some map // types (right now, isometric diamond), this would not work, and for robustness (especially diff --git a/src/lib.rs b/src/lib.rs index 4783bd08..2122dc16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ use map::{ TilemapGridSize, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, TilemapTileSize, TilemapType, }; -use prelude::{TilemapId, TilemapRenderSettings}; +use prelude::{TilemapId, TilemapRenderSettings, TilemapPhysicalTileSize}; #[cfg(feature = "render")] use render::material::{MaterialTilemap, StandardTilemapMaterial}; use tiles::{ @@ -120,6 +120,7 @@ pub struct MaterialTilemapBundle { pub storage: TileStorage, pub texture: TilemapTexture, pub tile_size: TilemapTileSize, + pub physical_tile_size: TilemapPhysicalTileSize, pub transform: Transform, pub global_transform: GlobalTransform, pub render_settings: TilemapRenderSettings, diff --git a/src/map.rs b/src/map.rs index bb25f9e9..079c9b9d 100644 --- a/src/map.rs +++ b/src/map.rs @@ -276,12 +276,63 @@ impl From<&TilemapTileSize> for Vec2 { } impl From for TilemapTileSize { - fn from(v: Vec2) -> Self { - let Vec2 { x, y } = v; + fn from(Vec2 { x, y }: Vec2) -> Self { TilemapTileSize { x, y } } } +/// Physical size of the tiles in units when rendered in-world +#[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq)] +pub struct TilemapPhysicalTileSize { + pub x: f32, + pub y: f32, +} + +impl From for TilemapGridSize { + fn from(tile_size: TilemapPhysicalTileSize) -> Self { + TilemapGridSize { + x: tile_size.x, + y: tile_size.y, + } + } +} + +impl From for Vec2 { + fn from(tile_size: TilemapPhysicalTileSize) -> Self { + Vec2::new(tile_size.x, tile_size.y) + } +} + +impl From<&TilemapPhysicalTileSize> for Vec2 { + fn from(tile_size: &TilemapPhysicalTileSize) -> Self { + Vec2::new(tile_size.x, tile_size.y) + } +} + +impl From for TilemapPhysicalTileSize { + fn from(Vec2 { x, y }: Vec2) -> Self { + Self { x, y } + } +} + +impl From for TilemapPhysicalTileSize { + fn from(tile_size: TilemapTileSize) -> Self { + Self { + x: tile_size.x, + y: tile_size.y, + } + } +} + +impl From<&TilemapTileSize> for TilemapPhysicalTileSize { + fn from(tile_size: &TilemapTileSize) -> Self { + Self { + x: tile_size.x, + y: tile_size.y, + } + } +} + /// Size of the tiles on the grid in pixels. /// This can be used to overlay tiles on top of each other. /// Ex. A 16x16 pixel tile can be overlapped by 8 pixels by using diff --git a/src/render/chunk.rs b/src/render/chunk.rs index 93319f58..f2cfd8c1 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -18,7 +18,7 @@ use bevy::{ render::mesh::MeshVertexBufferLayouts, }; -use crate::prelude::helpers::transform::{chunk_aabb, chunk_index_to_world_space}; +use crate::prelude::helpers::transform::{chunk_aabb, chunk_index_to_world_space,TilemapPhysicalTileSize}; use crate::render::extract::ExtractedFrustum; use crate::{ map::{TilemapSize, TilemapTexture, TilemapType}, @@ -49,6 +49,7 @@ impl RenderChunk2dStorage { chunk_size: UVec2, mesh_type: TilemapType, tile_size: TilemapTileSize, + physical_tile_size: TilemapPhysicalTileSize, texture_size: Vec2, spacing: Vec2, grid_size: TilemapGridSize, @@ -86,6 +87,7 @@ impl RenderChunk2dStorage { chunk_size, mesh_type, tile_size, + physical_tile_size, spacing, grid_size, texture, @@ -199,6 +201,8 @@ pub struct RenderChunk2d { pub grid_size: TilemapGridSize, /// The tile size of the map this chunk belongs to. pub tile_size: TilemapTileSize, + /// The physical tile size of the map this chunk belongs to. + pub physical_tile_size: TilemapPhysicalTileSize, /// The [`Aabb`] of this chunk, based on the map type, grid size, and tile size. It is not /// transformed by the `global_transform` or [`local_transform`] aabb: Aabb, @@ -231,6 +235,7 @@ impl RenderChunk2d { size_in_tiles: UVec2, map_type: TilemapType, tile_size: TilemapTileSize, + physical_tile_size: TilemapPhysicalTileSize, spacing: Vec2, grid_size: TilemapGridSize, texture: TilemapTexture, @@ -247,7 +252,7 @@ impl RenderChunk2d { let global_transform: Transform = global_transform.into(); let transform = local_transform * global_transform; let transform_matrix = transform.compute_matrix(); - let aabb = chunk_aabb(size_in_tiles, &grid_size, &tile_size, &map_type); + let aabb = chunk_aabb(size_in_tiles, &grid_size, &physical_tile_size, &map_type); Self { dirty_mesh: true, gpu_mesh: None, @@ -259,6 +264,7 @@ impl RenderChunk2d { map_type, grid_size, tile_size, + physical_tile_size, aabb, local_transform, global_transform, @@ -319,14 +325,20 @@ impl RenderChunk2d { global_transform: Transform, grid_size: TilemapGridSize, tile_size: TilemapTileSize, + physical_tile_size: TilemapPhysicalTileSize, map_type: TilemapType, ) { let mut dirty_local_transform = false; - if self.grid_size != grid_size || self.tile_size != tile_size || self.map_type != map_type { + if self.grid_size != grid_size + || self.tile_size != tile_size + || self.physical_tile_size != physical_tile_size + || self.map_type != map_type + { self.grid_size = grid_size; self.map_type = map_type; self.tile_size = tile_size; + self.physical_tile_size = physical_tile_size; self.position = chunk_index_to_world_space( self.index.xy(), @@ -341,7 +353,7 @@ impl RenderChunk2d { self.aabb = chunk_aabb( self.size_in_tiles, &self.grid_size, - &self.tile_size, + &self.physical_tile_size, &self.map_type, ); } @@ -474,6 +486,7 @@ impl RenderChunk2d { pub struct TilemapUniformData { pub texture_size: Vec2, pub tile_size: Vec2, + pub physical_tile_size: Vec2, pub grid_size: Vec2, pub spacing: Vec2, pub chunk_pos: Vec2, @@ -488,9 +501,11 @@ impl From<&RenderChunk2d> for TilemapUniformData { let chunk_size: Vec2 = chunk.size_in_tiles.as_vec2(); let map_size: Vec2 = chunk.map_size.into(); let tile_size: Vec2 = chunk.tile_size.into(); + let physical_tile_size: Vec2 = chunk.physical_tile_size.into(); Self { texture_size: chunk.texture_size, tile_size, + physical_tile_size, grid_size: chunk.grid_size.into(), spacing: chunk.spacing, chunk_pos: chunk_ix * chunk_size, @@ -507,9 +522,11 @@ impl From<&mut RenderChunk2d> for TilemapUniformData { let chunk_size: Vec2 = chunk.size_in_tiles.as_vec2(); let map_size: Vec2 = chunk.map_size.into(); let tile_size: Vec2 = chunk.tile_size.into(); + let physical_tile_size: Vec2 = chunk.physical_tile_size.into(); Self { texture_size: chunk.texture_size, tile_size, + physical_tile_size, grid_size: chunk.grid_size.into(), spacing: chunk.spacing, chunk_pos: chunk_pos * chunk_size, diff --git a/src/render/extract.rs b/src/render/extract.rs index 06fd69a6..4cfd657a 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -5,7 +5,7 @@ use bevy::render::render_resource::TextureFormat; use bevy::{prelude::*, render::Extract, utils::HashMap}; use crate::prelude::TilemapGridSize; -use crate::prelude::TilemapRenderSettings; +use crate::prelude::{TilemapPhysicalTileSize, TilemapRenderSettings}; use crate::render::{DefaultSampler, SecondsSinceStartup}; use crate::tiles::AnimatedTile; use crate::tiles::TilePosOld; @@ -59,6 +59,7 @@ pub struct ExtractedRemovedMapBundle { pub struct ExtractedTilemapBundle { transform: GlobalTransform, tile_size: TilemapTileSize, + physical_tile_size: TilemapPhysicalTileSize, grid_size: TilemapGridSize, texture_size: TilemapTextureSize, spacing: TilemapSpacing, @@ -213,6 +214,7 @@ pub fn extract( Entity, &GlobalTransform, &TilemapTileSize, + &TilemapPhysicalTileSize, &TilemapSpacing, &TilemapGridSize, &TilemapType, @@ -232,6 +234,7 @@ pub fn extract( Changed, Changed, Changed, + Changed, Changed, Changed, Changed, @@ -294,15 +297,16 @@ pub fn extract( ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, + physical_tile_size: *data.3, texture_size: TilemapTextureSize::default(), - spacing: *data.3, - grid_size: *data.4, - map_type: *data.5, - texture: data.6.clone_weak(), - map_size: *data.7, - visibility: *data.8, - frustum_culling: *data.9, - render_settings: *data.10, + spacing: *data.4, + grid_size: *data.5, + map_type: *data.6, + texture: data.7.clone_weak(), + map_size: *data.8, + visibility: *data.9, + frustum_culling: *data.10, + render_settings: *data.11, }, ), ); @@ -330,15 +334,16 @@ pub fn extract( ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, + physical_tile_size: *data.3, texture_size: TilemapTextureSize::default(), - spacing: *data.3, - grid_size: *data.4, - map_type: *data.5, - texture: data.6.clone_weak(), - map_size: *data.7, - visibility: *data.8, - frustum_culling: *data.9, - render_settings: *data.10, + spacing: *data.4, + grid_size: *data.5, + map_type: *data.6, + texture: data.7.clone_weak(), + map_size: *data.8, + visibility: *data.9, + frustum_culling: *data.10, + render_settings: *data.11, }, ), ); @@ -349,7 +354,9 @@ pub fn extract( extracted_tilemaps.drain().map(|kv| kv.1).collect(); // Extracts tilemap textures. - for (entity, _, tile_size, tile_spacing, _, _, texture, _, _, _, _) in tilemap_query.iter() { + for (entity, _, tile_size, _physical_tile_size, tile_spacing, _, _, texture, _, _, _, _) in + tilemap_query.iter() + { if texture.verify_ready(&images) { extracted_tilemap_textures.push(( entity, diff --git a/src/render/prepare.rs b/src/render/prepare.rs index afdb602f..79db5327 100644 --- a/src/render/prepare.rs +++ b/src/render/prepare.rs @@ -4,7 +4,7 @@ use crate::map::{ TilemapId, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, TilemapTileSize, TilemapType, }; -use crate::prelude::TilemapRenderSettings; +use crate::prelude::{TilemapRenderSettings,TilemapPhysicalTileSize}; use crate::render::extract::ExtractedFrustum; use crate::{ prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling, @@ -48,6 +48,7 @@ pub(crate) fn prepare( Entity, &GlobalTransform, &TilemapTileSize, + &TilemapPhysicalTileSize, &TilemapTextureSize, &TilemapSpacing, &TilemapGridSize, @@ -75,6 +76,7 @@ pub(crate) fn prepare( _entity, transform, tile_size, + physical_tile_size, texture_size, spacing, grid_size, @@ -104,6 +106,7 @@ pub(crate) fn prepare( *chunk_size, *mesh_type, *tile_size, + *physical_tile_size, (*texture_size).into(), (*spacing).into(), *grid_size, @@ -133,6 +136,7 @@ pub(crate) fn prepare( entity, global_transform, tile_size, + physical_tile_size, texture_size, spacing, grid_size, @@ -156,6 +160,7 @@ pub(crate) fn prepare( (*global_transform).into(), *grid_size, *tile_size, + *physical_tile_size, *map_type, ); } diff --git a/src/render/shaders/common.wgsl b/src/render/shaders/common.wgsl index e9a17971..4971c0c9 100644 --- a/src/render/shaders/common.wgsl +++ b/src/render/shaders/common.wgsl @@ -11,12 +11,13 @@ var mesh: Mesh; struct TilemapData { texture_size: vec2, tile_size: vec2, + physical_tile_size: vec2, grid_size: vec2, spacing: vec2, chunk_pos: vec2, map_size: vec2, time: f32, - _padding: vec3, // hack for webgl2 16 byte alignment + _padding: f32, // hack for webgl2 16 byte alignment }; @group(1) @binding(1) var tilemap_data: TilemapData; diff --git a/src/render/shaders/square.wgsl b/src/render/shaders/square.wgsl index af228dbe..aea13412 100644 --- a/src/render/shaders/square.wgsl +++ b/src/render/shaders/square.wgsl @@ -6,8 +6,9 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = vertex_position.xy * tilemap_data.grid_size; - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let offset = 0.5 * tilemap_data.physical_tile_size; + let bot_left = center - offset; + let top_right = center + offset; var positions = array, 4>( bot_left, From 513a0335686bd47dad5a90ff474d5fd8c4526584 Mon Sep 17 00:00:00 2001 From: SirHall Date: Thu, 29 Dec 2022 16:10:06 +1000 Subject: [PATCH 2/6] Update examples to use new `physical_tile_size` field, and add new `custom_tile_scaling.rs` example to demonstrate it --- examples/accessing_tiles.rs | 1 + examples/animation.rs | 1 + examples/basic.rs | 1 + examples/bench.rs | 14 ++----- examples/chunking.rs | 1 + examples/colors.rs | 1 + examples/custom_tile_scaling.rs | 69 +++++++++++++++++++++++++++++++++ examples/frustum_cull_test.rs | 1 + examples/game_of_life.rs | 1 + examples/helpers/tiled.rs | 1 + examples/hex_neighbors.rs | 1 + examples/hexagon_column.rs | 1 + examples/hexagon_generation.rs | 1 + examples/hexagon_row.rs | 1 + examples/iso_diamond.rs | 1 + examples/iso_staggered.rs | 1 + examples/layers.rs | 2 + examples/mouse_to_tile.rs | 1 + examples/move_tile.rs | 1 + examples/random_map.rs | 1 + examples/remove_tiles.rs | 1 + examples/spacing.rs | 2 + examples/texture_container.rs | 1 + examples/texture_vec.rs | 1 + examples/visibility.rs | 1 + 25 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 examples/custom_tile_scaling.rs diff --git a/examples/accessing_tiles.rs b/examples/accessing_tiles.rs index 16929c40..8a85ed2a 100644 --- a/examples/accessing_tiles.rs +++ b/examples/accessing_tiles.rs @@ -90,6 +90,7 @@ fn startup(mut commands: Commands, asset_server: Res) { map_type, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/animation.rs b/examples/animation.rs index 59ff5c20..eacffe55 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -58,6 +58,7 @@ fn create_background(mut commands: Commands, asset_server: Res) { grid_size, map_type, tile_size, + physical_tile_size: tile_size.into(), storage: tile_storage, texture: TilemapTexture::Single(texture_handle), transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 0.0), diff --git a/examples/basic.rs b/examples/basic.rs index b9a2868e..73545b85 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -56,6 +56,7 @@ fn startup( storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/bench.rs b/examples/bench.rs index 4022d47b..f4318634 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -23,17 +23,9 @@ fn startup(mut commands: Commands, asset_server: Res) { &mut tile_storage, ); - let physical_size = 8.0; - let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; - let grid_size = TilemapGridSize { - x: physical_size, - y: physical_size, - }; - let physical_tile_size = TilemapPhysicalTileSize { - x: physical_size, - y: physical_size, - }; + let grid_size = tile_size.into(); + println!("{:#?}", grid_size); let map_type = TilemapType::default(); @@ -44,7 +36,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), render_settings: TilemapRenderSettings { render_chunk_size: UVec2::new(256, 256), diff --git a/examples/chunking.rs b/examples/chunking.rs index c289ffc6..2e96bd72 100644 --- a/examples/chunking.rs +++ b/examples/chunking.rs @@ -44,6 +44,7 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TILE_SIZE, + physical_tile_size: TILE_SIZE.into(), transform, render_settings: TilemapRenderSettings { render_chunk_size: RENDER_CHUNK_SIZE, diff --git a/examples/colors.rs b/examples/colors.rs index 6b33e878..0a56fba5 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -84,6 +84,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), map_type: TilemapType::Square, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/custom_tile_scaling.rs b/examples/custom_tile_scaling.rs new file mode 100644 index 00000000..61772d2e --- /dev/null +++ b/examples/custom_tile_scaling.rs @@ -0,0 +1,69 @@ +use bevy::{ + diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, + prelude::*, +}; +use bevy_ecs_tilemap::prelude::*; + +mod helpers; + +fn startup(mut commands: Commands, asset_server: Res) { + commands.spawn(Camera2dBundle::default()); + + let texture_handle: Handle = asset_server.load("tiles.png"); + + let map_size = TilemapSize { x: 32, y: 32 }; + let mut tile_storage = TileStorage::empty(map_size); + let tilemap_entity = commands.spawn_empty().id(); + + fill_tilemap( + TileTextureIndex(0), + map_size, + TilemapId(tilemap_entity), + &mut commands, + &mut tile_storage, + ); + + // `tile_size` specifies how large in pixels each tile is in the source atlas texture + let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; + + // `physical_tile_size` specifies how large to render each tile in the world + let physical_tile_size = TilemapPhysicalTileSize { x: 4.0, y: 4.0 }; + // The `grid_size` is essentially how far about each tile is placed from eachother + let grid_size = TilemapGridSize { x: 4.0, y: 4.0 }; + + println!("{:#?}", grid_size); + let map_type = TilemapType::default(); + + commands.entity(tilemap_entity).insert(TilemapBundle { + grid_size, + map_type, + size: map_size, + storage: tile_storage, + texture: TilemapTexture::Single(texture_handle), + tile_size, + physical_tile_size, + transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), + ..Default::default() + }); +} + +fn main() { + App::new() + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + window: WindowDescriptor { + title: String::from("Benchmark Example"), + ..Default::default() + }, + ..default() + }) + .set(ImagePlugin::default_nearest()), + ) + .add_plugin(LogDiagnosticsPlugin::default()) + .add_plugin(FrameTimeDiagnosticsPlugin::default()) + .add_plugin(TilemapPlugin) + .add_startup_system(startup) + .add_system(helpers::camera::movement) + .run(); +} diff --git a/examples/frustum_cull_test.rs b/examples/frustum_cull_test.rs index ee15f082..8e889bfd 100644 --- a/examples/frustum_cull_test.rs +++ b/examples/frustum_cull_test.rs @@ -104,6 +104,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/helpers/tiled.rs b/examples/helpers/tiled.rs index 4e5172ff..06571b1e 100644 --- a/examples/helpers/tiled.rs +++ b/examples/helpers/tiled.rs @@ -376,6 +376,7 @@ pub fn process_loaded_maps( storage: tile_storage, texture: tilemap_texture.clone(), tile_size, + physical_tile_size: tile_size.into(), spacing: tile_spacing, transform: get_tilemap_center_transform( &map_size, diff --git a/examples/hex_neighbors.rs b/examples/hex_neighbors.rs index 9aa2f1bd..80188468 100644 --- a/examples/hex_neighbors.rs +++ b/examples/hex_neighbors.rs @@ -77,6 +77,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_hex_row: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/hexagon_generation.rs b/examples/hexagon_generation.rs index 57b9f895..9b859288 100644 --- a/examples/hexagon_generation.rs +++ b/examples/hexagon_generation.rs @@ -82,6 +82,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_hex_row: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/iso_diamond.rs b/examples/iso_diamond.rs index 89ebc966..bde0acaf 100644 --- a/examples/iso_diamond.rs +++ b/examples/iso_diamond.rs @@ -80,6 +80,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/iso_staggered.rs b/examples/iso_staggered.rs index 3070d852..c5e8295d 100644 --- a/examples/iso_staggered.rs +++ b/examples/iso_staggered.rs @@ -82,6 +82,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/layers.rs b/examples/layers.rs index 85e488b7..203dbdc8 100644 --- a/examples/layers.rs +++ b/examples/layers.rs @@ -32,6 +32,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle.clone()), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); @@ -55,6 +56,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TilemapTileSize { x: 16.0, y: 16.0 }, + physical_tile_size: TilemapPhysicalTileSize { x: 16.0, y: 16.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 1.0) * Transform::from_xyz(32.0, 32.0, 0.0), ..Default::default() diff --git a/examples/mouse_to_tile.rs b/examples/mouse_to_tile.rs index 9ea13ec2..711490db 100644 --- a/examples/mouse_to_tile.rs +++ b/examples/mouse_to_tile.rs @@ -101,6 +101,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/random_map.rs b/examples/random_map.rs index fe32b727..9f0e4503 100644 --- a/examples/random_map.rs +++ b/examples/random_map.rs @@ -44,6 +44,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/remove_tiles.rs b/examples/remove_tiles.rs index 51a1d4f9..f308f9de 100644 --- a/examples/remove_tiles.rs +++ b/examples/remove_tiles.rs @@ -39,6 +39,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/spacing.rs b/examples/spacing.rs index 05929a5d..9aa25d1b 100644 --- a/examples/spacing.rs +++ b/examples/spacing.rs @@ -32,6 +32,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle.clone()), tile_size, + physical_tile_size: tile_size.into(), spacing: TilemapSpacing { x: 8.0, y: 8.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() @@ -56,6 +57,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TilemapTileSize { x: 16.0, y: 16.0 }, + physical_tile_size: TilemapPhysicalTileSize { x: 16.0, y: 16.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 1.0) * Transform::from_xyz(32.0, 32.0, 0.0), ..Default::default() diff --git a/examples/texture_container.rs b/examples/texture_container.rs index f716c132..74568e10 100644 --- a/examples/texture_container.rs +++ b/examples/texture_container.rs @@ -80,6 +80,7 @@ mod no_atlas { grid_size, map_type, tile_size, + physical_tile_size: tile_size.into(), size: map_size, storage: tile_storage, texture: texture_vec, diff --git a/examples/texture_vec.rs b/examples/texture_vec.rs index 84202f97..6faaffdb 100644 --- a/examples/texture_vec.rs +++ b/examples/texture_vec.rs @@ -74,6 +74,7 @@ mod no_atlas { grid_size, map_type, tile_size, + physical_tile_size: tile_size.into(), size: map_size, storage: tile_storage, texture: texture_vec, diff --git a/examples/visibility.rs b/examples/visibility.rs index 967ccab4..4baddcf8 100644 --- a/examples/visibility.rs +++ b/examples/visibility.rs @@ -39,6 +39,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, + physical_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, From d5ee7ea5ab8f25dfbdcbf14d6609cb46330e3f8b Mon Sep 17 00:00:00 2001 From: SirHall Date: Thu, 29 Dec 2022 16:13:03 +1000 Subject: [PATCH 3/6] Update all other grid `getMesh` shader function calls to use `physical_tile_size` --- src/render/shaders/column_even_hex.wgsl | 4 ++-- src/render/shaders/column_hex.wgsl | 4 ++-- src/render/shaders/column_odd_hex.wgsl | 4 ++-- src/render/shaders/diamond_iso.wgsl | 4 ++-- src/render/shaders/row_even_hex.wgsl | 4 ++-- src/render/shaders/row_hex.wgsl | 4 ++-- src/render/shaders/row_odd_hex.wgsl | 4 ++-- src/render/shaders/staggered_iso.wgsl | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/render/shaders/column_even_hex.wgsl b/src/render/shaders/column_even_hex.wgsl index 8550ac9d..03f66cda 100644 --- a/src/render/shaders/column_even_hex.wgsl +++ b/src/render/shaders/column_even_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = col_even_to_axial(vertex_position.xy); let center = hex_col_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/column_hex.wgsl b/src/render/shaders/column_hex.wgsl index 371447b6..3f64e6d3 100644 --- a/src/render/shaders/column_hex.wgsl +++ b/src/render/shaders/column_hex.wgsl @@ -18,8 +18,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = hex_col_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/column_odd_hex.wgsl b/src/render/shaders/column_odd_hex.wgsl index 84b57a42..4badeaf0 100644 --- a/src/render/shaders/column_odd_hex.wgsl +++ b/src/render/shaders/column_odd_hex.wgsl @@ -25,8 +25,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = col_even_to_axial(vertex_position.xy); let center = hex_col_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/diamond_iso.wgsl b/src/render/shaders/diamond_iso.wgsl index 48b479c7..0d352757 100644 --- a/src/render/shaders/diamond_iso.wgsl +++ b/src/render/shaders/diamond_iso.wgsl @@ -16,8 +16,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = diamond_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_even_hex.wgsl b/src/render/shaders/row_even_hex.wgsl index 2d9ddc6e..3babe1f4 100644 --- a/src/render/shaders/row_even_hex.wgsl +++ b/src/render/shaders/row_even_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = row_even_to_axial(vertex_position.xy); let center = hex_row_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_hex.wgsl b/src/render/shaders/row_hex.wgsl index 80e442ea..15f3ced1 100644 --- a/src/render/shaders/row_hex.wgsl +++ b/src/render/shaders/row_hex.wgsl @@ -18,8 +18,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = hex_row_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_odd_hex.wgsl b/src/render/shaders/row_odd_hex.wgsl index ab6e62f0..637a2ee0 100644 --- a/src/render/shaders/row_odd_hex.wgsl +++ b/src/render/shaders/row_odd_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = row_odd_to_axial(vertex_position.xy); let center = hex_row_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/staggered_iso.wgsl b/src/render/shaders/staggered_iso.wgsl index 117f7c21..95d9cfd6 100644 --- a/src/render/shaders/staggered_iso.wgsl +++ b/src/render/shaders/staggered_iso.wgsl @@ -21,8 +21,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = staggered_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.tile_size; - let top_right = bot_left + tilemap_data.tile_size; + let bot_left = center - 0.5 * tilemap_data.physical_tile_size; + let top_right = bot_left + tilemap_data.physical_tile_size; var positions = array, 4>( bot_left, From 8e8edc652d107f5f0ef852cf2b33d5b71f23aa04 Mon Sep 17 00:00:00 2001 From: SirHall <28499210+SirHall@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:56:14 +1000 Subject: [PATCH 4/6] Rename physical_tile_size to in_world_tile_size --- examples/accessing_tiles.rs | 2 +- examples/animation.rs | 2 +- examples/basic.rs | 2 +- examples/bench.rs | 3 +- examples/chunking.rs | 2 +- examples/colors.rs | 2 +- examples/custom_tile_scaling.rs | 7 ++--- examples/frustum_cull_test.rs | 2 +- examples/game_of_life.rs | 2 +- examples/helpers/tiled.rs | 2 +- examples/hex_neighbors.rs | 2 +- examples/hexagon_column.rs | 2 +- examples/hexagon_generation.rs | 2 +- examples/hexagon_row.rs | 2 +- examples/iso_diamond.rs | 2 +- examples/iso_staggered.rs | 2 +- examples/layers.rs | 4 +-- examples/mouse_to_tile.rs | 2 +- examples/move_tile.rs | 2 +- examples/random_map.rs | 2 +- examples/remove_tiles.rs | 2 +- examples/spacing.rs | 4 +-- examples/texture_container.rs | 2 +- examples/texture_vec.rs | 2 +- examples/visibility.rs | 2 +- src/helpers/transform.rs | 8 +++--- src/lib.rs | 4 +-- src/map.rs | 22 +++++++-------- src/render/chunk.rs | 37 +++++++++++++------------ src/render/extract.rs | 14 +++++----- src/render/prepare.rs | 12 ++++---- src/render/shaders/column_even_hex.wgsl | 4 +-- src/render/shaders/column_hex.wgsl | 4 +-- src/render/shaders/column_odd_hex.wgsl | 4 +-- src/render/shaders/common.wgsl | 2 +- src/render/shaders/diamond_iso.wgsl | 4 +-- src/render/shaders/row_even_hex.wgsl | 4 +-- src/render/shaders/row_hex.wgsl | 4 +-- src/render/shaders/row_odd_hex.wgsl | 4 +-- src/render/shaders/square.wgsl | 2 +- src/render/shaders/staggered_iso.wgsl | 4 +-- 41 files changed, 97 insertions(+), 96 deletions(-) diff --git a/examples/accessing_tiles.rs b/examples/accessing_tiles.rs index 8a85ed2a..00f02da7 100644 --- a/examples/accessing_tiles.rs +++ b/examples/accessing_tiles.rs @@ -90,7 +90,7 @@ fn startup(mut commands: Commands, asset_server: Res) { map_type, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/animation.rs b/examples/animation.rs index eacffe55..221ed9f7 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -58,7 +58,7 @@ fn create_background(mut commands: Commands, asset_server: Res) { grid_size, map_type, tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), storage: tile_storage, texture: TilemapTexture::Single(texture_handle), transform: get_tilemap_center_transform(&size, &grid_size, &map_type, 0.0), diff --git a/examples/basic.rs b/examples/basic.rs index 73545b85..925d21cb 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -56,7 +56,7 @@ fn startup( storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/bench.rs b/examples/bench.rs index f4318634..9288d911 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -26,7 +26,6 @@ fn startup(mut commands: Commands, asset_server: Res) { let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; let grid_size = tile_size.into(); - println!("{:#?}", grid_size); let map_type = TilemapType::default(); commands.entity(tilemap_entity).insert(TilemapBundle { @@ -36,7 +35,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), render_settings: TilemapRenderSettings { render_chunk_size: UVec2::new(256, 256), diff --git a/examples/chunking.rs b/examples/chunking.rs index 2e96bd72..a9747fb2 100644 --- a/examples/chunking.rs +++ b/examples/chunking.rs @@ -44,7 +44,7 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TILE_SIZE, - physical_tile_size: TILE_SIZE.into(), + in_world_tile_size: TILE_SIZE.into(), transform, render_settings: TilemapRenderSettings { render_chunk_size: RENDER_CHUNK_SIZE, diff --git a/examples/colors.rs b/examples/colors.rs index 0a56fba5..81062513 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -84,7 +84,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), map_type: TilemapType::Square, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/custom_tile_scaling.rs b/examples/custom_tile_scaling.rs index 61772d2e..34d2e4c4 100644 --- a/examples/custom_tile_scaling.rs +++ b/examples/custom_tile_scaling.rs @@ -26,12 +26,11 @@ fn startup(mut commands: Commands, asset_server: Res) { // `tile_size` specifies how large in pixels each tile is in the source atlas texture let tile_size = TilemapTileSize { x: 16.0, y: 16.0 }; - // `physical_tile_size` specifies how large to render each tile in the world - let physical_tile_size = TilemapPhysicalTileSize { x: 4.0, y: 4.0 }; + // `in_world_tile_size` specifies how large to render each tile in the world + let in_world_tile_size = TilemapInWorldTileSize { x: 4.0, y: 4.0 }; // The `grid_size` is essentially how far about each tile is placed from eachother let grid_size = TilemapGridSize { x: 4.0, y: 4.0 }; - println!("{:#?}", grid_size); let map_type = TilemapType::default(); commands.entity(tilemap_entity).insert(TilemapBundle { @@ -41,7 +40,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size, + in_world_tile_size, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/frustum_cull_test.rs b/examples/frustum_cull_test.rs index 8e889bfd..55c96e54 100644 --- a/examples/frustum_cull_test.rs +++ b/examples/frustum_cull_test.rs @@ -104,7 +104,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/helpers/tiled.rs b/examples/helpers/tiled.rs index 06571b1e..28bb5b1a 100644 --- a/examples/helpers/tiled.rs +++ b/examples/helpers/tiled.rs @@ -376,7 +376,7 @@ pub fn process_loaded_maps( storage: tile_storage, texture: tilemap_texture.clone(), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), spacing: tile_spacing, transform: get_tilemap_center_transform( &map_size, diff --git a/examples/hex_neighbors.rs b/examples/hex_neighbors.rs index 80188468..f22212ab 100644 --- a/examples/hex_neighbors.rs +++ b/examples/hex_neighbors.rs @@ -77,7 +77,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_hex_row: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/hexagon_generation.rs b/examples/hexagon_generation.rs index 9b859288..79b8aad3 100644 --- a/examples/hexagon_generation.rs +++ b/examples/hexagon_generation.rs @@ -82,7 +82,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_hex_row: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/iso_diamond.rs b/examples/iso_diamond.rs index bde0acaf..1fd2d193 100644 --- a/examples/iso_diamond.rs +++ b/examples/iso_diamond.rs @@ -80,7 +80,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/iso_staggered.rs b/examples/iso_staggered.rs index c5e8295d..fbec1899 100644 --- a/examples/iso_staggered.rs +++ b/examples/iso_staggered.rs @@ -82,7 +82,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), map_type, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() diff --git a/examples/layers.rs b/examples/layers.rs index 203dbdc8..6c361acb 100644 --- a/examples/layers.rs +++ b/examples/layers.rs @@ -32,7 +32,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle.clone()), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); @@ -56,7 +56,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TilemapTileSize { x: 16.0, y: 16.0 }, - physical_tile_size: TilemapPhysicalTileSize { x: 16.0, y: 16.0 }, + in_world_tile_size: TilemapInWorldTileSize { x: 16.0, y: 16.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 1.0) * Transform::from_xyz(32.0, 32.0, 0.0), ..Default::default() diff --git a/examples/mouse_to_tile.rs b/examples/mouse_to_tile.rs index 711490db..a98b6cb3 100644 --- a/examples/mouse_to_tile.rs +++ b/examples/mouse_to_tile.rs @@ -101,7 +101,7 @@ fn spawn_tilemap(mut commands: Commands, tile_handle_square: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/random_map.rs b/examples/random_map.rs index 9f0e4503..099f33c2 100644 --- a/examples/random_map.rs +++ b/examples/random_map.rs @@ -44,7 +44,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }); diff --git a/examples/remove_tiles.rs b/examples/remove_tiles.rs index f308f9de..2fa4cd57 100644 --- a/examples/remove_tiles.rs +++ b/examples/remove_tiles.rs @@ -39,7 +39,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/examples/spacing.rs b/examples/spacing.rs index 9aa25d1b..57bbcb8d 100644 --- a/examples/spacing.rs +++ b/examples/spacing.rs @@ -32,7 +32,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle.clone()), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), spacing: TilemapSpacing { x: 8.0, y: 8.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() @@ -57,7 +57,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size: TilemapTileSize { x: 16.0, y: 16.0 }, - physical_tile_size: TilemapPhysicalTileSize { x: 16.0, y: 16.0 }, + in_world_tile_size: TilemapInWorldTileSize { x: 16.0, y: 16.0 }, transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 1.0) * Transform::from_xyz(32.0, 32.0, 0.0), ..Default::default() diff --git a/examples/texture_container.rs b/examples/texture_container.rs index 74568e10..13ed9ed9 100644 --- a/examples/texture_container.rs +++ b/examples/texture_container.rs @@ -80,7 +80,7 @@ mod no_atlas { grid_size, map_type, tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), size: map_size, storage: tile_storage, texture: texture_vec, diff --git a/examples/texture_vec.rs b/examples/texture_vec.rs index 6faaffdb..e39cb53b 100644 --- a/examples/texture_vec.rs +++ b/examples/texture_vec.rs @@ -74,7 +74,7 @@ mod no_atlas { grid_size, map_type, tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), size: map_size, storage: tile_storage, texture: texture_vec, diff --git a/examples/visibility.rs b/examples/visibility.rs index 4baddcf8..3cf831f9 100644 --- a/examples/visibility.rs +++ b/examples/visibility.rs @@ -39,7 +39,7 @@ fn startup(mut commands: Commands, asset_server: Res) { storage: tile_storage, texture: TilemapTexture::Single(texture_handle), tile_size, - physical_tile_size: tile_size.into(), + in_world_tile_size: tile_size.into(), transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0), ..Default::default() }, diff --git a/src/helpers/transform.rs b/src/helpers/transform.rs index a1fb9b35..4d45d5a1 100644 --- a/src/helpers/transform.rs +++ b/src/helpers/transform.rs @@ -1,6 +1,6 @@ -use crate::prelude::TilemapPhysicalTileSize; +use crate::prelude::TilemapInWorldTileSize; use crate::tiles::TilePos; -use crate::{TilemapGridSize, TilemapTileSize, TilemapType}; +use crate::{TilemapGridSize, TilemapType}; use bevy::math::{UVec2, Vec2, Vec3}; use bevy::render::primitives::Aabb; @@ -30,11 +30,11 @@ pub fn chunk_index_to_world_space( pub fn chunk_aabb( chunk_size: UVec2, grid_size: &TilemapGridSize, - physical_tile_size: &TilemapPhysicalTileSize, + in_world_tile_size: &TilemapInWorldTileSize, map_type: &TilemapType, ) -> Aabb { // The AABB minimum and maximum have to be modified by -border and +border respectively. - let border = Vec2::from(grid_size).max(physical_tile_size.into()); + let border = Vec2::from(grid_size).max(in_world_tile_size.into()); // For most map types, it would be sufficient to calculate c0 and c3. However, for some map // types (right now, isometric diamond), this would not work, and for robustness (especially diff --git a/src/lib.rs b/src/lib.rs index 2122dc16..aa0e8cd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ use map::{ TilemapGridSize, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, TilemapTileSize, TilemapType, }; -use prelude::{TilemapId, TilemapRenderSettings, TilemapPhysicalTileSize}; +use prelude::{TilemapId, TilemapInWorldTileSize, TilemapRenderSettings}; #[cfg(feature = "render")] use render::material::{MaterialTilemap, StandardTilemapMaterial}; use tiles::{ @@ -120,7 +120,7 @@ pub struct MaterialTilemapBundle { pub storage: TileStorage, pub texture: TilemapTexture, pub tile_size: TilemapTileSize, - pub physical_tile_size: TilemapPhysicalTileSize, + pub in_world_tile_size: TilemapInWorldTileSize, pub transform: Transform, pub global_transform: GlobalTransform, pub render_settings: TilemapRenderSettings, diff --git a/src/map.rs b/src/map.rs index 079c9b9d..aae4f8cf 100644 --- a/src/map.rs +++ b/src/map.rs @@ -281,15 +281,15 @@ impl From for TilemapTileSize { } } -/// Physical size of the tiles in units when rendered in-world +/// In world size of the tiles in units when rendered in-world #[derive(Component, Reflect, Default, Clone, Copy, Debug, PartialOrd, PartialEq)] -pub struct TilemapPhysicalTileSize { +pub struct TilemapInWorldTileSize { pub x: f32, pub y: f32, } -impl From for TilemapGridSize { - fn from(tile_size: TilemapPhysicalTileSize) -> Self { +impl From for TilemapGridSize { + fn from(tile_size: TilemapInWorldTileSize) -> Self { TilemapGridSize { x: tile_size.x, y: tile_size.y, @@ -297,25 +297,25 @@ impl From for TilemapGridSize { } } -impl From for Vec2 { - fn from(tile_size: TilemapPhysicalTileSize) -> Self { +impl From for Vec2 { + fn from(tile_size: TilemapInWorldTileSize) -> Self { Vec2::new(tile_size.x, tile_size.y) } } -impl From<&TilemapPhysicalTileSize> for Vec2 { - fn from(tile_size: &TilemapPhysicalTileSize) -> Self { +impl From<&TilemapInWorldTileSize> for Vec2 { + fn from(tile_size: &TilemapInWorldTileSize) -> Self { Vec2::new(tile_size.x, tile_size.y) } } -impl From for TilemapPhysicalTileSize { +impl From for TilemapInWorldTileSize { fn from(Vec2 { x, y }: Vec2) -> Self { Self { x, y } } } -impl From for TilemapPhysicalTileSize { +impl From for TilemapInWorldTileSize { fn from(tile_size: TilemapTileSize) -> Self { Self { x: tile_size.x, @@ -324,7 +324,7 @@ impl From for TilemapPhysicalTileSize { } } -impl From<&TilemapTileSize> for TilemapPhysicalTileSize { +impl From<&TilemapTileSize> for TilemapInWorldTileSize { fn from(tile_size: &TilemapTileSize) -> Self { Self { x: tile_size.x, diff --git a/src/render/chunk.rs b/src/render/chunk.rs index f2cfd8c1..55bafd88 100644 --- a/src/render/chunk.rs +++ b/src/render/chunk.rs @@ -18,7 +18,10 @@ use bevy::{ render::mesh::MeshVertexBufferLayouts, }; -use crate::prelude::helpers::transform::{chunk_aabb, chunk_index_to_world_space,TilemapPhysicalTileSize}; +use crate::prelude::{ + helpers::transform::{chunk_aabb, chunk_index_to_world_space}, + TilemapInWorldTileSize, +}; use crate::render::extract::ExtractedFrustum; use crate::{ map::{TilemapSize, TilemapTexture, TilemapType}, @@ -49,7 +52,7 @@ impl RenderChunk2dStorage { chunk_size: UVec2, mesh_type: TilemapType, tile_size: TilemapTileSize, - physical_tile_size: TilemapPhysicalTileSize, + in_world_tile_size: TilemapInWorldTileSize, texture_size: Vec2, spacing: Vec2, grid_size: TilemapGridSize, @@ -87,7 +90,7 @@ impl RenderChunk2dStorage { chunk_size, mesh_type, tile_size, - physical_tile_size, + in_world_tile_size, spacing, grid_size, texture, @@ -201,8 +204,8 @@ pub struct RenderChunk2d { pub grid_size: TilemapGridSize, /// The tile size of the map this chunk belongs to. pub tile_size: TilemapTileSize, - /// The physical tile size of the map this chunk belongs to. - pub physical_tile_size: TilemapPhysicalTileSize, + /// The in-world tile size of the map this chunk belongs to. + pub in_world_tile_size: TilemapInWorldTileSize, /// The [`Aabb`] of this chunk, based on the map type, grid size, and tile size. It is not /// transformed by the `global_transform` or [`local_transform`] aabb: Aabb, @@ -235,7 +238,7 @@ impl RenderChunk2d { size_in_tiles: UVec2, map_type: TilemapType, tile_size: TilemapTileSize, - physical_tile_size: TilemapPhysicalTileSize, + in_world_tile_size: TilemapInWorldTileSize, spacing: Vec2, grid_size: TilemapGridSize, texture: TilemapTexture, @@ -252,7 +255,7 @@ impl RenderChunk2d { let global_transform: Transform = global_transform.into(); let transform = local_transform * global_transform; let transform_matrix = transform.compute_matrix(); - let aabb = chunk_aabb(size_in_tiles, &grid_size, &physical_tile_size, &map_type); + let aabb = chunk_aabb(size_in_tiles, &grid_size, &in_world_tile_size, &map_type); Self { dirty_mesh: true, gpu_mesh: None, @@ -264,7 +267,7 @@ impl RenderChunk2d { map_type, grid_size, tile_size, - physical_tile_size, + in_world_tile_size, aabb, local_transform, global_transform, @@ -325,20 +328,20 @@ impl RenderChunk2d { global_transform: Transform, grid_size: TilemapGridSize, tile_size: TilemapTileSize, - physical_tile_size: TilemapPhysicalTileSize, + in_world_tile_size: TilemapInWorldTileSize, map_type: TilemapType, ) { let mut dirty_local_transform = false; if self.grid_size != grid_size || self.tile_size != tile_size - || self.physical_tile_size != physical_tile_size + || self.in_world_tile_size != in_world_tile_size || self.map_type != map_type { self.grid_size = grid_size; self.map_type = map_type; self.tile_size = tile_size; - self.physical_tile_size = physical_tile_size; + self.in_world_tile_size = in_world_tile_size; self.position = chunk_index_to_world_space( self.index.xy(), @@ -353,7 +356,7 @@ impl RenderChunk2d { self.aabb = chunk_aabb( self.size_in_tiles, &self.grid_size, - &self.physical_tile_size, + &self.in_world_tile_size, &self.map_type, ); } @@ -486,7 +489,7 @@ impl RenderChunk2d { pub struct TilemapUniformData { pub texture_size: Vec2, pub tile_size: Vec2, - pub physical_tile_size: Vec2, + pub in_world_tile_size: Vec2, pub grid_size: Vec2, pub spacing: Vec2, pub chunk_pos: Vec2, @@ -501,11 +504,11 @@ impl From<&RenderChunk2d> for TilemapUniformData { let chunk_size: Vec2 = chunk.size_in_tiles.as_vec2(); let map_size: Vec2 = chunk.map_size.into(); let tile_size: Vec2 = chunk.tile_size.into(); - let physical_tile_size: Vec2 = chunk.physical_tile_size.into(); + let in_world_tile_size: Vec2 = chunk.in_world_tile_size.into(); Self { texture_size: chunk.texture_size, tile_size, - physical_tile_size, + in_world_tile_size, grid_size: chunk.grid_size.into(), spacing: chunk.spacing, chunk_pos: chunk_ix * chunk_size, @@ -522,11 +525,11 @@ impl From<&mut RenderChunk2d> for TilemapUniformData { let chunk_size: Vec2 = chunk.size_in_tiles.as_vec2(); let map_size: Vec2 = chunk.map_size.into(); let tile_size: Vec2 = chunk.tile_size.into(); - let physical_tile_size: Vec2 = chunk.physical_tile_size.into(); + let in_world_tile_size: Vec2 = chunk.in_world_tile_size.into(); Self { texture_size: chunk.texture_size, tile_size, - physical_tile_size, + in_world_tile_size, grid_size: chunk.grid_size.into(), spacing: chunk.spacing, chunk_pos: chunk_pos * chunk_size, diff --git a/src/render/extract.rs b/src/render/extract.rs index 4cfd657a..e3d5fdcd 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -5,7 +5,7 @@ use bevy::render::render_resource::TextureFormat; use bevy::{prelude::*, render::Extract, utils::HashMap}; use crate::prelude::TilemapGridSize; -use crate::prelude::{TilemapPhysicalTileSize, TilemapRenderSettings}; +use crate::prelude::{TilemapInWorldTileSize, TilemapRenderSettings}; use crate::render::{DefaultSampler, SecondsSinceStartup}; use crate::tiles::AnimatedTile; use crate::tiles::TilePosOld; @@ -59,7 +59,7 @@ pub struct ExtractedRemovedMapBundle { pub struct ExtractedTilemapBundle { transform: GlobalTransform, tile_size: TilemapTileSize, - physical_tile_size: TilemapPhysicalTileSize, + in_world_tile_size: TilemapInWorldTileSize, grid_size: TilemapGridSize, texture_size: TilemapTextureSize, spacing: TilemapSpacing, @@ -214,7 +214,7 @@ pub fn extract( Entity, &GlobalTransform, &TilemapTileSize, - &TilemapPhysicalTileSize, + &TilemapInWorldTileSize, &TilemapSpacing, &TilemapGridSize, &TilemapType, @@ -234,7 +234,7 @@ pub fn extract( Changed, Changed, Changed, - Changed, + Changed, Changed, Changed, Changed, @@ -297,7 +297,7 @@ pub fn extract( ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, - physical_tile_size: *data.3, + in_world_tile_size: *data.3, texture_size: TilemapTextureSize::default(), spacing: *data.4, grid_size: *data.5, @@ -334,7 +334,7 @@ pub fn extract( ExtractedTilemapBundle { transform: *data.1, tile_size: *data.2, - physical_tile_size: *data.3, + in_world_tile_size: *data.3, texture_size: TilemapTextureSize::default(), spacing: *data.4, grid_size: *data.5, @@ -354,7 +354,7 @@ pub fn extract( extracted_tilemaps.drain().map(|kv| kv.1).collect(); // Extracts tilemap textures. - for (entity, _, tile_size, _physical_tile_size, tile_spacing, _, _, texture, _, _, _, _) in + for (entity, _, tile_size, _in_world_tile_size, tile_spacing, _, _, texture, _, _, _, _) in tilemap_query.iter() { if texture.verify_ready(&images) { diff --git a/src/render/prepare.rs b/src/render/prepare.rs index 79db5327..50bd9024 100644 --- a/src/render/prepare.rs +++ b/src/render/prepare.rs @@ -4,7 +4,7 @@ use crate::map::{ TilemapId, TilemapSize, TilemapSpacing, TilemapTexture, TilemapTextureSize, TilemapTileSize, TilemapType, }; -use crate::prelude::{TilemapRenderSettings,TilemapPhysicalTileSize}; +use crate::prelude::{TilemapInWorldTileSize, TilemapRenderSettings}; use crate::render::extract::ExtractedFrustum; use crate::{ prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling, @@ -48,7 +48,7 @@ pub(crate) fn prepare( Entity, &GlobalTransform, &TilemapTileSize, - &TilemapPhysicalTileSize, + &TilemapInWorldTileSize, &TilemapTextureSize, &TilemapSpacing, &TilemapGridSize, @@ -76,7 +76,7 @@ pub(crate) fn prepare( _entity, transform, tile_size, - physical_tile_size, + in_world_tile_size, texture_size, spacing, grid_size, @@ -106,7 +106,7 @@ pub(crate) fn prepare( *chunk_size, *mesh_type, *tile_size, - *physical_tile_size, + *in_world_tile_size, (*texture_size).into(), (*spacing).into(), *grid_size, @@ -136,7 +136,7 @@ pub(crate) fn prepare( entity, global_transform, tile_size, - physical_tile_size, + in_world_tile_size, texture_size, spacing, grid_size, @@ -160,7 +160,7 @@ pub(crate) fn prepare( (*global_transform).into(), *grid_size, *tile_size, - *physical_tile_size, + *in_world_tile_size, *map_type, ); } diff --git a/src/render/shaders/column_even_hex.wgsl b/src/render/shaders/column_even_hex.wgsl index 03f66cda..0f49b1da 100644 --- a/src/render/shaders/column_even_hex.wgsl +++ b/src/render/shaders/column_even_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = col_even_to_axial(vertex_position.xy); let center = hex_col_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/column_hex.wgsl b/src/render/shaders/column_hex.wgsl index 3f64e6d3..72dae5f8 100644 --- a/src/render/shaders/column_hex.wgsl +++ b/src/render/shaders/column_hex.wgsl @@ -18,8 +18,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = hex_col_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/column_odd_hex.wgsl b/src/render/shaders/column_odd_hex.wgsl index 4badeaf0..25db47d3 100644 --- a/src/render/shaders/column_odd_hex.wgsl +++ b/src/render/shaders/column_odd_hex.wgsl @@ -25,8 +25,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = col_even_to_axial(vertex_position.xy); let center = hex_col_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/common.wgsl b/src/render/shaders/common.wgsl index 4971c0c9..65b7e69e 100644 --- a/src/render/shaders/common.wgsl +++ b/src/render/shaders/common.wgsl @@ -11,7 +11,7 @@ var mesh: Mesh; struct TilemapData { texture_size: vec2, tile_size: vec2, - physical_tile_size: vec2, + in_world_tile_size: vec2, grid_size: vec2, spacing: vec2, chunk_pos: vec2, diff --git a/src/render/shaders/diamond_iso.wgsl b/src/render/shaders/diamond_iso.wgsl index 0d352757..b46c294b 100644 --- a/src/render/shaders/diamond_iso.wgsl +++ b/src/render/shaders/diamond_iso.wgsl @@ -16,8 +16,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = diamond_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_even_hex.wgsl b/src/render/shaders/row_even_hex.wgsl index 3babe1f4..0d89c4e8 100644 --- a/src/render/shaders/row_even_hex.wgsl +++ b/src/render/shaders/row_even_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = row_even_to_axial(vertex_position.xy); let center = hex_row_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_hex.wgsl b/src/render/shaders/row_hex.wgsl index 15f3ced1..884d886b 100644 --- a/src/render/shaders/row_hex.wgsl +++ b/src/render/shaders/row_hex.wgsl @@ -18,8 +18,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = hex_row_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/row_odd_hex.wgsl b/src/render/shaders/row_odd_hex.wgsl index 637a2ee0..effb61c9 100644 --- a/src/render/shaders/row_odd_hex.wgsl +++ b/src/render/shaders/row_odd_hex.wgsl @@ -24,8 +24,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { let axial_pos = row_odd_to_axial(vertex_position.xy); let center = hex_row_tile_pos_to_world_pos(axial_pos, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, diff --git a/src/render/shaders/square.wgsl b/src/render/shaders/square.wgsl index aea13412..26bdae62 100644 --- a/src/render/shaders/square.wgsl +++ b/src/render/shaders/square.wgsl @@ -6,7 +6,7 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = vertex_position.xy * tilemap_data.grid_size; - let offset = 0.5 * tilemap_data.physical_tile_size; + let offset = 0.5 * tilemap_data.in_world_tile_size; let bot_left = center - offset; let top_right = center + offset; diff --git a/src/render/shaders/staggered_iso.wgsl b/src/render/shaders/staggered_iso.wgsl index 95d9cfd6..0314006c 100644 --- a/src/render/shaders/staggered_iso.wgsl +++ b/src/render/shaders/staggered_iso.wgsl @@ -21,8 +21,8 @@ fn get_mesh(v_index: u32, vertex_position: vec3) -> MeshOutput { var out: MeshOutput; let center = staggered_tile_pos_to_world_pos(vertex_position.xy, tilemap_data.grid_size.x, tilemap_data.grid_size.y); - let bot_left = center - 0.5 * tilemap_data.physical_tile_size; - let top_right = bot_left + tilemap_data.physical_tile_size; + let bot_left = center - 0.5 * tilemap_data.in_world_tile_size; + let top_right = bot_left + tilemap_data.in_world_tile_size; var positions = array, 4>( bot_left, From 0626fece7e2ac9608f52b9ae0e7bc9f2848e2dd2 Mon Sep 17 00:00:00 2001 From: SirHall <28499210+SirHall@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:14:21 +1000 Subject: [PATCH 5/6] Fix animation plant in-world tile-size --- examples/animation.rs | 1 + src/lib.rs | 1 + src/render/extract.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/animation.rs b/examples/animation.rs index 221ed9f7..95b9d3d4 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -116,6 +116,7 @@ fn create_animated_flowers(mut commands: Commands, asset_server: Res, Changed, Changed, + Changed, Changed, Changed, - Changed, Changed, Changed, Changed, From 16eaa4ea4a8b36140258980c91b2aca1793b07e4 Mon Sep 17 00:00:00 2001 From: SirHall <28499210+SirHall@users.noreply.github.com> Date: Sat, 2 Nov 2024 07:46:28 +1000 Subject: [PATCH 6/6] Fix `custom_tile_scaling` example --- examples/custom_tile_scaling.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/custom_tile_scaling.rs b/examples/custom_tile_scaling.rs index 34d2e4c4..666e1a1c 100644 --- a/examples/custom_tile_scaling.rs +++ b/examples/custom_tile_scaling.rs @@ -48,21 +48,21 @@ fn startup(mut commands: Commands, asset_server: Res) { fn main() { App::new() - .add_plugins( + .add_plugins(( DefaultPlugins .set(WindowPlugin { - window: WindowDescriptor { + primary_window: Option::Some(Window { title: String::from("Benchmark Example"), ..Default::default() - }, + }), ..default() }) .set(ImagePlugin::default_nearest()), - ) - .add_plugin(LogDiagnosticsPlugin::default()) - .add_plugin(FrameTimeDiagnosticsPlugin::default()) - .add_plugin(TilemapPlugin) - .add_startup_system(startup) - .add_system(helpers::camera::movement) + LogDiagnosticsPlugin::default(), + FrameTimeDiagnosticsPlugin::default(), + TilemapPlugin, + )) + .add_systems(Startup, startup) + .add_systems(Update, helpers::camera::movement) .run(); }