Noise surface

This commit is contained in:
StephenAdamson
2024-12-20 22:45:30 +00:00
parent 4141a1b430
commit 1d292d080b
7 changed files with 105 additions and 46 deletions
+15 -9
View File
@@ -1,8 +1,10 @@
use crate::constants::TILE_SIZE;
use crate::game;
use crate::item::Item;
use bevy::ecs::system::ParamSet;
use bevy::prelude::*;
use std::collections::HashMap;
use std::process::exit;
#[derive(Component, Clone)]
#[require(Sprite)]
@@ -118,18 +120,19 @@ pub fn tile_sprite_generate_occlusion_map(
);
// Check visibility for each possible z-index
for camera_z in -150..100 {
for mut camera_z in -150..100 {
camera_z *= TILE_SIZE as i32;
let mut is_visible = false;
// Skip if tile is above camera
if pos.2 > camera_z {
if pos.2 > (camera_z) {
continue;
}
// Check for opaque tiles above
let mut is_occluded = false;
'vertical_check: for z_offset in 1..=20 {
let above_pos = (pos.0, pos.1, pos.2 + z_offset);
let above_pos = (pos.0, pos.1, pos.2 + (z_offset * TILE_SIZE as i32));
if above_pos.2 <= camera_z {
if let Some(&(is_opaque, _)) = tile_map.get(&above_pos) {
if is_opaque {
@@ -137,6 +140,8 @@ pub fn tile_sprite_generate_occlusion_map(
break 'vertical_check;
}
}
} else {
break 'vertical_check;
}
}
@@ -149,12 +154,14 @@ pub fn tile_sprite_generate_occlusion_map(
continue;
}
let neighbor_pos =
(pos.0 + x_offset, pos.1 + y_offset, pos.2 + z_offset);
let neighbor_pos = (
pos.0 + (x_offset * TILE_SIZE as i32),
pos.1 + (y_offset * TILE_SIZE as i32),
pos.2 + (z_offset * TILE_SIZE as i32),
);
if let Some(&(_, id)) = tile_map.get(&neighbor_pos) {
if id == 0 {
// sky tile
// air tile
is_visible = true;
break 'neighbor_check;
}
@@ -165,7 +172,7 @@ pub fn tile_sprite_generate_occlusion_map(
}
if is_visible {
let z2 = (camera_z + 150) as usize;
let z2 = ((camera_z / TILE_SIZE as i32) + 150) as usize;
tile.visible_range[z2 / 32] |= 1 << ((z2 % 32) as u32);
}
}
@@ -177,7 +184,6 @@ pub fn update_tile_visibility(
mut query: Query<(&Tile, &mut Visibility)>,
) {
let z_index = (z_index.0 as i32 + 150) as usize;
query.par_iter_mut().for_each(|(tile, mut visibility)| {
let is_visible = (tile.visible_range[z_index / 32] & (1 << (z_index % 32) as u32)) != 0;
*visibility = if is_visible {