diff --git a/worldsim/src/lodstore/newdata.rs b/worldsim/src/lodstore/newdata.rs index 1a6931cfb0..d86a7c04ba 100644 --- a/worldsim/src/lodstore/newdata.rs +++ b/worldsim/src/lodstore/newdata.rs @@ -50,12 +50,7 @@ pub trait Key { } pub trait IndexStore { - type KEY: Key; - type INDEX: Copy; - const OWN_PER_PARENT: usize; // theoretically this can be auto calculated in a new trait, however rust ist detecting conflicting implementations - - fn load(&self, key: Self::KEY) -> Self::INDEX; - fn store(&mut self, key: Self::KEY, index: Self::INDEX); + fn load(&self, pos: LodPos) -> usize; } pub trait DetailStore { @@ -63,9 +58,9 @@ pub trait DetailStore { type DETAIL; const LEVEL: u8; - fn load(&self, key: Self::KEY) -> &Self::DETAIL; - fn load_mut(&mut self, key: Self::KEY) -> &mut Self::DETAIL; - fn store(&mut self, key: Self::KEY, detail: Self::DETAIL); + DER RETURNWERT MUSS EIN EIGENER TYPE SEIN JE NACHDEM VEC ODER HASH + + fn load(&self, pos: LodPos) -> usize; } pub trait Nestable: DetailStore { @@ -90,74 +85,55 @@ pub struct LayerResult<'a, N: DetailStore> { key: N::KEY, } -impl Index for u16 {} -impl Index for u32 {} -impl Index for LodPos {} - - -//TODO: optimize this self away! vtable -//TODO: arrr and the clone -impl KeyConvertable { - fn uncompress(&self, index: &u16) -> usize { index.clone() as usize } - fn compress(&self, key: &usize) -> u16 { key.clone() as u16 } -} -impl KeyConvertable { - fn uncompress(&self, index: &u32) -> usize { index.clone() as usize } - fn compress(&self, key: &usize) -> u32 { key.clone() as u32 } -} -impl KeyConvertable { - fn uncompress(&self, index: &LodPos) -> LodPos { index.clone() } - fn compress(&self, key: &LodPos) -> LodPos { key.clone() } -} - //####################################################### -pub struct VecVecLayer { +pub struct VecLayer { pub detail: Vec, - pub index: Vec, } -pub struct VecHashLayer { - pub detail: Vec, - pub index: HashMap, -} - -//T: own detail type -//PI: parents index type u16, u32 -pub struct VecVecNestLayer { - pub detail: Vec, - pub index: Vec, - pub nested: N, -} - -pub struct VecHashNestLayer { - pub detail: Vec, - pub index: HashMap, - pub nested: N, -} - -pub struct HashNoneNestLayer { +pub struct HashLayer { pub detail: HashMap, +} + +pub struct VecNestLayer { + pub detail: Vec, + pub index: Vec, + pub nested: N, +} + +pub struct HashNestLayer { + pub detail_index: HashMap, pub nested: N, } #[rustfmt::skip] -impl IndexStore for VecVecLayer { - type KEY = usize; type INDEX=PI; const OWN_PER_PARENT: usize = 4096; //TODO: calculate these correctly - fn load(&self, key: usize) -> PI { *self.index.get(key).unwrap() } - fn store(&mut self, key: usize, index: PI) { self.index.insert(key, index); } +impl IndexStore for VecNestLayer { + fn load(&self, pos: LodPos) -> usize { + let adjusted_pos = pos; + let pos_offset = 0; + let childs_per_own = 8; + let u1 = ( self.index[adjusted_pos * childs_per_own ) as usize + pos_offset; + return u1; + } } #[rustfmt::skip] -impl + DetailStore, T, PI: Copy, const L: u8> IndexStore for VecVecNestLayer { - type KEY = usize; type INDEX=PI; const OWN_PER_PARENT: usize = 32768; - fn load(&self, key: usize) -> PI { *self.index.get(key).unwrap() } - fn store(&mut self, key: usize, index: PI) { self.index.insert(key, index); } +impl IndexStore for HashNestLayer { + fn load(&self, pos: LodPos) -> usize { + let adjusted_pos = pos; + let pos_offset = 0; + let childs_per_own = 8; + let u1 = ( self.index[adjusted_pos * childs_per_own ) as usize + pos_offset; + return u1; + } } + + #[rustfmt::skip] -impl IndexStore for VecHashLayer { +impl IndexStore for HashNestLayer { type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 1337; fn load(&self, key: LodPos) -> PI { *self.index.get(&key).unwrap() } fn store(&mut self, key: LodPos, index: PI) { self.index.insert(key, index); } } + #[rustfmt::skip] impl + DetailStore, T, PI: Copy, const L: u8> IndexStore for VecHashNestLayer { type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 4096; @@ -289,14 +265,14 @@ impl<'a, N: IndexStore + DetailStore> Materializeable for LayerResult #[rustfmt::skip] pub type ExampleDelta = - HashNoneNestLayer< - VecHashNestLayer< - VecVecNestLayer< - VecVecLayer< - (), u16, 0 - > ,(), u32, 4 - > ,Option<()> , u16, 9 - > ,() , 13 + HashNestLayer< + VecNestLayer< + VecNestLayer< + VecLayer< + (), 0 + > ,(), u16, 4 + > ,Option<()> , u32, 9 + > ,() ,u16. 13 >; @@ -327,7 +303,7 @@ NEUE IDEE: IndexStore DirectHashLookup { store() -> - load(LodPos) -> LodPos + load(LodPos) -> LodAbs } NestedVecLokup {