Skip to content

Commit 195d984

Browse files
committed
Fixed a few issues.
1 parent 8f5fb95 commit 195d984

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

examples/3d_iso.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
1010

1111
commands.spawn(helpers::tiled::TiledMapBundle {
1212
tiled_map: map_handle,
13+
render_settings: TilemapRenderSettings {
14+
// Map size is 12x12 so we'll have render chunks that are:
15+
// 12 tiles wide and 1 tile tall.
16+
render_chunk_size: UVec2::new(3, 1),
17+
y_sort: true,
18+
},
1319
..Default::default()
1420
});
1521
}
1622

1723
fn main() {
1824
App::new()
19-
.insert_resource(TilemapRenderSettings {
20-
// Map size is 12x12 so we'll have render chunks that are:
21-
// 12 tiles wide and 1 tile tall.
22-
render_chunk_size: UVec2::new(3, 1),
23-
y_sort: true,
24-
})
2525
.add_plugins(
2626
DefaultPlugins
2727
.set(WindowPlugin {

examples/bench.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
3535
texture: TilemapTexture::Single(texture_handle),
3636
tile_size,
3737
transform: get_tilemap_center_transform(&map_size, &grid_size, &map_type, 0.0),
38+
render_settings: TilemapRenderSettings {
39+
render_chunk_size: UVec2::new(256, 256),
40+
..Default::default()
41+
},
3842
..Default::default()
3943
});
4044
}
@@ -56,10 +60,6 @@ fn main() {
5660
})
5761
.set(ImagePlugin::default_nearest()),
5862
)
59-
.insert_resource(TilemapRenderSettings {
60-
render_chunk_size: UVec2::new(256, 256),
61-
..Default::default()
62-
})
6363
.add_plugins(LogDiagnosticsPlugin::default())
6464
.add_plugins(FrameTimeDiagnosticsPlugin)
6565
.add_plugins(TilemapPlugin)

examples/chunking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ fn spawn_chunk(commands: &mut Commands, asset_server: &AssetServer, chunk_pos: I
4545
texture: TilemapTexture::Single(texture_handle),
4646
tile_size: TILE_SIZE,
4747
transform,
48+
render_settings: TilemapRenderSettings {
49+
render_chunk_size: RENDER_CHUNK_SIZE,
50+
..Default::default()
51+
},
4852
..Default::default()
4953
});
5054
}
@@ -117,11 +121,7 @@ fn main() {
117121
})
118122
.set(ImagePlugin::default_nearest()),
119123
)
120-
// `TilemapRenderSettings` be added before the `TilemapPlugin`.
121-
.insert_resource(TilemapRenderSettings {
122-
render_chunk_size: RENDER_CHUNK_SIZE,
123-
..Default::default()
124-
})
124+
// `TilemapRenderS
125125
.add_plugins(TilemapPlugin)
126126
.insert_resource(ChunkManager::default())
127127
.add_systems(Startup, startup)

examples/helpers/tiled.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct TiledMapBundle {
6565
pub storage: TiledLayersStorage,
6666
pub transform: Transform,
6767
pub global_transform: GlobalTransform,
68+
pub render_settings: TilemapRenderSettings,
6869
}
6970

7071
struct BytesResourceReader {
@@ -200,7 +201,11 @@ pub fn process_loaded_maps(
200201
mut map_events: EventReader<AssetEvent<TiledMap>>,
201202
maps: Res<Assets<TiledMap>>,
202203
tile_storage_query: Query<(Entity, &TileStorage)>,
203-
mut map_query: Query<(&Handle<TiledMap>, &mut TiledLayersStorage)>,
204+
mut map_query: Query<(
205+
&Handle<TiledMap>,
206+
&mut TiledLayersStorage,
207+
&TilemapRenderSettings,
208+
)>,
204209
new_maps: Query<&Handle<TiledMap>, Added<Handle<TiledMap>>>,
205210
) {
206211
let mut changed_maps = Vec::<AssetId<TiledMap>>::default();
@@ -230,7 +235,7 @@ pub fn process_loaded_maps(
230235
}
231236

232237
for changed_map in changed_maps.iter() {
233-
for (map_handle, mut layer_storage) in map_query.iter_mut() {
238+
for (map_handle, mut layer_storage, render_settings) in map_query.iter_mut() {
234239
// only deal with currently changed map
235240
if map_handle.id() != *changed_map {
236241
continue;
@@ -382,6 +387,7 @@ pub fn process_loaded_maps(
382387
layer_index as f32,
383388
) * Transform::from_xyz(offset_x, -offset_y, 0.0),
384389
map_type,
390+
render_settings: *render_settings,
385391
..Default::default()
386392
});
387393

src/map/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use bevy::{
88
prelude::{Component, Entity, Handle, Image, Reflect},
99
};
1010

11+
use crate::render::CHUNK_SIZE_2D;
12+
1113
/// Custom parameters for the render pipeline.
1214
///
1315
/// It must be added as a component to the tilemap entity.
14-
#[derive(Component, Debug, Default, Copy, Clone)]
16+
#[derive(Component, Debug, Copy, Clone)]
1517
pub struct TilemapRenderSettings {
1618
/// Dimensions of a "chunk" in tiles. Chunks are grouping of tiles combined and rendered as a
1719
/// single mesh by the render pipeline.
@@ -29,6 +31,15 @@ pub struct TilemapRenderSettings {
2931
pub y_sort: bool,
3032
}
3133

34+
impl Default for TilemapRenderSettings {
35+
fn default() -> Self {
36+
Self {
37+
render_chunk_size: CHUNK_SIZE_2D,
38+
y_sort: false,
39+
}
40+
}
41+
}
42+
3243
/// A component which stores a reference to the tilemap entity.
3344
#[derive(Component, Reflect, Clone, Copy, Debug, Hash)]
3445
#[reflect(Component, MapEntities)]

src/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use self::extract::ExtractedTilemapTexture;
5050
pub(crate) use self::texture_array_cache::TextureArrayCache;
5151

5252
/// The default chunk_size (in tiles) used per mesh.
53-
const CHUNK_SIZE_2D: UVec2 = UVec2::from_array([64, 64]);
53+
pub const CHUNK_SIZE_2D: UVec2 = UVec2::from_array([64, 64]);
5454

5555
#[derive(Copy, Clone, Debug, Component)]
5656
pub(crate) struct ExtractedFilterMode(FilterMode);

src/render/texture_array_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl TextureArrayCache {
8686
"Expected image to have finished loading if \
8787
it is being extracted as a texture!",
8888
);
89-
let this_tile_size: TilemapTileSize = image.size_f32().try_into().unwrap();
89+
let this_tile_size: TilemapTileSize = image.size_f32().into();
9090
if this_tile_size != tile_size {
9191
panic!(
9292
"Expected all provided image assets to have size {tile_size:?}, \

0 commit comments

Comments
 (0)