optimize item removal

This commit is contained in:
2026-02-15 19:18:52 +00:00
parent 886d162963
commit a9040a4c9e
+18 -19
View File
@@ -111,24 +111,23 @@ pub fn item_tile_management_system(
) {
rotation_timer.timer.tick(time.delta());
let mut tiles_to_remove = Vec::new();
let mut tiles_with_items = Vec::new();
for (position, items) in tilemap.item_tiles.iter() {
if items.is_empty() {
tiles_to_remove.push(*position);
} else {
tiles_with_items.push((*position, items.clone()));
}
}
for position in tiles_to_remove {
tilemap.item_tiles.remove(&position);
rotation_timer.current_indices.remove(&position);
}
if rotation_timer.timer.just_finished() {
for (position, items) in tiles_with_items {
let positions: Vec<IVec3> = tilemap.item_tiles.keys().copied().collect();
for position in positions {
let items = match tilemap.item_tiles.get(&position) {
Some(i) => i,
None => continue,
};
// Clean up empty tiles
if items.is_empty() {
tilemap.item_tiles.remove(&position);
rotation_timer.current_indices.remove(&position);
continue;
}
// Single item: ensure visible
if items.len() <= 1 {
if let Some(&entity_id) = items.first() {
let entity = Entity::from_raw(entity_id);
@@ -139,13 +138,14 @@ pub fn item_tile_management_system(
continue;
}
// Rotate visibility
let current_index = rotation_timer
.current_indices
.get(&position)
.copied()
.unwrap_or(0);
for &entity_id in &items {
for &entity_id in items {
let entity = Entity::from_raw(entity_id);
if let Ok(mut rotation_state) = item_query.get_mut(entity) {
rotation_state.should_be_visible = false;
@@ -153,7 +153,6 @@ pub fn item_tile_management_system(
}
let next_index = (current_index + 1) % items.len();
if let Some(&next_entity_id) = items.get(next_index) {
let next_entity = Entity::from_raw(next_entity_id);
if let Ok(mut rotation_state) = item_query.get_mut(next_entity) {