fix terrain z scrolling
This commit is contained in:
+26
-17
@@ -1,5 +1,5 @@
|
||||
use crate::tile::{FixtureTile, FloorTile, NeedsOccluded, TileState};
|
||||
use crate::{constants::*, game};
|
||||
use crate::{constants::*, game, tilemap};
|
||||
use bevy::prelude::*;
|
||||
use bevy_platform::collections::hash_map::HashMap;
|
||||
|
||||
@@ -92,34 +92,34 @@ pub struct CurrentWorldSpriteState {
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct TerrainSprite;
|
||||
pub struct TerrainSprite {
|
||||
pub z_index: usize, // Store the z-index this sprite belongs to (as world_Z)
|
||||
}
|
||||
|
||||
// TODO: re-rendering on z-index change is inefficient, replace with shifting pool system for z-index change
|
||||
// This system generates sprites for all z-indices and stores references to them
|
||||
pub fn build_world_sprites(
|
||||
mut query: Query<(&FloorTile, &Transform)>,
|
||||
query: Query<(&FloorTile, &Transform)>,
|
||||
mut commands: Commands,
|
||||
mut cwss: ResMut<CurrentWorldSpriteState>,
|
||||
textures: Res<Textures>,
|
||||
texture_ids: Res<TextureIDs>,
|
||||
z_index: ResMut<game::ZIndex>,
|
||||
query_1: Query<Entity, With<TerrainSprite>>,
|
||||
) {
|
||||
if cwss.state != WorldSpriteState::WaitingForRender {
|
||||
return;
|
||||
}
|
||||
|
||||
// despawn all query_1 entities
|
||||
let now = Instant::now();
|
||||
cwss.state = WorldSpriteState::InProgress;
|
||||
|
||||
// despawn all existing terrain sprites
|
||||
for entity in query_1.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
|
||||
let now = Instant::now();
|
||||
if cwss.state == WorldSpriteState::WaitingForRender {
|
||||
cwss.state = WorldSpriteState::InProgress;
|
||||
let z_index = (z_index.0 as i32 + 150) as usize;
|
||||
println!("z_index = {}", z_index);
|
||||
|
||||
for (floortile, transform) in query.iter_mut() {
|
||||
// Generate sprites for all z-indices (0 to 150)
|
||||
for z_index in 0..=tilemap::Z_TOTAL as usize {
|
||||
for (floortile, transform) in query.iter() {
|
||||
let is_visible =
|
||||
(floortile.visible_range[z_index / 32] & (1 << (z_index % 32) as u32)) != 0;
|
||||
if is_visible {
|
||||
@@ -130,14 +130,23 @@ pub fn build_world_sprites(
|
||||
image: texture.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
commands.spawn((sprite, *transform, TerrainSprite));
|
||||
|
||||
// Spawn with hidden visibility initially - update_tile_visibility will handle showing/hiding
|
||||
commands.spawn((
|
||||
sprite,
|
||||
*transform,
|
||||
TerrainSprite { z_index },
|
||||
Visibility::Hidden,
|
||||
));
|
||||
}
|
||||
}
|
||||
cwss.state = WorldSpriteState::RenderReady;
|
||||
}
|
||||
println!("{:?}", cwss.state);
|
||||
|
||||
cwss.state = WorldSpriteState::RenderReady;
|
||||
|
||||
let elapsed = now.elapsed();
|
||||
println!("Elapsed: {:.2?}", elapsed);
|
||||
|
||||
println!("World sprites built. Elapsed: {:.2?}", elapsed);
|
||||
}
|
||||
|
||||
#[derive(Bundle)]
|
||||
|
||||
Reference in New Issue
Block a user