This commit is contained in:
2025-01-21 23:39:00 +00:00
parent bb3905e6b9
commit ca3fcc00ff
4 changed files with 52 additions and 49 deletions
+7 -9
View File
@@ -1,4 +1,4 @@
use crate::constants::TILE_SIZE;
use crate::constants::{ITILE_SIZE, TILE_SIZE};
use crate::tile::{self, FixtureTile, FloorTile, NeedsOccluded, TileMap};
use crate::tiles::{FixtureTilePrefab, FloorTilePrefab};
use bevy::prelude::*;
@@ -72,12 +72,10 @@ pub fn handle_tile_occlusion_updates(
}
pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
let tile_size = TILE_SIZE as i32;
let mut visible_range = [0u32; 8];
for mut camera_z in -15..=5 {
camera_z *= tile_size;
camera_z *= ITILE_SIZE;
let mut is_visible = false;
if pos.z > camera_z {
@@ -87,7 +85,7 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
let mut is_occluded = false;
'vertical_check: for z_offset in 1..5 {
let above_pos = IVec3::new(pos.x, pos.y, pos.z + (z_offset * tile_size));
let above_pos = IVec3::new(pos.x, pos.y, pos.z + (z_offset * ITILE_SIZE));
if above_pos.z <= camera_z {
if let Some(&(_, opaque, _, _, _)) = tilemap.floor_tiles.get(&above_pos) {
if opaque {
@@ -117,9 +115,9 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
continue;
}
let neighbor_pos = IVec3::new(
pos.x + x_offset * tile_size,
pos.y + y_offset * tile_size,
pos.z + z_offset * tile_size,
pos.x + x_offset * ITILE_SIZE,
pos.y + y_offset * ITILE_SIZE,
pos.z + z_offset * ITILE_SIZE,
);
if let Some(&(id, _, _, _, _)) = tilemap.floor_tiles.get(&neighbor_pos) {
@@ -140,7 +138,7 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
}
if is_visible {
let z2 = ((camera_z / tile_size) + 150) as usize;
let z2 = ((camera_z / ITILE_SIZE) + 150) as usize;
visible_range[z2 / 32] |= 1 << ((z2 % 32) as u32);
}
}