From b4e4d2c001dddd530c6e416e841c571c7e127138 Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 21 Feb 2026 23:25:40 -0530 Subject: enable threaded ecs and implement some micro-optimizations --- azalea-entity/src/plugin/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'azalea-entity/src/plugin/mod.rs') diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index b86c6b7d..7c4f3ed4 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -254,10 +254,10 @@ pub struct InLoadedChunk; /// Update the [`InLoadedChunk`] component for all entities in the world. pub fn update_in_loaded_chunk( mut commands: bevy_ecs::system::Commands, - query: Query<(Entity, &WorldName, &Position)>, + query: Query<(Entity, &WorldName, &Position, Option<&InLoadedChunk>)>, worlds: Res, ) { - for (entity, world_name, position) in &query { + for (entity, world_name, position, last_in_loaded_chunk) in &query { let player_chunk_pos = ChunkPos::from(position); let Some(world_lock) = worlds.get(world_name) else { commands.entity(entity).remove::(); @@ -266,9 +266,13 @@ pub fn update_in_loaded_chunk( let in_loaded_chunk = world_lock.read().chunks.get(&player_chunk_pos).is_some(); if in_loaded_chunk { - commands.entity(entity).insert(InLoadedChunk); + if last_in_loaded_chunk.is_none() { + commands.entity(entity).insert(InLoadedChunk); + } } else { - commands.entity(entity).remove::(); + if last_in_loaded_chunk.is_some() { + commands.entity(entity).remove::(); + } } } } -- cgit v1.2.3