diff options
| author | mat <git@matdoes.dev> | 2023-12-13 22:02:50 -0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-12-13 22:02:53 -0600 |
| commit | 5b7ed4852c5b47a47a231832d418bad0d69fa563 (patch) | |
| tree | ccb63ab84b1b5c7df0bd4048bda5ff09b2de84fc | |
| parent | da96a7663ab50eef04874755b716194e6622c3cf (diff) | |
| download | azalea-drasl-5b7ed4852c5b47a47a231832d418bad0d69fa563.tar.xz | |
fix chunks incorrectly being forgotten sometimes
mojang WHY are chunk positions read z first and then x :sob:
| -rw-r--r-- | azalea/examples/testbot.rs | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index 1c8caad7..7e7b2ca0 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -308,43 +308,63 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< bot.chat(&format!("block: {block:?}")); } "debugchunks" => { - println!("shared:"); + { + println!("shared:"); + + let mut ecs = bot.ecs.lock(); - let partial_instance_lock = bot.component::<InstanceHolder>().partial_instance; - let local_chunk_storage = &partial_instance_lock.read().chunks; + let instance_holder = bot.query::<&InstanceHolder>(&mut ecs).clone(); + drop(ecs); + let local_chunk_storage = &instance_holder.partial_instance.read().chunks; + let shared_chunk_storage = instance_holder.instance.read(); - let mut total_loaded_chunks_count = 0; - for (chunk_pos, chunk) in &bot.world().read().chunks.map { - if let Some(chunk) = chunk.upgrade() { - let in_range = local_chunk_storage.in_range(chunk_pos); - println!( - "{chunk_pos:?} has {} references{}", - std::sync::Arc::strong_count(&chunk) - 1, - if in_range { "" } else { " (out of range)" } - ); - total_loaded_chunks_count += 1; + let mut total_loaded_chunks_count = 0; + for (chunk_pos, chunk) in &shared_chunk_storage.chunks.map { + if let Some(chunk) = chunk.upgrade() { + let in_range = local_chunk_storage.in_range(chunk_pos); + println!( + "{chunk_pos:?} has {} references{}", + std::sync::Arc::strong_count(&chunk) - 1, + if in_range { "" } else { " (out of range)" } + ); + total_loaded_chunks_count += 1; + } } - } - println!("local:"); + println!("local:"); + println!("view range: {}", local_chunk_storage.view_range()); + println!("view center: {:?}", local_chunk_storage.view_center()); - let mut local_loaded_chunks_count = 0; - for (i, chunk) in local_chunk_storage.chunks().enumerate() { - if let Some(chunk) = chunk { - let chunk_pos = local_chunk_storage.chunk_pos_from_index(i); - println!( - "{chunk_pos:?} has {} references", - std::sync::Arc::strong_count(&chunk) - ); - local_loaded_chunks_count += 1; + let mut local_loaded_chunks_count = 0; + for (i, chunk) in local_chunk_storage.chunks().enumerate() { + if let Some(chunk) = chunk { + let chunk_pos = local_chunk_storage.chunk_pos_from_index(i); + println!( + "{chunk_pos:?} (#{i}) has {} references", + std::sync::Arc::strong_count(&chunk) + ); + local_loaded_chunks_count += 1; + } } + + println!("total loaded chunks: {total_loaded_chunks_count}"); + println!( + "local loaded chunks: {local_loaded_chunks_count}/{}", + local_chunk_storage.chunks().collect::<Vec<_>>().len() + ); } + { + let local_chunk_storage_lock = bot.partial_world(); + let local_chunk_storage = local_chunk_storage_lock.read(); + let current_chunk_loaded = local_chunk_storage + .chunks + .limited_get(&ChunkPos::from(bot.position())); - println!("total loaded chunks: {total_loaded_chunks_count}"); - println!( - "local loaded chunks: {local_loaded_chunks_count}/{}", - local_chunk_storage.chunks().collect::<Vec<_>>().len() - ); + bot.chat(&format!( + "current chunk loaded: {}", + current_chunk_loaded.is_some() + )); + } } _ => {} } |
