to tower pc
This commit is contained in:
parent
0f9a9c0f35
commit
7e91f93fe0
|
@ -7,6 +7,7 @@ pub mod s_obb;
|
|||
pub mod s_oct_asset;
|
||||
pub mod s_octtree;
|
||||
pub mod s_structure_asset;
|
||||
pub mod s_true_generic_octtree;
|
||||
|
||||
pub const RANDOM_SPACE: f32 = 5.; // size of the random possibility space.
|
||||
pub const INTERVAL: f32 = 0.3; // how often to add ^ that many and remove ^ that many random locations
|
||||
|
|
115
src/vvlib/s_true_generic_octtree.rs
Normal file
115
src/vvlib/s_true_generic_octtree.rs
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*use bevy::math::Vec3;
|
||||
pub trait OctTreeStorage<T, S: Sized> {
|
||||
type Identifier: Sized;
|
||||
type Storage: ElementTraversal<T, S>;
|
||||
}
|
||||
pub trait ElementTraversal<T, S> {
|
||||
fn as_ref(&self, subject: S) -> Option<&T>;
|
||||
fn as_mut(&mut self, subject: S) -> Option<&mut T>;
|
||||
fn child_ref(&self, subject: S, index: usize) -> Option<&Self>;
|
||||
fn child_mut(&self, subject: S, index: usize) -> Option<&mut Self>;
|
||||
fn children_ref(&self, subject: S) -> Option<[&Self; 8]>;
|
||||
fn children_mut(&self, subject: S) -> Option<[&mut Self; 8]>;
|
||||
// match avoidance helpers
|
||||
fn is_none(&self, subject: S) -> bool;
|
||||
fn is_some(&self, subject: S) -> bool {
|
||||
self.is_leaf(subject) || self.is_child(subject)
|
||||
}
|
||||
fn is_leaf(&self, subject: S) -> bool;
|
||||
fn is_child(&self, subject: S) -> bool;
|
||||
}
|
||||
|
||||
pub struct Path {
|
||||
packed: u64,
|
||||
length: usize,
|
||||
}
|
||||
impl Path {
|
||||
pub fn parent(&self) -> Path {
|
||||
let mut duplicate = self.clone();
|
||||
duplicate.set_index(self.length - 1, 0);
|
||||
duplicate.length = duplicate.length - 1;
|
||||
return duplicate;
|
||||
}
|
||||
pub fn pop(&mut self) -> Option<usize> {
|
||||
if self.length == 0 {
|
||||
return None;
|
||||
}
|
||||
self.length -= 1;
|
||||
return Some(self.get_index(self.length));
|
||||
}
|
||||
pub fn append(&mut self, value: usize) {
|
||||
self.set_index(self.length, value);
|
||||
}
|
||||
pub fn to_local(&self, grid: &OctTree) -> Vec3 {
|
||||
let (center, size) = (grid.center, grid.size);
|
||||
self.to_vec3(center, size);
|
||||
}
|
||||
pub fn to_vec3(&self, center: Vec3, size: usize) -> Vec3 {
|
||||
let mut iter = (center, size);
|
||||
for i in 0..self.length {
|
||||
iter = super::constants::sub_region(
|
||||
iter.0,
|
||||
iter.1,
|
||||
self.get_index(i.try_into().unwrap()).try_into().unwrap(),
|
||||
);
|
||||
}
|
||||
return iter.0;
|
||||
}
|
||||
pub fn get_index(&self, index: usize) -> usize {
|
||||
if index >= 22 {
|
||||
panic!("the Path can only hold 21 layers! this equates to 2,097,152 voxels across any oct-tree grid.");
|
||||
}
|
||||
if self.length < index {
|
||||
panic!("in too deep!");
|
||||
}
|
||||
let shift_amount = index as u64 * 3;
|
||||
let unshifted_result = self.packed >> shift_amount;
|
||||
(unshifted_result & 7) as usize
|
||||
}
|
||||
pub fn set_index(&mut self, index: usize, value: usize) {
|
||||
if index >= 22 {
|
||||
panic!("the Path can only hold 21 layers! this equates to 2,097,152 voxels across any oct-tree grid.");
|
||||
}
|
||||
if value > 7 {
|
||||
panic!("cannot set to more than 7!");
|
||||
}
|
||||
if index + 1 > self.length {
|
||||
self.length = index + 1;
|
||||
}
|
||||
let shift_amount = index as u64 * 3;
|
||||
let shifted_value = (value as u64) << shift_amount;
|
||||
let shift_mask = 7_u64 << shift_amount;
|
||||
let shift_mask = !shift_mask;
|
||||
self.packed = self.packed & shift_mask;
|
||||
self.packed = self.packed | shifted_value;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OctTree<T, S> {
|
||||
storage: S,
|
||||
root: Box<dyn ElementTraversal<T, S>>,
|
||||
pub size: usize,
|
||||
pub center: Vec3,
|
||||
}
|
||||
|
||||
struct GridID<T> {
|
||||
id: Option<T>,
|
||||
location: Vec3,
|
||||
}
|
||||
|
||||
enum VoxelGridLookupError {
|
||||
LocationNotOccupied,
|
||||
LocationNotInGrid,
|
||||
}
|
||||
|
||||
pub trait VoxelGrid<T> {
|
||||
type Identifier;
|
||||
fn new() -> Self;
|
||||
fn pop(&mut self, subject: GridID<Self::Identifier>) -> Result<T, VoxelGridLookupError>;
|
||||
fn remove(&mut self, subject: GridID<Self::Identifier>) -> Option<VoxelGridLookupError>;
|
||||
fn set(&mut self, subject: GridID<Self::Identifier>) -> bool;
|
||||
}
|
||||
|
||||
// implement indexing trait for Path and Vec3
|
||||
// implement indexing for each element in the tree, using a type that is either path or vec3 (constructs path while iterating down)
|
||||
*/
|
Loading…
Reference in a new issue