fix unloadng of temp terrain
This commit is contained in:
+3
-4
@@ -162,9 +162,8 @@ pub fn generate_surface_noise(x: i32, y: i32) -> f32 {
|
|||||||
(noise_value * 2.5) as f32
|
(noise_value * 2.5) as f32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_chunk_loading(
|
fn generate_chunks_from_algo(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
textures: Res<Textures>,
|
|
||||||
mut events: EventReader<LoadChunkEvent>,
|
mut events: EventReader<LoadChunkEvent>,
|
||||||
mut chunk_map: ResMut<ChunkMap>,
|
mut chunk_map: ResMut<ChunkMap>,
|
||||||
mut tilemap: ResMut<TileMap>,
|
mut tilemap: ResMut<TileMap>,
|
||||||
@@ -306,12 +305,12 @@ impl Plugin for TilemapPlugin {
|
|||||||
.add_systems(
|
.add_systems(
|
||||||
PostStartup,
|
PostStartup,
|
||||||
(
|
(
|
||||||
handle_chunk_loading,
|
generate_chunks_from_algo,
|
||||||
handle_tile_occlusion_updates,
|
handle_tile_occlusion_updates,
|
||||||
tile::update_tile_visibility,
|
tile::update_tile_visibility,
|
||||||
)
|
)
|
||||||
.chain(),
|
.chain(),
|
||||||
)
|
)
|
||||||
.add_systems(FixedUpdate, (handle_chunk_loading).chain());
|
.add_systems(FixedUpdate, (generate_chunks_from_algo).chain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -92,6 +92,10 @@ pub struct CurrentWorldSpriteState {
|
|||||||
}
|
}
|
||||||
use std::time::Instant;
|
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(
|
pub fn build_world_sprites(
|
||||||
mut query: Query<(&FloorTile, &Transform)>,
|
mut query: Query<(&FloorTile, &Transform)>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
@@ -99,10 +103,17 @@ pub fn build_world_sprites(
|
|||||||
textures: Res<Textures>,
|
textures: Res<Textures>,
|
||||||
texture_ids: Res<TextureIDs>,
|
texture_ids: Res<TextureIDs>,
|
||||||
z_index: ResMut<game::ZIndex>,
|
z_index: ResMut<game::ZIndex>,
|
||||||
|
query_1: Query<Entity, With<TerrainSprite>>,
|
||||||
) {
|
) {
|
||||||
if cwss.state != WorldSpriteState::WaitingForRender {
|
if cwss.state != WorldSpriteState::WaitingForRender {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// despawn all query_1 entities
|
||||||
|
for entity in query_1.iter() {
|
||||||
|
commands.entity(entity).despawn();
|
||||||
|
}
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if cwss.state == WorldSpriteState::WaitingForRender {
|
if cwss.state == WorldSpriteState::WaitingForRender {
|
||||||
cwss.state = WorldSpriteState::InProgress;
|
cwss.state = WorldSpriteState::InProgress;
|
||||||
@@ -120,7 +131,7 @@ pub fn build_world_sprites(
|
|||||||
image: texture.clone(),
|
image: texture.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
commands.spawn((sprite, *transform));
|
commands.spawn((sprite, *transform, TerrainSprite));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cwss.state = WorldSpriteState::RenderReady;
|
cwss.state = WorldSpriteState::RenderReady;
|
||||||
|
|||||||
Reference in New Issue
Block a user