Skip to content

Commit b4e4d2c

Browse files
committed
enable threaded ecs and implement some micro-optimizations
1 parent 2756eb4 commit b4e4d2c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ anyhow = "1.0.100"
3535
async-compat = "0.2.5"
3636
base64 = "0.22.1"
3737
bevy_app = "0.18.0"
38-
bevy_ecs = { version = "0.18.0", default-features = false }
38+
bevy_ecs = { version = "0.18.0", default-features = false, features = [
39+
"multi_threaded",
40+
] }
3941
bevy_utils = { version = "0.18.0", default-features = false }
4042
bevy_log = "0.18.0"
4143
bevy_tasks = "0.18.0"

azalea-entity/src/plugin/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ pub struct InLoadedChunk;
254254
/// Update the [`InLoadedChunk`] component for all entities in the world.
255255
pub fn update_in_loaded_chunk(
256256
mut commands: bevy_ecs::system::Commands,
257-
query: Query<(Entity, &WorldName, &Position)>,
257+
query: Query<(Entity, &WorldName, &Position, Option<&InLoadedChunk>)>,
258258
worlds: Res<Worlds>,
259259
) {
260-
for (entity, world_name, position) in &query {
260+
for (entity, world_name, position, last_in_loaded_chunk) in &query {
261261
let player_chunk_pos = ChunkPos::from(position);
262262
let Some(world_lock) = worlds.get(world_name) else {
263263
commands.entity(entity).remove::<InLoadedChunk>();
@@ -266,9 +266,13 @@ pub fn update_in_loaded_chunk(
266266

267267
let in_loaded_chunk = world_lock.read().chunks.get(&player_chunk_pos).is_some();
268268
if in_loaded_chunk {
269-
commands.entity(entity).insert(InLoadedChunk);
269+
if last_in_loaded_chunk.is_none() {
270+
commands.entity(entity).insert(InLoadedChunk);
271+
}
270272
} else {
271-
commands.entity(entity).remove::<InLoadedChunk>();
273+
if last_in_loaded_chunk.is_some() {
274+
commands.entity(entity).remove::<InLoadedChunk>();
275+
}
272276
}
273277
}
274278
}

0 commit comments

Comments
 (0)