optimize item removal
This commit is contained in:
@@ -111,24 +111,23 @@ pub fn item_tile_management_system(
|
|||||||
) {
|
) {
|
||||||
rotation_timer.timer.tick(time.delta());
|
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() {
|
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 items.len() <= 1 {
|
||||||
if let Some(&entity_id) = items.first() {
|
if let Some(&entity_id) = items.first() {
|
||||||
let entity = Entity::from_raw(entity_id);
|
let entity = Entity::from_raw(entity_id);
|
||||||
@@ -139,13 +138,14 @@ pub fn item_tile_management_system(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rotate visibility
|
||||||
let current_index = rotation_timer
|
let current_index = rotation_timer
|
||||||
.current_indices
|
.current_indices
|
||||||
.get(&position)
|
.get(&position)
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
for &entity_id in &items {
|
for &entity_id in items {
|
||||||
let entity = Entity::from_raw(entity_id);
|
let entity = Entity::from_raw(entity_id);
|
||||||
if let Ok(mut rotation_state) = item_query.get_mut(entity) {
|
if let Ok(mut rotation_state) = item_query.get_mut(entity) {
|
||||||
rotation_state.should_be_visible = false;
|
rotation_state.should_be_visible = false;
|
||||||
@@ -153,7 +153,6 @@ pub fn item_tile_management_system(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let next_index = (current_index + 1) % items.len();
|
let next_index = (current_index + 1) % items.len();
|
||||||
|
|
||||||
if let Some(&next_entity_id) = items.get(next_index) {
|
if let Some(&next_entity_id) = items.get(next_index) {
|
||||||
let next_entity = Entity::from_raw(next_entity_id);
|
let next_entity = Entity::from_raw(next_entity_id);
|
||||||
if let Ok(mut rotation_state) = item_query.get_mut(next_entity) {
|
if let Ok(mut rotation_state) = item_query.get_mut(next_entity) {
|
||||||
|
|||||||
Reference in New Issue
Block a user