fix
This commit is contained in:
@@ -253,7 +253,7 @@ pub fn generate_chunk_forrestry(
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove all fixture tiles and entities belonging to the tree rooted at `root_pos`.
|
||||
/// Fells the entire tree containing the trunk at `trunk_pos`.
|
||||
///
|
||||
/// # How trees are identified
|
||||
/// Finds all TreePart entities whose XY is within canopy radius of the trunk column.
|
||||
@@ -266,20 +266,25 @@ pub fn generate_chunk_forrestry(
|
||||
/// - Fires `TileChangedEvent` for path invalidation
|
||||
/// - Fires `TileOcclusionEvent` for the column at each removed position
|
||||
///
|
||||
/// # chunk_entity_index
|
||||
/// Despawned tree entities leave stale entries in `chunk_entity_index`. This is harmless:
|
||||
/// `unload_chunk` calls `despawn()` on each indexed entity, which is a no-op on
|
||||
/// already-despawned entities.
|
||||
///
|
||||
/// # Performance
|
||||
/// O(tree_size) entity lookups via `Query<(Entity, &TreePart)>`. For a typical tree
|
||||
/// (4-8 trunk + ~60 leaf tiles) this is ~68 iterations. Acceptable for an infrequent
|
||||
/// action.
|
||||
pub fn fell_tree(
|
||||
root_pos: IVec3,
|
||||
trunk_pos: IVec3,
|
||||
tree_parts: &Query<(Entity, &TreePart)>,
|
||||
commands: &mut Commands,
|
||||
tilemap: &mut TileMap,
|
||||
tile_changed: &mut MessageWriter<TileChangedEvent>,
|
||||
occlusion: &mut MessageWriter<TileOcclusionEvent>,
|
||||
) {
|
||||
let trunk_x = root_pos.x;
|
||||
let trunk_y = root_pos.y;
|
||||
let trunk_x = trunk_pos.x;
|
||||
let trunk_y = trunk_pos.y;
|
||||
let canopy_radius_world = (TREE_LEAF_BASE_RADIUS * TILE_SIZE) as i32 + ITILE_SIZE;
|
||||
|
||||
let to_remove: Vec<(Entity, IVec3)> = tree_parts
|
||||
@@ -298,6 +303,7 @@ pub fn fell_tree(
|
||||
|
||||
// Full column occlusion refresh for each removed tile.
|
||||
// calculate_visibility traces up arbitrarily deep, so refresh the full column.
|
||||
// TODO: batch into a dirty-region approach once tree felling is common (~13k events/tree).
|
||||
let z_depth =
|
||||
crate::world::chunks::Z_BELOW as i32 + crate::world::chunks::Z_ABOVE as i32 + 1;
|
||||
for dz in 0..=z_depth {
|
||||
|
||||
Reference in New Issue
Block a user