Skip to content

Commit

Permalink
fix chunks incorrectly being forgotten sometimes
Browse files Browse the repository at this point in the history
mojang WHY are chunk positions read z first and then x 😭
  • Loading branch information
mat-1 committed Dec 14, 2023
1 parent da96a76 commit 5b7ed48
Showing 1 changed file with 49 additions and 29 deletions.
78 changes: 49 additions & 29 deletions azalea/examples/testbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));
}
}
_ => {}
}
Expand Down

0 comments on commit 5b7ed48

Please sign in to comment.