diff --git a/worldsim/src/lib.rs b/worldsim/src/lib.rs index 5502d405b4..1d176314ff 100644 --- a/worldsim/src/lib.rs +++ b/worldsim/src/lib.rs @@ -2,6 +2,7 @@ #![feature(const_generics, test)] #![feature(associated_type_bounds)] #![feature(generic_associated_types)] +#![feature(specialization)] extern crate serde_derive; #[macro_use] diff --git a/worldsim/src/lodstore/delta.rs b/worldsim/src/lodstore/delta.rs index 4fc8f048bc..521ec1cf32 100644 --- a/worldsim/src/lodstore/delta.rs +++ b/worldsim/src/lodstore/delta.rs @@ -2,11 +2,13 @@ use super::data::DetailStore; #[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that use super::entrylayer::EntryLayer; use super::layer::Layer; +use super::layer::ParentLayer; use super::lodpos::LodPos; #[allow(unused_imports)] use super::materializeable::Materializeable; #[allow(unused_imports)] use super::traversable::Traversable; +use std::slice::Iter; /* A LodDelta applies a change to a Lod The rules for LodDeltas are strict in order to make them as simple as possible. @@ -21,6 +23,12 @@ use super::traversable::Traversable; pub trait DeltaStore: Layer { type DETAIL; fn store(&mut self, pos: LodPos, value: Option); + fn iter(&self) -> Iter<(LodPos, Option)>; +} + +pub trait DeltaApplyer { + //pub trait DeltaApplyer, D: DeltaStore> { + fn apply_delta(&mut self); } #[derive(Default, Clone)] @@ -33,7 +41,7 @@ pub struct VecNestDelta { pub child: D, } -pub struct DeltaWriter<'a, C: DetailStore, D: DeltaStore> { +pub struct DeltaWriter<'a, COMMONDETAIL, C: DetailStore, D: DeltaStore> { pub delta: &'a mut D, pub data: &'a mut C, } @@ -46,30 +54,59 @@ pub struct VecDeltaIterMut<'a, D: DeltaStore> { pub(super) layer: &'a mut D, } -pub struct DataWriterIter { - pub(super) delta_iter: DT, +pub struct DataWriterIter { pub(super) data_iter: CT, + pub(super) delta_iter: DT, } //####################################################### -impl<'a, C: DetailStore, D: DeltaStore> DeltaWriter<'a, C, D> { +ERROR, we want DeltaApply on delta and mut data, the Iterator is the wrong place because its only for 1 pos. the DeltaWriter is part. wrong because we only want non mut delta + +impl<'a, COMMONDETAIL, C: DetailStore, D: DeltaStore> DeltaWriter<'a, COMMONDETAIL, C, D> { pub fn new(delta: &'a mut D, data: &'a mut C) -> Self { DeltaWriter { delta, data } } } +pub fn apply_delta, D: DeltaStore>(data: &mut C, delta: &D) { + +} + +impl DeltaApplyer for DataWriterIter { + default fn apply_delta(&mut self) { + + } +} + +impl, D: DeltaStore> DeltaApplyer for DataWriterIter + where + C: ParentLayer, + D: ParentLayer, +{ + fn apply_delta(&mut self) { + + } +} + + impl DeltaStore for VecDelta { type DETAIL = T; fn store(&mut self, pos: LodPos, value: Option) { self.detail.push((pos, value)); } + fn iter(&self) -> Iter<(LodPos, Option)> { + self.detail.iter() + } } impl DeltaStore for VecNestDelta { type DETAIL = T; fn store(&mut self, pos: LodPos, value: Option) { self.detail.push((pos, value)); } + fn iter(&self) -> Iter<(LodPos, Option)> { + self.detail.iter() + } } //####################################################### @@ -134,11 +171,11 @@ mod stests { assert_eq!(*w.trav_mut(i).get().get().get().mat(), 7_i8); w.trav_mut(i).get().get().get().store(123); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8); + assert_eq!(x.detail_index.len(), 1); assert_eq!(d.detail.len(), 0); assert_eq!(d.child.detail.len(), 0); assert_eq!(d.child.child.detail.len(), 0); assert_eq!(d.child.child.child.detail.len(), 1); - //assert_eq!(x.detail_index.len(),1); } } @@ -169,6 +206,27 @@ mod stests { let i = LodPos::xyz(0, 0, 0); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8); assert_eq!(x.detail_index.len(), 1); + assert_eq!(d.child.detail.len(), 0); + assert_eq!(d.child.child.detail.len(), 0); + assert_eq!(d.child.child.child.detail.len(), 3); + } + } + + #[test] + fn apply() { + let mut x = gen_simple_example(); + let mut d = ExampleDelta::default(); + let i = LodPos::xyz(2, 2, 2); + { + let mut w = DeltaWriter::new(&mut d, &mut x); + w.trav_mut(i).get().get().get().store(123); + assert_eq!(d.child.child.child.detail.len(), 1); + } + let mut x = gen_simple_example(); + //assert_ne!(w.trav(i).get().get().get().mat(), 123); + { + let mut w = DeltaWriter::new(&mut d, &mut x); + w.trav_mut().apply_delta() } } diff --git a/worldsim/src/lodstore/entrylayer.rs b/worldsim/src/lodstore/entrylayer.rs index dc7efdefd2..004e261a10 100644 --- a/worldsim/src/lodstore/entrylayer.rs +++ b/worldsim/src/lodstore/entrylayer.rs @@ -50,14 +50,14 @@ impl VecNestDelta { } impl - DeltaWriter<'_, HashNestLayer, VecNestDelta> + DeltaWriter<'_, T, HashNestLayer, VecNestDelta> { pub fn trav<'a>( &'a self, pos: LodPos, ) -> DataWriterIter< - VecDeltaIter<'a, VecNestDelta>, HashIter<'a, HashNestLayer>, + VecDeltaIter<'a, VecNestDelta>, > { DataWriterIter { delta_iter: self.delta.trav(pos), @@ -69,8 +69,8 @@ impl &'a mut self, pos: LodPos, ) -> DataWriterIter< - VecDeltaIterMut<'a, VecNestDelta>, HashIterMut<'a, HashNestLayer>, + VecDeltaIterMut<'a, VecNestDelta>, > { DataWriterIter { delta_iter: self.delta.trav_mut(pos), diff --git a/worldsim/src/lodstore/materializeable.rs b/worldsim/src/lodstore/materializeable.rs index 9a0372ceee..6bdc8673db 100644 --- a/worldsim/src/lodstore/materializeable.rs +++ b/worldsim/src/lodstore/materializeable.rs @@ -75,8 +75,8 @@ impl<'a, L: DetailStore> Materializeable<'a> for VecIterMut<'a, L> ///////////////// delta types -impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a> - for DataWriterIter +impl<'a, CT: Materializeable<'a>, DT: Deltalizeable> Materializeable<'a> + for DataWriterIter { type MAT_CHILD = CT::MAT_CHILD; diff --git a/worldsim/src/lodstore/traversable.rs b/worldsim/src/lodstore/traversable.rs index 0fb6fd0078..de1ed5de40 100644 --- a/worldsim/src/lodstore/traversable.rs +++ b/worldsim/src/lodstore/traversable.rs @@ -148,13 +148,13 @@ where } } -impl Traversable for DataWriterIter { - type TRAV_CHILD = DataWriterIter; +impl Traversable for DataWriterIter { + type TRAV_CHILD = DataWriterIter; - fn get(self) -> DataWriterIter { + fn get(self) -> DataWriterIter { DataWriterIter { - delta_iter: self.delta_iter.get(), data_iter: self.data_iter.get(), + delta_iter: self.delta_iter.get(), } } }