re-working the editor nodes

de-coupling godot resources from internal runtime logic
This commit is contained in:
2026-03-28 03:12:31 +03:30
parent 166f9e4aa7
commit d3c1b7bb5b
21 changed files with 393 additions and 235 deletions

View File

@@ -2,11 +2,12 @@ use godot::prelude::*;
pub const CHUNK_SIZE: i32 = 32;
pub const ARR_SIZE: usize = CHUNK_SIZE.pow(3) as usize;
// 32x32x32 = 32768 bits, stored in u32s (32 bits each) = 1024 u32s
pub const BITPACKED_SIZE: usize = ARR_SIZE / 32;
#[derive(Debug)]
pub struct Chunk {
pub struct SubChunk {
// Bitpacked voxel data: 0 = air, 1 = solid
pub voxels: Vec<u32>,
// WORLD COORDINATES
@@ -14,10 +15,10 @@ pub struct Chunk {
modified: bool,
}
impl Chunk {
impl SubChunk {
/// pos_z and pos_x are `world` coordinates of the chunk, inside the world
pub fn new(world_pos_x: f64, world_pos_y: f64, world_pos_z: f64) -> Self {
Chunk {
SubChunk {
voxels: vec![0u32; BITPACKED_SIZE],
world_position: (world_pos_x, world_pos_y, world_pos_z),
modified: false,
@@ -30,7 +31,7 @@ impl Chunk {
// as usize
// }
#[inline(always)]
fn get_voxel_index(local: Vector3i, chunk_size: Vector3i) -> usize {
fn get_voxel_index(local: Vector3i) -> usize {
((local.x << 10) | (local.y << 5) | local.z) as usize
}
@@ -52,7 +53,7 @@ impl Chunk {
local_pos
);
let index = Self::get_voxel_index(local_pos, chunk_size);
let index = Self::get_voxel_index(local_pos);
debug_assert!(
index < BITPACKED_SIZE,
"Voxel index {:?} out of chunk bounds",
@@ -71,7 +72,7 @@ impl Chunk {
"Voxel position {:?} out of chunk bounds",
voxel_pos
);
let index = Self::get_voxel_index(voxel_pos, chunk_size);
let index = Self::get_voxel_index(voxel_pos);
let word_index = index >> 5;
let bit_index = index & 31;