Skip to content

Commit

Permalink
Eliminated Stackoverflow on bigger brick dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
davids91 committed Jul 19, 2024
1 parent cbed49b commit a77fd8a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ bevy_wgpu = ["raytracing", "dep:bevy"]
[dependencies]
serde = { version = "1.0.183", features = ["derive"], optional = true }
bendy = { git = "https://github.com/davids91/bendy.git" , features = ["std", "serde"]}
array-init = "2.1.0"
# for example cpu_render
image = { version = "0.25.1", optional = true }
show-image = { version = "0.14.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy_wgpu_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn setup(mut commands: Commands, images: ResMut<Assets<Image>>) {
commands.spawn(DomePosition { yaw: 0. });

// fill octree with data
let mut tree = shocovox_rs::octree::Octree::<Albedo, 16>::new(ARRAY_DIMENSION)
let mut tree = shocovox_rs::octree::Octree::<Albedo, 32>::new(ARRAY_DIMENSION)
.ok()
.unwrap();

Expand Down
15 changes: 6 additions & 9 deletions src/octree/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use bendy::decoding::{FromBencode, Object};
use super::types::Albedo;
impl<T, const DIM: usize> FromBencode for NodeContent<T, DIM>
where
T: PartialEq + Default + Clone + VoxelData,
T: PartialEq + Default + Clone + Copy + VoxelData,
{
fn decode_bencode_object(data: Object) -> Result<Self, bendy::decoding::Error> {
match data {
Expand Down Expand Up @@ -132,13 +132,10 @@ where
};
Ok(NodeContent::Internal(count as u8))
} else {
Ok(NodeContent::<T, DIM>::Leaf(array_init::array_init(|_| {
array_init::array_init(|_| {
array_init::array_init(|_| {
NodeContent::<T, DIM>::decode_single(&mut list).unwrap()
})
})
})))
Ok(NodeContent::<T, DIM>::Leaf(
[[[NodeContent::<T, DIM>::decode_single(&mut list).unwrap(); DIM]; DIM];
DIM],
))
}
}
Object::Bytes(b) => {
Expand Down Expand Up @@ -244,7 +241,7 @@ where

impl<T, const DIM: usize> FromBencode for Octree<T, DIM>
where
T: PartialEq + Default + Clone + VoxelData,
T: PartialEq + Default + Clone + Copy + VoxelData,
{
fn decode_bencode_object(data: Object) -> Result<Self, bendy::decoding::Error> {
match data {
Expand Down
6 changes: 2 additions & 4 deletions src/octree/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
///####################################################################################
impl<T, const DIM: usize> NodeContent<T, DIM>
where
T: VoxelData + PartialEq + Clone + Default,
T: VoxelData + PartialEq + Clone + Copy + Default,
{
pub fn is_leaf(&self) -> bool {
matches!(self, NodeContent::Leaf(_))
Expand Down Expand Up @@ -221,9 +221,7 @@ where
}

pub fn leaf_from(data: T) -> Self {
NodeContent::Leaf(array_init::array_init(|_| {
array_init::array_init(|_| array_init::array_init(|_| data.clone()))
}))
NodeContent::Leaf([[[data; DIM]; DIM]; DIM])
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/octree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use crate::octree::{
use crate::spatial::{math::hash_region, Cube};
use bendy::{decoding::FromBencode, encoding::ToBencode};

impl<T: Default + PartialEq + Clone + VoxelData, const DIM: usize> Octree<T, DIM> {
impl<T, const DIM: usize> Octree<T, DIM>
where
T: Default + PartialEq + Clone + Copy + VoxelData,
{
/// converts the data structure to a byte representation
pub fn to_bytes(&self) -> Vec<u8> {
self.to_bencode().ok().unwrap()
Expand Down
5 changes: 3 additions & 2 deletions src/octree/raytracing/raytracing_on_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ impl NodeStackItem {
}
}

impl<T: Default + PartialEq + Clone + std::fmt::Debug + VoxelData, const DIM: usize>
Octree<T, DIM>
impl<T, const DIM: usize> Octree<T, DIM>
where
T: Default + PartialEq + Clone + Copy + VoxelData,
{
pub(in crate::octree) fn get_dda_scale_factors(ray: &Ray) -> V3c<f32> {
V3c::new(
Expand Down
5 changes: 4 additions & 1 deletion src/octree/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use crate::spatial::{
Cube,
};

impl<T: Default + PartialEq + Clone + VoxelData, const DIM: usize> Octree<T, DIM> {
impl<T, const DIM: usize> Octree<T, DIM>
where
T: Default + PartialEq + Clone + Copy + VoxelData,
{
/// Inserts the given data into the octree into the intended voxel position
pub fn insert(&mut self, position: &V3c<u32>, data: T) -> Result<(), OctreeError> {
self.insert_at_lod(position, 1, data)
Expand Down

0 comments on commit a77fd8a

Please sign in to comment.