Fix tiled patching

This commit is contained in:
2026-03-18 09:22:47 +00:00
parent b0b0ca0390
commit aeef78eca2
3 changed files with 29 additions and 29 deletions
Generated
+2 -2
View File
@@ -1249,9 +1249,9 @@ checksum = "4f98cbc6d34bbdb58240b72ed1731931b4991a893b3a3238bb7c42ae054aa676"
[[package]] [[package]]
name = "bevy_rand" name = "bevy_rand"
version = "0.14.0" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41e6e263026d08a4ca27c83257ed582939162534e6658ead164886d610df9b13" checksum = "c76e5db2c274081fdff32a525609436bd7ac2c24b91c1a5d3bc04e43d7558ddf"
dependencies = [ dependencies = [
"bevy_app", "bevy_app",
"bevy_ecs", "bevy_ecs",
+1 -1
View File
@@ -7,7 +7,7 @@ edition = "2021"
bevy = { version = "0.18.0", features = ["wayland"] } bevy = { version = "0.18.0", features = ["wayland"] }
noise = "0.9.0" noise = "0.9.0"
rand = "0.10.0" rand = "0.10.0"
bevy_rand = { version = "0.14.0", features = ["wyrand"] } bevy_rand = { version = "0.14.1", features = ["wyrand"] }
image = "0.25.9" image = "0.25.9"
bevy_platform = "0.18.0" bevy_platform = "0.18.0"
rayon = "1.11.0" rayon = "1.11.0"
+26 -26
View File
@@ -36,8 +36,8 @@ pub fn compute_visibility_of_game_entities(
return; return;
} }
} }
let scaled_z = transform.translation.z / TILE_SIZE;
let entity_z = (transform.translation.z / TILE_SIZE) - 1.0; let entity_z = scaled_z - 1.0;
// if same z-level, always visible // if same z-level, always visible
if z_index.0 == entity_z { if z_index.0 == entity_z {
sprite.color = Color::WHITE; sprite.color = Color::WHITE;
@@ -59,11 +59,11 @@ pub fn compute_visibility_of_game_entities(
// if visible, calculate saturation // if visible, calculate saturation
*visibility = Visibility::Visible; *visibility = Visibility::Visible;
let saturation = let saturation = ((z_index.0 - scaled_z + 1.) / 8.0).clamp(0.0, 1.0);
((z_index.0 - (transform.translation.z / TILE_SIZE) + 1.) / 8.0).clamp(0.0, 1.0);
sprite.color = Color::hsv(194.7, saturation, 1.0 - (saturation / 2.0)); let mut c = Color::hsv(194.7, saturation, 1.0 - (saturation / 2.0));
sprite.color.set_alpha(1.0 - saturation); c.set_alpha(1.0 - saturation);
sprite.color = c;
}); });
} }
@@ -115,8 +115,11 @@ pub fn handle_tile_occlusion_updates(
} }
} }
#[inline(always)]
pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] { pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
let mut visible_range = [0u32; 8]; let mut visible_range = [0u32; 8];
let z_total = Z_TOTAL as i32;
let z_below = Z_BELOW as i32;
let touches_air = 'neighbor_check: { let touches_air = 'neighbor_check: {
for x_offset in -1..=1 { for x_offset in -1..=1 {
@@ -145,45 +148,42 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
return visible_range; return visible_range;
} }
let base_camera_index = (pos.z / ITILE_SIZE) + Z_BELOW as i32; let base_camera_index = (pos.z / ITILE_SIZE) + z_below;
if base_camera_index >= 0 && base_camera_index <= Z_TOTAL as i32 { if base_camera_index >= 0 && base_camera_index <= z_total {
if touches_air { let z2 = base_camera_index as usize;
let z2 = base_camera_index as usize; visible_range[z2 / 32] |= 1 << (z2 % 32);
visible_range[z2 / 32] |= 1 << (z2 % 32);
}
} }
let mut occluded = false; let mut occluded = false;
let mut check_pos = pos;
for z_offset in 1..=(Z_TOTAL as i32 + Z_BELOW as i32 + 1) { for z_offset in 1..=(Z_TOTAL as i32 + Z_BELOW as i32 + 1) {
let check_z = pos.z + z_offset * ITILE_SIZE; check_pos.z = pos.z + z_offset * ITILE_SIZE;
let camera_z_index = (check_z / ITILE_SIZE) + Z_BELOW as i32; let camera_z_index = (check_pos.z / ITILE_SIZE) + z_below;
if camera_z_index < 0 { if camera_z_index < 0 {
match tilemap.floor_tiles.get(&IVec3::new(pos.x, pos.y, check_z)) { if let Some(&(_, _, _, vt, _, _)) = tilemap.floor_tiles.get(&check_pos) {
Some(&(_, _, _, visibly_transparent, _, _)) => occluded = !visibly_transparent, occluded = !vt;
None => occluded = false, } else {
occluded = false;
} }
continue; continue;
} }
if camera_z_index > Z_TOTAL as i32 { if camera_z_index > z_total {
break; break;
} }
if !occluded { if !occluded {
let z2 = camera_z_index as usize; let z2 = camera_z_index as usize;
visible_range[z2 / 32] |= 1 << ((z2 % 32) as u32); visible_range[z2 / 32] |= 1 << (z2 % 32);
} }
let tile = tilemap.floor_tiles.get(&IVec3::new(pos.x, pos.y, check_z)); if let Some(&(_, _, _, vt, _, _)) = tilemap.floor_tiles.get(&check_pos) {
occluded = !vt;
match tile { } else {
Some(&(_, _, _, visibly_transparent, _, _)) => { occluded = false;
occluded = !visibly_transparent;
}
None => occluded = false,
} }
} }