A whole lot of garbage

This commit is contained in:
Mia
2026-06-04 18:22:57 +02:00
commit 7e764095b9
17 changed files with 7654 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
[package]
name = "voxtech_terrain"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy_ecs = "0.18.1"
bevy_app = "0.18.1"
modular-bitfield = "0.13.1"
+93
View File
@@ -0,0 +1,93 @@
use std::{
ops::{Deref, DerefMut, Index, IndexMut},
sync::{Arc, atomic::AtomicU32},
};
use bevy_ecs::component::Component;
use modular_bitfield::{
bitfield,
specifiers::{B1, B21},
};
pub const SIZE: usize = 32;
pub const SIZE2: usize = SIZE * SIZE;
pub const SIZE3: usize = SIZE * SIZE2;
#[bitfield]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Component)]
pub struct ChunkId {
x: B21,
y: B21,
z: B21,
b: B1,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Component)]
pub struct Chunk;
#[derive(Component)]
pub struct ChunkData(Arc<[AtomicU32; SIZE3]>);
impl ChunkData {
pub fn empty() -> Self {
unsafe { Self(Arc::new_zeroed().assume_init()) }
}
pub fn solid(voxel_id: u32) -> Self {
let mut data = Arc::new_uninit();
let inner = Arc::get_mut(&mut data).unwrap();
let ptr = inner.as_mut_ptr() as *mut u32;
unsafe {
for i in 0..SIZE {
ptr.add(i).write(voxel_id);
}
Self(data.assume_init())
}
}
#[inline]
pub unsafe fn as_unsafe(&self) -> &UnsafeChunkData {
unsafe { &*(self.0.as_ptr() as *const UnsafeChunkData) }
}
}
impl Index<[usize; 3]> for ChunkData {
type Output = AtomicU32;
#[inline]
fn index(&self, [x, y, z]: [usize; 3]) -> &Self::Output {
&self.0[x + y * SIZE + z * SIZE2]
}
}
pub struct UnsafeChunkData([u32; SIZE3]);
impl Deref for UnsafeChunkData {
type Target = [u32; SIZE3];
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for UnsafeChunkData {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl Index<[usize; 3]> for UnsafeChunkData {
type Output = u32;
#[inline]
fn index(&self, [x, y, z]: [usize; 3]) -> &Self::Output {
&self.0[x + y * SIZE + z * SIZE2]
}
}
impl IndexMut<[usize; 3]> for UnsafeChunkData {
#[inline]
fn index_mut(&mut self, [x, y, z]: [usize; 3]) -> &mut Self::Output {
&mut self.0[x + y * SIZE + z * SIZE2]
}
}
+1
View File
@@ -0,0 +1 @@
pub mod chunk;