Fixed cylindrical

This commit is contained in:
Alvsch 2024-10-19 14:49:05 +02:00
parent 387da2c8b5
commit c85216242e
3 changed files with 25 additions and 24 deletions

View File

@ -19,7 +19,7 @@ impl Cylindrical {
old_cylindrical: Cylindrical,
new_cylindrical: Cylindrical,
mut newly_included: impl FnMut(Vector2<i32>),
just_removed: impl FnMut(Vector2<i32>),
mut just_removed: impl FnMut(Vector2<i32>),
ignore: bool,
) {
let min_x = old_cylindrical.left().min(new_cylindrical.left());
@ -29,26 +29,24 @@ impl Cylindrical {
for x in min_x..=max_x {
for z in min_z..=max_z {
// TODO
// let old_is_within = if ignore {
// false
// } else {
// old_cylindrical.is_within_distance(x, z)
// };
// let new_is_within = if ignore {
// true
// } else {
// new_cylindrical.is_within_distance(x, z)
// };
let old_is_within = if ignore {
false
} else {
old_cylindrical.is_within_distance(x, z)
};
let new_is_within = if ignore {
true
} else {
new_cylindrical.is_within_distance(x, z)
};
// if old_is_within != new_is_within {
// if new_is_within {
if old_is_within != new_is_within {
if new_is_within {
newly_included(Vector2::new(x, z));
// } else {
// dbg!("aa");
// just_removed(Vector2::new(x, z));
// }
// }
} else {
just_removed(Vector2::new(x, z));
}
}
}
}
}

View File

@ -101,13 +101,14 @@ impl Entity {
let block_pos = self.block_pos.load();
let block_pos_vec = block_pos.0;
if i != block_pos_vec.x || j != block_pos_vec.y || k != block_pos_vec.z {
self.block_pos.store(WorldPosition(Vector3::new(i, j, k)));
let new_block_pos = Vector3::new(i, j, k);
self.block_pos.store(WorldPosition(new_block_pos));
let chunk_pos = self.chunk_pos.load();
if get_section_cord(i) != chunk_pos.x || get_section_cord(k) != chunk_pos.z {
self.chunk_pos.store(Vector2::new(
get_section_cord(block_pos_vec.x),
get_section_cord(block_pos_vec.z),
get_section_cord(new_block_pos.x),
get_section_cord(new_block_pos.z),
));
}
}

View File

@ -79,8 +79,10 @@ pub async fn update_position(entity: &Entity, player: &Player) {
view_distance,
);
let new_cylindrical =
Cylindrical::new(Vector2::new(chunk_pos.x, chunk_pos.z), view_distance);
Cylindrical::new(chunk_pos, view_distance);
player.watched_section.store(new_watched);
let mut loading_chunks = Vec::new();
Cylindrical::for_each_changed_chunk(
old_cylindrical,