diff --git a/src/tilemap.rs b/src/tilemap.rs index 783bbaf..6f924f9 100644 --- a/src/tilemap.rs +++ b/src/tilemap.rs @@ -162,9 +162,8 @@ pub fn generate_surface_noise(x: i32, y: i32) -> f32 { (noise_value * 2.5) as f32 } -fn handle_chunk_loading( +fn generate_chunks_from_algo( mut commands: Commands, - textures: Res, mut events: EventReader, mut chunk_map: ResMut, mut tilemap: ResMut, @@ -306,12 +305,12 @@ impl Plugin for TilemapPlugin { .add_systems( PostStartup, ( - handle_chunk_loading, + generate_chunks_from_algo, handle_tile_occlusion_updates, tile::update_tile_visibility, ) .chain(), ) - .add_systems(FixedUpdate, (handle_chunk_loading).chain()); + .add_systems(FixedUpdate, (generate_chunks_from_algo).chain()); } } diff --git a/src/tiles.rs b/src/tiles.rs index 72a840c..5df81d0 100644 --- a/src/tiles.rs +++ b/src/tiles.rs @@ -92,6 +92,10 @@ pub struct CurrentWorldSpriteState { } use std::time::Instant; +#[derive(Component)] +pub struct TerrainSprite; + +// TODO: re-rendering on z-index change is inefficient, replace with shifting pool system for z-index change pub fn build_world_sprites( mut query: Query<(&FloorTile, &Transform)>, mut commands: Commands, @@ -99,10 +103,17 @@ pub fn build_world_sprites( textures: Res, texture_ids: Res, z_index: ResMut, + query_1: Query>, ) { if cwss.state != WorldSpriteState::WaitingForRender { return; } + + // despawn all query_1 entities + for entity in query_1.iter() { + commands.entity(entity).despawn(); + } + let now = Instant::now(); if cwss.state == WorldSpriteState::WaitingForRender { cwss.state = WorldSpriteState::InProgress; @@ -120,7 +131,7 @@ pub fn build_world_sprites( image: texture.clone(), ..Default::default() }; - commands.spawn((sprite, *transform)); + commands.spawn((sprite, *transform, TerrainSprite)); } } cwss.state = WorldSpriteState::RenderReady;