From a3c36f135ac3353e42e2a7b7a22c11af66122d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 28 May 2019 08:29:04 +0200 Subject: [PATCH] implement a new version, that uses a more ecs approach of LOD. the old implementation needed a Vec per Element, which itself needs 24 bytes, which is a huge overhead for a single byte element. the new implementation has global Vec per region and only needs a index for the first element, which might be 8 bytes (implementation 4 bytes because of some assumptions) or none at all. It's still not ideal, because it will requiere alot of duplicate coding. Former-commit-id: 7172829c18ceabe67689487ffd269ebe62d1647b --- worldsim/src/lodstore/index.rs | 155 +++- worldsim/src/lodstore/mod.rs | 1363 ++++++++++++++++++++++++++-- worldsim/src/region/lod/example.rs | 273 ++++++ worldsim/src/region/lod/mod.rs | 3 +- worldsim/src/region/lod/terrain.rs | 298 +++--- worldsim/src/region/mod.rs | 50 +- worldsim/src/server/mod.rs | 2 + 7 files changed, 1926 insertions(+), 218 deletions(-) create mode 100644 worldsim/src/region/lod/example.rs diff --git a/worldsim/src/lodstore/index.rs b/worldsim/src/lodstore/index.rs index 10cc59a12a..6d65c9e0ed 100644 --- a/worldsim/src/lodstore/index.rs +++ b/worldsim/src/lodstore/index.rs @@ -1,34 +1,148 @@ use vek::*; +use std::ops::Sub; +use std::ops::Add; /* For our LodStructures we need a type that covers the values from 0 - 2047 in steps of 1/32. which is 11 bits for the digits before the decimal point and 5 bits for the digits after the decimal point. Because for accessing the decimal point makes no difference we use a u16 to represent this value. The value needs to be shiftet to get it's "real inworld size", -e.g. 1 represents 1/32 - 32 represents 1 - 65535 represents 2047 + 31/32 + +Edit: now it actually implements a value from 0 - 3*2048 - 1/32, covering over 3 regions for accessing neighbor region values + +-- lower neighbor +0 -> 0 +1 -> 2047 31/32 +-- owned +65536 -> 2048 +131071 -> 4095 31/32 +-- upper neighbor +196607 -> 6143 31/32 + */ -pub type LodIndex = Vec3; - -pub fn to_lod_i(pos: Vec3) -> LodIndex { - pos.map(|x| x * 32) +#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)] +pub struct LodIndex { + /* + bit 0..17 -> x + bit 18..35 -> y + bit 36..53 -> z + bit 54..63 -> unused + */ + data: u64, } -/*will round*/ -pub fn to_lod_f(pos: Vec3) -> LodIndex { - pos.map(|x| (x * 32.0).round() as u16) +/*does not work on big endian!*/ +const BIT_X_MASK: u64 = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0011_1111_1111_1111_1111; +const BIT_Y_MASK: u64 = 0b0000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1100_0000_0000_0000_0000; +const BIT_Z_MASK: u64 = 0b0000_0000_0011_1111_1111_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000; +const BIT_X_MASK32: u32 = 0b0000_0000_0000_0011_1111_1111_1111_1111; + +impl LodIndex { + pub fn new(data: Vec3) -> Self { + let mut index = LodIndex {data: 0}; + index.set(data); + index + } + + pub fn get(&self) -> Vec3 { + let x = (self.data & BIT_X_MASK) as u32; + let y = ((self.data & BIT_Y_MASK) >> 18 ) as u32; + let z = ((self.data & BIT_Z_MASK) >> 36 ) as u32; + Vec3{x,y,z} + } + + pub fn set(&mut self, data: Vec3) { + let x = (data.x & BIT_X_MASK32) as u64; + let y = ((data.y & BIT_X_MASK32) as u64 ) << 18; + let z = ((data.z & BIT_X_MASK32) as u64 ) << 36; + self.data = x + y + z; + } + + pub fn align_to_layer_id(&self, level: u8) -> LodIndex { + let xyz = self.get(); + let f = two_pow_u(level) as u32; + LodIndex::new(xyz.map(|i| { + (i / f) * f + })) + } } -pub fn to_pos_i(index: LodIndex) -> Vec3 { - index.map(|x| x / 32) + +#[cfg(test)] +mod tests { + use crate::{ + lodstore::index::LodIndex, + }; + use vek::*; + + #[test] + fn setter_getter() { + let i = LodIndex::new(Vec3::new(0,0,0)); + assert_eq!(i.get(), Vec3::new(0,0,0)); + + let i = LodIndex::new(Vec3::new(1337,0,0)); + assert_eq!(i.get(), Vec3::new(1337,0,0)); + + let i = LodIndex::new(Vec3::new(0,1337,0)); + assert_eq!(i.get(), Vec3::new(0,1337,0)); + + let i = LodIndex::new(Vec3::new(0,0,1337)); + assert_eq!(i.get(), Vec3::new(0,0,1337)); + + let i = LodIndex::new(Vec3::new(1,1,1)); + assert_eq!(i.get(), Vec3::new(1,1,1)); + + let i = LodIndex::new(Vec3::new(262143,262143,262143)); + assert_eq!(i.get(), Vec3::new(262143,262143,262143)); + + let i = LodIndex::new(Vec3::new(262144,262144,262144)); //overflow + assert_eq!(i.get(), Vec3::new(0,0,0)); + + let i = LodIndex::new(Vec3::new(42,1337,69)); + assert_eq!(i.get(), Vec3::new(42,1337,69)); + } } -pub fn to_pos_f(index: LodIndex) -> Vec3 { - index.map(|x| x as f32 / 32.0) +impl Sub for LodIndex { + type Output = LodIndex; + fn sub(self, rhs: LodIndex) -> Self::Output { + LodIndex { + data: self.data - rhs.data /*fast but has overflow issues*/ + } + } } +impl Add for LodIndex { + type Output = LodIndex; + fn add(self, rhs: LodIndex) -> Self::Output { + LodIndex { + data: self.data + rhs.data /*fast but has overflow issues*/ + } + } +} + + +/* +impl LodIndex { + pub fn new(pos: Vec3) -> Self { + Self { + data: pos.map(|x| (x * 32 + 65535) as u32), + } + } + + pub fn newf(pos: Vec3) -> Self { + Self { + data: pos.map(|x| (x * 32.0).round() as u32 + 65535), + } + } + + pub fn to_pos_i(&self) -> Vec3 { self.data.map(|x| (x / 32 - 2048) as i32) } + + pub fn to_pos_f(&self) -> Vec3 { + self.data.map(|x| x as f32 / 32.0 - 2048.0) + } +} pub const LEVEL_LENGTH_POW_MAX: i8 = 11; pub const LEVEL_LENGTH_POW_MIN: i8 = -4; @@ -44,4 +158,15 @@ pub const fn two_pow_u(n: u8) -> u16 { pub fn two_pow_i(n: i8) -> f32 { 2.0_f32.powi(n as i32) -} \ No newline at end of file +} + +*/ + +pub const fn two_pow_u(n: u8) -> u16 { + 1 << n +} + +pub fn relative_to_1d(index: LodIndex, relative_size: Vec3) -> usize { + let index = index.get(); + (index[0] + index[1] * relative_size[0] + index[2] * relative_size[0] * relative_size[1]) as usize +} diff --git a/worldsim/src/lodstore/mod.rs b/worldsim/src/lodstore/mod.rs index 31bc0709fb..ee9ced14a5 100644 --- a/worldsim/src/lodstore/mod.rs +++ b/worldsim/src/lodstore/mod.rs @@ -1,19 +1,1317 @@ pub mod index; use std::sync::Arc; +use std::collections::HashMap; use vek::*; use index::{ LodIndex, - length_to_index, - two_pow_u, + relative_to_1d, }; /* -Alternative impl idea: -1) Put LodLayer to a trait to give everyone the power to store it themself. -2) Put childs in up to 8 different VECs, and have a index in LogLayer, pointing to the fist childred in this supervector, and ge the length from E. -all access is only possible if the Owner sturcture is given +LOD Data contains different Entries in different vecs, every entry has a "pointer" to it's child start. +This is the structure to store a region and all subscribed information +*/ +pub trait LayerInfo { + fn get_child_index(&self) -> Option; + const layer_volume: Vec3; // e.g. (1|1|1) for l0 or (4|4|4) for l2 optimization + const child_layer_id: Option; + const child_len: usize; //number of childs on this layer, MUST BE 2^(SELF::child_dim*3) +} + +/* for dyn trait objects, not really fast, but faster to code, use as a makeshift solution only! */ +pub trait LayerInfoDyn { + fn get_child_index(&self) -> Option; + fn get_layer_volume(&self) -> Vec3; + fn get_child_layer_id(&self) -> Option; + fn get_child_len(&self) -> usize; +} + +impl LayerInfoDyn for L { + fn get_child_index(&self) -> Option { + self.get_child_index() + } + fn get_layer_volume(&self) -> Vec3 { + L::layer_volume + } + fn get_child_layer_id(&self) -> Option { + L::child_layer_id + } + fn get_child_len(&self) -> usize { + L::child_len + } +} + + + +pub trait LodConfig { + type L0: LayerInfo; // 2^-4 + type L1: LayerInfo; + type L2: LayerInfo; + type L3: LayerInfo; + type L4: LayerInfo; // 2^0 + type L5: LayerInfo; + type L6: LayerInfo; + type L7: LayerInfo; + type L8: LayerInfo; + type L9: LayerInfo; + type L10: LayerInfo; + type L11: LayerInfo; + type L12: LayerInfo; + type L13: LayerInfo; + type L14: LayerInfo; + type L15: LayerInfo; // 2^11 + + const anchor_layer_id: u8; + + fn setup(&mut self); + fn drill_down(data: &mut LodData::, level: u8, index: usize) where Self: Sized; + fn drill_up(data: &mut LodData::, level: u8, parent_index: usize) where Self: Sized; +} + +/* +There is another optimization problem: We have OWNED data and foreign DATA in the struct, but we don't want the foreign data to take a lot of space if unused +But both needs to be accessible transparent without overhead in calculation, difficult. +Imagine a Terrain, which top level is L13, so it would have 64 entries for the owned and 1664 for foreign data if everything is filled. +So we really only fill the boarder giving us 152 border areas. +One could think about multiple entry levels for foreign and owned data, but that means, that foreign data without a parent would exist, which might break algorithms.... +So for now we go with a single anchorlevel for now, and hope the designer chooses good levels */ +//ERROR NEXT STEP IS TO WORK ON SYSTEMS IN ORDER TO KNOW WHAT EXACTLY WE NEED. BUILD A FAKE "RASTERIZER" E:G: + +#[derive(Debug, Clone)] +pub struct LodData { + pub layer0: Vec, // 1/16 + pub layer1: Vec, // 1/8 + pub layer2: Vec, // 1/4 + pub layer3: Vec, // 1/2 + pub layer4: Vec, // 1 + pub layer5: Vec, // 2 + pub layer6: Vec, // 4 + pub layer7: Vec, // 8 + pub layer8: Vec, // 16 + pub layer9: Vec, // 32 + pub layer10: Vec, // 64 + pub layer11: Vec, // 128 + pub layer12: Vec, // 256 + pub layer13: Vec, // 512 + pub layer14: Vec, // 1024 + pub layer15: Vec, // 2048 + pub anchor: HashMap, +} + +impl LodData +{ + pub fn new() -> Self { + Self { + layer0: Vec::new(), + layer1: Vec::new(), + layer2: Vec::new(), + layer3: Vec::new(), + layer4: Vec::new(), + layer5: Vec::new(), + layer6: Vec::new(), + layer7: Vec::new(), + layer8: Vec::new(), + layer9: Vec::new(), + layer10: Vec::new(), + layer11: Vec::new(), + layer12: Vec::new(), + layer13: Vec::new(), + layer14: Vec::new(), + layer15: Vec::new(), + anchor: HashMap::new(), + } + } + + /* + Da fuq is his code you might ask, + but seriosly. because of logic reasons you have to know the level you want anyway, so we go for it ;) + + int_getN => if you know the parent and absolute index, as well as parents absolut index, i return you your child + */ + + fn int_get0(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L0 { + debug_assert_eq!(T::child_layer_id, X::L0::child_layer_id); + &self.layer0[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get1(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L1 { + debug_assert_eq!(T::child_layer_id, X::L1::child_layer_id); + &self.layer1[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get2(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L2 { + debug_assert_eq!(T::child_layer_id, X::L2::child_layer_id); + &self.layer2[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get3(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L3 { + debug_assert_eq!(T::child_layer_id, X::L3::child_layer_id); + &self.layer3[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get4(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L4 { + debug_assert_eq!(T::child_layer_id, X::L4::child_layer_id); + &self.layer4[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get5(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L5 { + debug_assert_eq!(T::child_layer_id, X::L5::child_layer_id); + &self.layer5[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get6(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L6 { + debug_assert_eq!(T::child_layer_id, X::L6::child_layer_id); + &self.layer6[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get7(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L7 { + debug_assert_eq!(T::child_layer_id, X::L7::child_layer_id); + &self.layer7[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get8(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L8 { + debug_assert_eq!(T::child_layer_id, X::L8::child_layer_id); + &self.layer8[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get9(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L9 { + debug_assert_eq!(T::child_layer_id, X::L9::child_layer_id); + &self.layer9[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get10(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L10 { + debug_assert_eq!(T::child_layer_id, X::L10::child_layer_id); + &self.layer10[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get11(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L11 { + debug_assert_eq!(T::child_layer_id, X::L11::child_layer_id); + &self.layer11[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get12(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L12 { + debug_assert_eq!(T::child_layer_id, X::L12::child_layer_id); + &self.layer12[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get13(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L13 { + debug_assert_eq!(T::child_layer_id, X::L13::child_layer_id); + &self.layer13[relative_to_1d(index - parent_index, T::layer_volume)] + } + + fn int_get14(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L14 { + debug_assert_eq!(T::child_layer_id, X::L14::child_layer_id); + &self.layer14[relative_to_1d(index - parent_index, T::layer_volume)] + } + + /* + These matches are const evaluatable, hope for the optimizer + */ + + fn int_hop_get14(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L14 { + match T::child_layer_id { + Some(14) => { + self.int_get14(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get13(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L13 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get13(l14, index, parent_index) + }, + Some(13) => { + self.int_get13(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get12(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L12 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get12(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get12(l13, index, parent_index) + }, + Some(12) => { + self.int_get12(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get11(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L11 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get11(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get11(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get11(l12, index, parent_index) + }, + Some(11) => { + self.int_get11(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get10(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L10 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get10(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get10(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get10(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get10(l11, index, parent_index) + }, + Some(10) => { + self.int_get10(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get9(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L9 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get9(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get9(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get9(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get9(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get9(l10, index, parent_index) + }, + Some(9) => { + self.int_get9(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get8(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L8 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get8(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get8(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get8(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get8(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get8(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get8(l9, index, parent_index) + }, + Some(8) => { + self.int_get8(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get7(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L7 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get7(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get7(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get7(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get7(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get7(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get7(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get7(l8, index, parent_index) + }, + Some(7) => { + self.int_get7(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get6(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L6 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get6(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get6(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get6(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get6(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get6(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get6(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get6(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get6(l7, index, parent_index) + }, + Some(6) => { + self.int_get6(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get5(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L5 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get5(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get5(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get5(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get5(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get5(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get5(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get5(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get5(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get5(l6, index, parent_index) + }, + Some(5) => { + self.int_get5(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get4(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L4 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get4(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get4(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get4(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get4(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get4(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get4(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get4(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get4(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get4(l6, index, parent_index) + }, + Some(5) => { + let l5 = self.int_get5(parent, index, parent_index); + self.int_hop_get4(l5, index, parent_index) + }, + Some(4) => { + self.int_get4(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get3(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L3 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get3(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get3(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get3(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get3(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get3(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get3(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get3(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get3(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get3(l6, index, parent_index) + } + Some(5) => { + let l5 = self.int_get5(parent, index, parent_index); + self.int_hop_get3(l5, index, parent_index) + }, + Some(4) => { + let l4 = self.int_get4(parent, index, parent_index); + self.int_hop_get3(l4, index, parent_index) + }, + Some(3) => { + self.int_get3(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get2(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L2 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get2(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get2(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get2(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get2(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get2(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get2(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get2(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get2(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get2(l6, index, parent_index) + }, + Some(5) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get2(l6, index, parent_index) + }, + Some(4) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get2(l6, index, parent_index) + }, + Some(3) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get2(l6, index, parent_index) + }, + Some(2) => { + self.int_get2(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get1(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L1 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get1(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get1(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get1(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get1(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get1(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get1(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get1(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get1(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get1(l6, index, parent_index) + }, + Some(5) => { + let l5 = self.int_get5(parent, index, parent_index); + self.int_hop_get1(l5, index, parent_index) + }, + Some(4) => { + let l4 = self.int_get4(parent, index, parent_index); + self.int_hop_get1(l4, index, parent_index) + }, + Some(3) => { + let l3 = self.int_get3(parent, index, parent_index); + self.int_hop_get1(l3, index, parent_index) + }, + Some(2) => { + let l2 = self.int_get2(parent, index, parent_index); + self.int_hop_get1(l2, index, parent_index) + }, + Some(1) => { + self.int_get1(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + fn int_hop_get0(&self, parent: &T, index: LodIndex, parent_index: LodIndex) -> &X::L0 { + match T::child_layer_id { + Some(14) => { + let l14 = self.int_get14(parent, index, parent_index); + self.int_hop_get0(l14, index, parent_index) + }, + Some(13) => { + let l13 = self.int_get13(parent, index, parent_index); + self.int_hop_get0(l13, index, parent_index) + }, + Some(12) => { + let l12 = self.int_get12(parent, index, parent_index); + self.int_hop_get0(l12, index, parent_index) + }, + Some(11) => { + let l11 = self.int_get11(parent, index, parent_index); + self.int_hop_get0(l11, index, parent_index) + }, + Some(10) => { + let l10 = self.int_get10(parent, index, parent_index); + self.int_hop_get0(l10, index, parent_index) + }, + Some(9) => { + let l9 = self.int_get9(parent, index, parent_index); + self.int_hop_get0(l9, index, parent_index) + }, + Some(8) => { + let l8 = self.int_get8(parent, index, parent_index); + self.int_hop_get0(l8, index, parent_index) + }, + Some(7) => { + let l7 = self.int_get7(parent, index, parent_index); + self.int_hop_get0(l7, index, parent_index) + }, + Some(6) => { + let l6 = self.int_get6(parent, index, parent_index); + self.int_hop_get0(l6, index, parent_index) + }, + Some(5) => { + let l5 = self.int_get5(parent, index, parent_index); + self.int_hop_get0(l5, index, parent_index) + }, + Some(4) => { + let l4 = self.int_get4(parent, index, parent_index); + self.int_hop_get0(l4, index, parent_index) + }, + Some(3) => { + let l3 = self.int_get3(parent, index, parent_index); + self.int_hop_get0(l3, index, parent_index) + }, + Some(2) => { + let l2 = self.int_get2(parent, index, parent_index); + self.int_hop_get0(l2, index, parent_index) + }, + Some(1) => { + let l1 = self.int_get1(parent, index, parent_index); + self.int_hop_get0(l1, index, parent_index) + }, + Some(0) => { + self.int_get0(parent, index, parent_index) + }, + _ => unreachable!("wrong layer info"), + } + } + + + + + + + pub fn get15(&self, index: LodIndex) -> &X::L15 { + debug_assert!(Some(X::anchor_layer_id) > X::L15::child_layer_id); + &self.layer15[0] + } + + pub fn get14(&self, index: LodIndex) -> &X::L14 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get14(l15, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L14::child_layer_id); + &self.layer14[0] + } + } + + pub fn get13(&self, index: LodIndex) -> &X::L13 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get13(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get13(l14, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L13::child_layer_id); + &self.layer13[0] + } + } + + pub fn get12(&self, index: LodIndex) -> &X::L12 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get12(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get12(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get12(l13, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L12::child_layer_id); + &self.layer12[0] + } + } + + pub fn get11(&self, index: LodIndex) -> &X::L11 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get11(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get11(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get11(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get11(l12, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L11::child_layer_id); + &self.layer11[0] + } + } + + pub fn get10(&self, index: LodIndex) -> &X::L10 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get10(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get10(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get10(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get10(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get10(l11, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L10::child_layer_id); + &self.layer10[0] + } + } + + pub fn get9(&self, index: LodIndex) -> &X::L9 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get9(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get9(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get9(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get9(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get9(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get9(l10, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L9::child_layer_id); + &self.layer9[0] + } + } + + pub fn get8(&self, index: LodIndex) -> &X::L8 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get8(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get8(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get8(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get8(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get8(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get8(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get8(l9, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L8::child_layer_id); + &self.layer8[0] + } + } + + pub fn get7(&self, index: LodIndex) -> &X::L7 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get7(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get7(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get7(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get7(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get7(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get7(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get7(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get7(l8, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L7::child_layer_id); + &self.layer7[0] + } + } + + pub fn get6(&self, index: LodIndex) -> &X::L6 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get6(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get6(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get6(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get6(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get6(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get6(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get6(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get6(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get6(l7, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L6::child_layer_id); + &self.layer6[0] + } + } + + pub fn get5(&self, index: LodIndex) -> &X::L5 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get5(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get5(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get5(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get5(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get5(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get5(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get5(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get5(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get5(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get5(l6, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L5::child_layer_id); + &self.layer5[0] + } + } + + pub fn get4(&self, index: LodIndex) -> &X::L4 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get4(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get4(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get4(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get4(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get4(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get4(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get4(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get4(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get4(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get4(l6, index, index) + } else if Some(X::anchor_layer_id) == X::L5::child_layer_id { + let l5 = self.get5(index); + self.int_hop_get4(l5, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L4::child_layer_id); + &self.layer4[0] + } + } + + pub fn get3(&self, index: LodIndex) -> &X::L3 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get3(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get3(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get3(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get3(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get3(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get3(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get3(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get3(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get3(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get3(l6, index, index) + } else if Some(X::anchor_layer_id) == X::L5::child_layer_id { + let l5 = self.get5(index); + self.int_hop_get3(l5, index, index) + } else if Some(X::anchor_layer_id) == X::L4::child_layer_id { + let l4 = self.get4(index); + self.int_hop_get3(l4, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L3::child_layer_id); + &self.layer3[0] + } + } + + pub fn get2(&self, index: LodIndex) -> &X::L2 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get2(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get2(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get2(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get2(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get2(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get2(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get2(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get2(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get2(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get2(l6, index, index) + } else if Some(X::anchor_layer_id) == X::L5::child_layer_id { + let l5 = self.get5(index); + self.int_hop_get2(l5, index, index) + } else if Some(X::anchor_layer_id) == X::L4::child_layer_id { + let l4 = self.get4(index); + self.int_hop_get2(l4, index, index) + } else if Some(X::anchor_layer_id) == X::L3::child_layer_id { + let l3 = self.get3(index); + self.int_hop_get2(l3, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L2::child_layer_id); + &self.layer2[0] + } + } + + pub fn get1(&self, index: LodIndex) -> &X::L1 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get1(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get1(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get1(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get1(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get1(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get1(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get1(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get1(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get1(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get1(l6, index, index) + } else if Some(X::anchor_layer_id) == X::L5::child_layer_id { + let l5 = self.get5(index); + self.int_hop_get1(l5, index, index) + } else if Some(X::anchor_layer_id) == X::L4::child_layer_id { + let l4 = self.get4(index); + self.int_hop_get1(l4, index, index) + } else if Some(X::anchor_layer_id) == X::L3::child_layer_id { + let l3 = self.get3(index); + self.int_hop_get1(l3, index, index) + } else if Some(X::anchor_layer_id) == X::L2::child_layer_id { + let l2 = self.get2(index); + self.int_hop_get1(l2, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L1::child_layer_id); + &self.layer1[0] + } + } + + pub fn get0(&self, index: LodIndex) -> &X::L0 { + if Some(X::anchor_layer_id) == X::L15::child_layer_id { + let l15 = self.get15(index); + self.int_hop_get0(l15, index, index) + } else if Some(X::anchor_layer_id) == X::L14::child_layer_id { + let l14 = self.get14(index); + self.int_hop_get0(l14, index, index) + } else if Some(X::anchor_layer_id) == X::L13::child_layer_id { + let l13 = self.get13(index); + self.int_hop_get0(l13, index, index) + } else if Some(X::anchor_layer_id) == X::L12::child_layer_id { + let l12 = self.get12(index); + self.int_hop_get0(l12, index, index) + } else if Some(X::anchor_layer_id) == X::L11::child_layer_id { + let l11 = self.get11(index); + self.int_hop_get0(l11, index, index) + } else if Some(X::anchor_layer_id) == X::L10::child_layer_id { + let l10 = self.get10(index); + self.int_hop_get0(l10, index, index) + } else if Some(X::anchor_layer_id) == X::L9::child_layer_id { + let l9 = self.get9(index); + self.int_hop_get0(l9, index, index) + } else if Some(X::anchor_layer_id) == X::L8::child_layer_id { + let l8 = self.get8(index); + self.int_hop_get0(l8, index, index) + } else if Some(X::anchor_layer_id) == X::L7::child_layer_id { + let l7 = self.get7(index); + self.int_hop_get0(l7, index, index) + } else if Some(X::anchor_layer_id) == X::L6::child_layer_id { + let l6 = self.get6(index); + self.int_hop_get0(l6, index, index) + } else if Some(X::anchor_layer_id) == X::L5::child_layer_id { + let l5 = self.get5(index); + self.int_hop_get0(l5, index, index) + } else if Some(X::anchor_layer_id) == X::L4::child_layer_id { + let l4 = self.get4(index); + self.int_hop_get0(l4, index, index) + } else if Some(X::anchor_layer_id) == X::L3::child_layer_id { + let l3 = self.get3(index); + self.int_hop_get0(l3, index, index) + } else if Some(X::anchor_layer_id) == X::L2::child_layer_id { + let l2 = self.get2(index); + self.int_hop_get0(l2, index, index) + } else if Some(X::anchor_layer_id) == X::L1::child_layer_id { + let l1 = self.get1(index); + self.int_hop_get0(l1, index, index) + } else { + debug_assert!(Some(X::anchor_layer_id) > X::L0::child_layer_id); + &self.layer0[0] + } + } + + /* + function to return a trait object, should not be used because slow, + so as a rule of thumb only use it in case i modify self, because modify should occur not that often, and is slow anyways + */ + fn get_mut_dyn(&mut self, level: u8, i: usize) -> &mut dyn LayerInfoDyn { + match level { + 0 => &mut self.layer0[i], + 1 => &mut self.layer1[i], + 2 => &mut self.layer2[i], + 3 => &mut self.layer3[i], + 4 => &mut self.layer4[i], + 5 => &mut self.layer5[i], + 6 => &mut self.layer6[i], + 7 => &mut self.layer7[i], + 8 => &mut self.layer8[i], + 9 => &mut self.layer9[i], + 10 => &mut self.layer10[i], + 11 => &mut self.layer11[i], + 12 => &mut self.layer12[i], + 13 => &mut self.layer13[i], + 14 => &mut self.layer14[i], + 15 => &mut self.layer15[i], + _ => panic!("invalid level"), + } + } + + /* + These functions allow you to make the LodLayer provide a certain LOD for the specified area + */ + /*is at least minimum or maximum*/ + pub fn make_at_least(&mut self, lower: LodIndex, upper: LodIndex, level: u8) { + //ERROR, DOES NOT RECURSIVLY CALL + let anchor_layer_id = X::anchor_layer_id; + let anchor_lower = lower.align_to_layer_id(anchor_layer_id); + let anchor_upper = upper.align_to_layer_id(anchor_layer_id); + let lower_xyz = anchor_lower.get(); + let upper_xyz = anchor_upper.get(); + let w = index::two_pow_u(level) as u32; + let mut x = lower_xyz[0]; + while x <= upper_xyz[0] { + let mut y = lower_xyz[1]; + while y <= upper_xyz[1] { + let mut z = lower_xyz[2]; + while z <= upper_xyz[2] { + let xyz = LodIndex::new(Vec3::new(x,y,z)); + let i = self.anchor[&xyz]; + X::drill_down(self, anchor_layer_id, i); + z += w; + } + y += w; + } + x += w; + } + } + fn make_at_most(&mut self, lower: LodIndex, upper: LodIndex, level: i8) { + + } + fn make_exactly(&mut self, lower: LodIndex, upper: LodIndex, level: i8) { + + } +} + +impl LayerInfo for () { + fn get_child_index(self: &Self) -> Option { + None + } + const child_layer_id: Option = Some(0); + const layer_volume: Vec3 = Vec3{x: 1, y: 1,z: 1}; + const child_len: usize = 0; +} + +/* #[derive(Debug, Clone)] pub struct LodLayer { pub data: E, @@ -37,7 +1335,7 @@ impl LodLayer { pub fn new_data(data: E) -> Self { Self { data, - childs: vec!(), + childs: Vec::new(), } } } @@ -81,55 +1379,6 @@ impl LodLayer { } } - /* - These functions allow you to make the LodLayer provide a certain LOD for the specified area - */ - /*is at least minimum or maximum*/ - pub fn make_at_least(&mut self, lower: LodIndex, upper: LodIndex, level: i8) { - if E::get_level(self) <= level { - //println!("done"); - return; - } - let (li, lr) = self.get_internal_index_and_remainder(lower); - let (ui, ur) = self.get_internal_index_and_remainder(upper); - if self.childs.is_empty() { - E::drill_down(self); - //println!("dd"); - } - let ll = length_to_index(E::get_lower_level(self).expect("your type is wrong configured!, configure Layer trait correctly")); - let length_per_children: u16 = two_pow_u(ll); - //println!("li {} lr {} ui {} ur {} length {}", li, lr, ui, ur, length_per_children); - if E::get_lower_level(self).unwrap() <= level { - //println!("done"); - return; - } - - for z in li.z..ui.z+1 { - for y in li.y..ui.y+1 { - for x in li.x..ui.x+1 { - //recursive call make_at_least - let mut new_lower = LodIndex::new(0,0,0); - let mut new_upper = LodIndex::new(length_per_children-1,length_per_children-1,length_per_children-1); - if x == li.x { new_lower.x = lr.x; } - if y == li.y { new_lower.y = lr.y; } - if z == li.z { new_lower.z = lr.z; } - if x == ui.x { new_upper.x = ur.x; } - if y == ui.y { new_upper.y = ur.y; } - if z == ui.z { new_upper.z = ur.z; } - let index = self.get_flat_index(LodIndex::new(x,y,z)); - //println!("lo {} up {} layer {} inr {} in {}, vec {}", new_lower, new_upper, E::get_level(self), LodIndex::new(x,y,z), index, self.childs.len()); - self.childs[index].make_at_least( new_lower, new_upper, level ); - - } - } - } - } - fn make_at_most(&mut self, lower: LodIndex, upper: LodIndex, level: i8) { - - } - fn make_exactly(&mut self, lower: LodIndex, upper: LodIndex, level: i8) { - - } } - +*/ diff --git a/worldsim/src/region/lod/example.rs b/worldsim/src/region/lod/example.rs new file mode 100644 index 0000000000..6556358b34 --- /dev/null +++ b/worldsim/src/region/lod/example.rs @@ -0,0 +1,273 @@ +use crate::lodstore::{ + LodData, + LayerInfo, + LodConfig, + index::LodIndex, +}; +use vek::*; + +#[derive(Clone)] +pub struct Example9 { + data: [u8; 700], + child_id: Option, // Chunk5 2^(7*3), this is valid +} + +#[derive(Clone)] +pub struct Example5 { + data: [u8; 130], + child_id: Option, // see Block0 2^(12*3) +} + +#[derive(Debug, Clone)] +pub struct Example0 { + data: u32, + child_id: Option,// In reality 2^(16*3) SubBlock_4 should be possible, but 2^48 subblocks would kill anything anyway, so save 2 bytes here +} + +#[derive(Debug, Clone)] +pub struct Example_4 { + data: u16, +} + +impl Example9 { + pub fn new() -> Self { + Example9{ + data: [0; 700], + child_id: None, + } + } +} + +impl LayerInfo for Example9 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(9); + const layer_volume: Vec3 = Vec3{x: 16, y: 16, z: 16}; + const child_len: usize = 4096;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for Example5 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(4); + const layer_volume: Vec3 = Vec3{x: 32, y: 32, z: 32}; + const child_len: usize = 32768;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for Example0 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(0); + const layer_volume: Vec3 = Vec3{x: 16, y: 16, z: 16}; + const child_len: usize = 4096;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for Example_4 { + fn get_child_index(self: &Self) -> Option { None } + const child_layer_id: Option = None; + const layer_volume: Vec3 = Vec3{x: 1, y: 1, z: 1}; + const child_len: usize = 0; +} + +#[derive(Debug, Clone)] +pub struct ExampleLodConfig {} + +impl LodConfig for ExampleLodConfig { + type L0 = Example_4; + type L1 = (); + type L2 = (); + type L3 = (); + type L4 = Example0; + type L5 = (); + type L6 = (); + type L7 = (); + type L8 = (); + type L9 = Example5; + type L10 = (); + type L11 = (); + type L12 = (); + type L13 = Example9; + type L14 = (); + type L15 = (); + + const anchor_layer_id: u8 = 13; + + fn setup(&mut self) { + + } + + fn drill_down(data: &mut LodData::, level: u8, index: usize) { + match level { + 0 => { + panic!("cannot drill down further"); + }, + 4 => { + if data.layer4[index].child_id.is_some() {return;} + let insert = data.layer0.len(); + data.layer4.reserve(Example_4::child_len); + data.layer4[index].child_id = Some(insert as u32); + for i in 0..Example0::child_len { + data.layer0.push(Example_4{ + data: 0, + }); + } + }, + 9 => { + if data.layer9[index].child_id.is_some() {return;} + let insert = data.layer4.len(); + data.layer9.reserve(Example0::child_len); + data.layer9[index].child_id = Some(insert as u32); + for i in 0..Example5::child_len { + data.layer4.push(Example0{ + data: 0, + child_id: None, + }); + } + }, + 13 => { + if data.layer13[index].child_id.is_some() {return;} + let insert = data.layer9.len(); + data.layer13.reserve(Example9::child_len); + data.layer13[index].child_id = Some(insert as u32); + for i in 0..Example9::child_len { + data.layer9.push(Example5{ + data: [0; 130], + child_id: None, + }); + } + }, + _ => unreachable!(), + } + + } + + fn drill_up(data: &mut LodData::, level: u8, parent_index: usize) { + match level { + 0 => { + panic!("SubBlocks_4 does not have children"); + }, + 4 => { + let delete = data.layer4[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer4[parent_index].child_id = None; + data.layer0.drain(delete..delete+Example0::child_len); + }, + 9 => { + let delete = data.layer9[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer9[parent_index].child_id = None; + data.layer4.drain(delete..delete+Example5::child_len); + }, + 13 => { + let delete = data.layer13[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer13[parent_index].child_id = None; + data.layer9.drain(delete..delete+Example9::child_len); + }, + _ => unreachable!(), + } + } +} + +#[cfg(test)] +mod tests { + use crate::{ + region::lod::example::ExampleLodConfig, + region::lod::example::*, + lodstore::LodData, + lodstore::index::LodIndex, + lodstore::index, + }; + use std::{thread, time, mem::size_of}; + use vek::*; + use rand::Rng; + use rand::ThreadRng; + + fn randIndex(rng: &mut ThreadRng) -> LodIndex { + let x: u16 = rng.gen(); + let y: u16 = rng.gen(); + let z: u16 = rng.gen(); + LodIndex::new(Vec3::new(x,y,z).map(|x| x as u32)) + } + + + pub type Example = LodData; + + fn createRegion(p_e5: f32, p_e0: f32, p_e_4: f32, p_foreign: f32) -> Example { + let mut rng = rand::thread_rng(); + let mut result = Example::new(); + let abs9 = (index::two_pow_u(15-13) as u64).pow(3); + let abs5 = (index::two_pow_u(15-9) as u64).pow(3); + let abs0 = (index::two_pow_u(15-4) as u64).pow(3); + let abs_4 = (index::two_pow_u(15) as u64).pow(3); + let act9 = (abs9 as f32 * (1.0+p_foreign) ) as u32; + let act5 = (abs5 as f32 * (p_e5*(1.0+p_foreign))) as u32; + let act0 = (abs0 as f32 * (p_e0*(1.0+p_foreign))) as u32; + let act_4 = (abs_4 as f32 * (p_e_4*(1.0+p_foreign))) as u32; + + let w9 = index::two_pow_u(13) as u32; + result.layer13 = vec![Example9::new(); 8*8*8]; + for x in 0..8 { + for y in 0..8 { + for z in 0..8 { + println!("{:?}", Vec3::new(x*w9,y*w9,z*w9)); + println!("{:?}", LodIndex::new(Vec3::new(x*w9,y*w9,z*w9))); + result.anchor.insert(LodIndex::new(Vec3::new(x*w9,y*w9,z*w9)), (x+y*8+z*8*8) as usize); + } + } + } + while result.layer9.len() < act5 as usize { + let index = randIndex(&mut rng); + let low = index.align_to_layer_id(9); + result.make_at_least(low,low,9); + }/* + while result.layer5.len() < act0 as usize { + let index = randIndex(&mut rng); + let low = index.align_to_layer_id(5); + result.make_at_least(low,low,5); + println!("{}", result.layer5.len()); + }*//* + while result.layer0.len() < act_4 as usize { + let index = randIndex(&mut rng); + let low = index.align_to_layer_id(0); + result.make_at_least(low,low,0); + }*/ + + println!("creating Region with {} 5er, {} 0er, {} -4er", act5, act0 , act_4); + println!("created Region l13: {} l9: {} l5: {} l0: {}", result.layer13.len(), result.layer9.len(), result.layer5.len(), result.layer0.len()); + println!("size {} {} {}", size_of::(), size_of::(), size_of::()); + result + } + + #[test] + fn reagiontest() { + let reg = createRegion(0.15, 0.01, 0.001, 0.1); + + thread::sleep(time::Duration::from_secs(4)); + /* + let i = LodIndex::new(Vec3::new(0,0,0)); + assert_eq!(i.get(), Vec3::new(0,0,0)); + + let i = LodIndex::new(Vec3::new(1337,0,0)); + assert_eq!(i.get(), Vec3::new(1337,0,0)); + + let i = LodIndex::new(Vec3::new(0,1337,0)); + assert_eq!(i.get(), Vec3::new(0,1337,0)); + + let i = LodIndex::new(Vec3::new(0,0,1337)); + assert_eq!(i.get(), Vec3::new(0,0,1337)); + + let i = LodIndex::new(Vec3::new(1,1,1)); + assert_eq!(i.get(), Vec3::new(1,1,1)); + + let i = LodIndex::new(Vec3::new(262143,262143,262143)); + assert_eq!(i.get(), Vec3::new(262143,262143,262143)); + + let i = LodIndex::new(Vec3::new(262144,262144,262144)); //overflow + assert_eq!(i.get(), Vec3::new(0,0,0)); + + let i = LodIndex::new(Vec3::new(42,1337,69)); + assert_eq!(i.get(), Vec3::new(42,1337,69)); + */ + } +} \ No newline at end of file diff --git a/worldsim/src/region/lod/mod.rs b/worldsim/src/region/lod/mod.rs index 71b893d511..bbd449f607 100644 --- a/worldsim/src/region/lod/mod.rs +++ b/worldsim/src/region/lod/mod.rs @@ -1 +1,2 @@ -pub mod terrain; \ No newline at end of file +pub mod terrain; +mod example; \ No newline at end of file diff --git a/worldsim/src/region/lod/terrain.rs b/worldsim/src/region/lod/terrain.rs index 4c9b7caeda..c847a06d90 100644 --- a/worldsim/src/region/lod/terrain.rs +++ b/worldsim/src/region/lod/terrain.rs @@ -1,144 +1,168 @@ -use crate::lodstore::Layer; -use crate::lodstore::LodLayer; +use crate::lodstore::{ + LodData, + LayerInfo, + LodConfig, + index::LodIndex, +}; +use vek::*; #[derive(Debug, Clone)] -pub enum Terrain { - // 11 is max - Unused11, - Region9 { //512m this is for normal simulation if no player nearby - precent_air: f32, - percent_forrest: f32, - percent_lava: f32, - percent_water: f32, - }, - Chunk5 {//32m, same detail as region, but to not force block1 everywhere in 512 area - precent_air: f32, - percent_forrest: f32, - percent_lava: f32, - percent_water: f32, - }, - Block1 { - material: u32, - }, - SubBlock_4 { - material: u32, - }, - // -4 is min +pub struct Region9 { + precent_air: f32, + percent_forrest: f32, + percent_lava: f32, + percent_water: f32, + child_id: Option, // Chunk5 2^(7*3), this is valid } -impl Terrain { - fn new() -> Self { - Terrain::Unused11 +#[derive(Debug, Clone)] +pub struct Chunk5 { + precent_air: f32, + percent_forrest: f32, + percent_lava: f32, + percent_water: f32, + child_id: Option, // see Block0 2^(12*3) +} + +#[derive(Debug, Clone)] +pub struct Block0 { + material: u32, + child_id: Option,// In reality 2^(16*3) SubBlock_4 should be possible, but 2^48 subblocks would kill anything anyway, so save 2 bytes here +} + +#[derive(Debug, Clone)] +pub struct SubBlock_4 { + material: u32, +} + +impl LayerInfo for Region9 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(9); + const layer_volume: Vec3 = Vec3{x: 16, y: 16, z: 16}; + const child_len: usize = 4096;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for Chunk5 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(4); + const layer_volume: Vec3 = Vec3{x: 32, y: 32, z: 32}; + const child_len: usize = 32768;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for Block0 { + fn get_child_index(self: &Self) -> Option { + self.child_id.map(|n| n as usize) + } + const child_layer_id: Option = Some(0); + const layer_volume: Vec3 = Vec3{x: 16, y: 16, z: 16}; + const child_len: usize = 4096;//2_usize.pow(Self::child_dim*3); +} + +impl LayerInfo for SubBlock_4 { + fn get_child_index(self: &Self) -> Option { + None + } + const child_layer_id: Option = None; + const layer_volume: Vec3 = Vec3{x: 1, y: 1, z: 1}; + const child_len: usize = 0; +} + +#[derive(Debug, Clone)] +pub struct TerrainLodConfig {} + +impl LodConfig for TerrainLodConfig { + type L0 = SubBlock_4; + type L1 = (); + type L2 = (); + type L3 = (); + type L4 = Block0; + type L5 = (); + type L6 = (); + type L7 = (); + type L8 = (); + type L9 = Chunk5; + type L10 = (); + type L11 = (); + type L12 = (); + type L13 = Region9; + type L14 = (); + type L15 = (); + + const anchor_layer_id: u8 = 13; + + fn setup(&mut self) { + + } + + fn drill_down(data: &mut LodData::, level: u8, index: usize) { + match level { + 0 => { + panic!("cannot drill down further"); + }, + 4 => { + let insert = data.layer0.len(); + data.layer4[index].child_id = Some(insert as u32); + for i in 0..Block0::child_len { + data.layer0[i+insert] = SubBlock_4{ + material: 0, + }; + } + }, + 9 => { + let insert = data.layer4.len(); + data.layer9[index].child_id = Some(insert as u32); + for i in 0..Chunk5::child_len { + data.layer4[i+insert] = Block0{ + material: 0, + child_id: None, + }; + } + }, + 13 => { + let insert = data.layer9.len(); + data.layer13[index].child_id = Some(insert as u32); + for i in 0..Region9::child_len { + data.layer9[i+insert] = Chunk5{ + precent_air: 0.2, + percent_forrest: 0.3, + percent_lava: 0.4, + percent_water: 0.1, + child_id: None, + }; + } + }, + _ => unreachable!(), + } + + } + + fn drill_up(data: &mut LodData::, level: u8, parent_index: usize) { + match level { + 0 => { + panic!("SubBlocks_4 does not have children"); + }, + 4 => { + let delete = data.layer4[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer4[parent_index].child_id = None; + data.layer0.drain(delete..delete+Block0::child_len); + }, + 9 => { + let delete = data.layer9[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer9[parent_index].child_id = None; + data.layer4.drain(delete..delete+Chunk5::child_len); + }, + 13 => { + let delete = data.layer13[parent_index].child_id.expect("has no childs to drill up") as usize; + data.layer13[parent_index].child_id = None; + data.layer9.drain(delete..delete+Region9::child_len); + }, + _ => unreachable!(), + } } } -const LAYER5: i8 = 11; -const LAYER4: i8 = 9; -const LAYER3: i8 = 5; -const LAYER2: i8 = 0; -const LAYER1: i8 = -4; - - -impl Layer for Terrain { - fn new() -> LodLayer { - let mut n = LodLayer::::new_data(Terrain::Unused11); - Self::drill_down(&mut n); - n - } - - fn get_level(layer: &LodLayer) -> i8 { - match &layer.data { - Terrain::Unused11 => LAYER5, - Terrain::Region9{..} => LAYER4, - Terrain::Chunk5{..} => LAYER3, - Terrain::Block1{..} => LAYER2, - Terrain::SubBlock_4{..} => -LAYER1, - } - } - - fn get_lower_level(layer: &LodLayer) -> Option { - match &layer.data { - Terrain::Unused11 => Some(LAYER4), - Terrain::Region9{..} => Some(LAYER3), - Terrain::Chunk5{..} => Some(LAYER2), - Terrain::Block1{..} => Some(LAYER1), - Terrain::SubBlock_4{..} => None, - } - } - - fn drill_down(layer: &mut LodLayer) { - match &layer.data { - Terrain::Unused11 => { - let n = LodLayer::new_data(Terrain::Region9{ - precent_air: 1.0, - percent_forrest: 0.0, - percent_lava: 0.0, - percent_water: 0.0, - }); - layer.childs = vec![n; 2_usize.pow((LAYER5-LAYER4) as u32 *3)]; - }, - Terrain::Region9{..} => { - let n = LodLayer::new_data(Terrain::Chunk5{ - precent_air: 1.0, - percent_forrest: 0.0, - percent_lava: 0.0, - percent_water: 0.0, - }); - layer.childs = vec![n; 2_usize.pow((LAYER4-LAYER3) as u32 *3)]; - }, - Terrain::Chunk5{..} => { - let n = LodLayer::new_data( Terrain::Block1{ - material: 10, - }); - layer.childs = vec![n; 2_usize.pow((LAYER3-LAYER2) as u32 *3)]; - }, - Terrain::Block1{..} => { - let n = LodLayer::new_data( Terrain::SubBlock_4{ - material: 10, - }); - layer.childs = vec![n; 2_usize.pow((LAYER2-LAYER1) as u32 *3)]; - }, - Terrain::SubBlock_4{..} => { - panic!("cannot drillDown further") - }, - } - } - fn drill_up(parent: &mut LodLayer) { - match &parent.data { - Terrain::Unused11 => { - panic!("cannot drillUp further") - }, - Terrain::Region9{..} => { - //recalculate values here - parent.data = Terrain::Region9{ - precent_air: 1.0, - percent_forrest: 0.0, - percent_lava: 0.0, - percent_water: 0.0, - }; - parent.childs = vec![]; - }, - Terrain::Chunk5{..} => { - parent.data = Terrain::Chunk5{ - precent_air: 1.0, - percent_forrest: 0.0, - percent_lava: 0.0, - percent_water: 0.0, - }; - parent.childs = vec![]; - }, - Terrain::Block1{..} => { - parent.data = Terrain::Block1{ - material: 10, - }; - parent.childs = vec![]; - }, - Terrain::SubBlock_4{..} => { - parent.data = Terrain::SubBlock_4{ - material: 10, - }; - parent.childs = vec![]; - }, - } - } -} \ No newline at end of file +pub type Terrain = LodData; \ No newline at end of file diff --git a/worldsim/src/region/mod.rs b/worldsim/src/region/mod.rs index ab7971ccce..2a2608ad2e 100644 --- a/worldsim/src/region/mod.rs +++ b/worldsim/src/region/mod.rs @@ -5,8 +5,6 @@ use std::sync::Arc; use crate::{ regionmanager::meta::RegionId, job::JobManager, - lodstore::LodLayer, - lodstore::Layer, }; use lod::terrain::Terrain; @@ -15,11 +13,11 @@ pub struct Region { id: RegionId, jobmanager: Arc, - pub block: LodLayer, - temp: LodLayer, - light: LodLayer, - evil: LodLayer, - civ: LodLayer, + pub block: Terrain, + temp: Terrain, + light: Terrain, + evil: Terrain, + civ: Terrain, } impl Region { @@ -36,6 +34,39 @@ impl Region { } } +fn rasterize(region: &Region) -> Vec { + let mut res = Vec::new(); + + // iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ + //region.block + + res +} + + + +fn plant_trees(region: &Region) -> Vec { + let mut res = Vec::new(); + + // iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ + // acces blocks around + + res +} + + + +fn corrosion(region: &Region) -> Vec { + let mut res = Vec::new(); + + // iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ + // access neighbours + + res +} + + + /* pub type aaa = LodLayer; @@ -48,6 +79,7 @@ fn example() { */ +/* #[cfg(test)] mod tests { use crate::{ @@ -84,4 +116,6 @@ mod tests { let mut r = Region::new((0,0), Arc::new(JobManager::new())); r.block.make_at_least(Vec3::new(0,0,0), Vec3::new(65535,65535,65535), -4); }*/ -} \ No newline at end of file +} + +*/ \ No newline at end of file diff --git a/worldsim/src/server/mod.rs b/worldsim/src/server/mod.rs index 7c94475d59..2df0a16269 100644 --- a/worldsim/src/server/mod.rs +++ b/worldsim/src/server/mod.rs @@ -71,9 +71,11 @@ impl Server { println!("new server found"); }, RegionManagerMsg::CreateRegion{region_id} => { + /* let mut r = Region::new(region_id, self.jobmanager.clone()); r.block.make_at_least(Vec3::new(0,0,0), Vec3::new(65535,65535,65535), 9); self.region.insert(region_id, r); + */ println!("create region"); }, RegionManagerMsg::TakeOverRegionFrom{region_id, server_id} => {