mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
sync
This commit is contained in:
parent
4726c93f1c
commit
876702dd2d
@ -2,6 +2,7 @@
|
||||
#![feature(const_generics, test)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![feature(generic_associated_types)]
|
||||
#![feature(specialization)]
|
||||
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
|
@ -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<Self::DETAIL>);
|
||||
fn iter(&self) -> Iter<(LodPos, Option<Self::DETAIL>)>;
|
||||
}
|
||||
|
||||
pub trait DeltaApplyer<C, D> {
|
||||
//pub trait DeltaApplyer<COMMONDETAIL, C: DetailStore<DETAIL=COMMONDETAIL>, D: DeltaStore<DETAIL=COMMONDETAIL>> {
|
||||
fn apply_delta(&mut self);
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@ -33,7 +41,7 @@ pub struct VecNestDelta<D: DeltaStore, T, const L: u8> {
|
||||
pub child: D,
|
||||
}
|
||||
|
||||
pub struct DeltaWriter<'a, C: DetailStore, D: DeltaStore> {
|
||||
pub struct DeltaWriter<'a, COMMONDETAIL, C: DetailStore<DETAIL=COMMONDETAIL>, D: DeltaStore<DETAIL=COMMONDETAIL>> {
|
||||
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<DT, CT> {
|
||||
pub(super) delta_iter: DT,
|
||||
pub struct DataWriterIter<CT, DT> {
|
||||
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<DETAIL=COMMONDETAIL>, D: DeltaStore<DETAIL=COMMONDETAIL>> DeltaWriter<'a, COMMONDETAIL, C, D> {
|
||||
pub fn new(delta: &'a mut D, data: &'a mut C) -> Self {
|
||||
DeltaWriter { delta, data }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_delta<COMMONDETAIL, C: DetailStore<DETAIL=COMMONDETAIL>, D: DeltaStore<DETAIL=COMMONDETAIL>>(data: &mut C, delta: &D) {
|
||||
|
||||
}
|
||||
|
||||
impl<C, D> DeltaApplyer<C, D> for DataWriterIter<C,D> {
|
||||
default fn apply_delta(&mut self) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl<COMMONDETAIL, C: DetailStore<DETAIL=COMMONDETAIL>, D: DeltaStore<DETAIL=COMMONDETAIL>> DeltaApplyer<C, D> for DataWriterIter<C,D>
|
||||
where
|
||||
C: ParentLayer<CHILD: DetailStore>,
|
||||
D: ParentLayer<CHILD: DeltaStore>,
|
||||
{
|
||||
fn apply_delta(&mut self) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T, const L: u8> DeltaStore for VecDelta<T, { L }> {
|
||||
type DETAIL = T;
|
||||
fn store(&mut self, pos: LodPos, value: Option<Self::DETAIL>) {
|
||||
self.detail.push((pos, value));
|
||||
}
|
||||
fn iter(&self) -> Iter<(LodPos, Option<Self::DETAIL>)> {
|
||||
self.detail.iter()
|
||||
}
|
||||
}
|
||||
impl<C: DeltaStore, T, const L: u8> DeltaStore for VecNestDelta<C, T, { L }> {
|
||||
type DETAIL = T;
|
||||
fn store(&mut self, pos: LodPos, value: Option<Self::DETAIL>) {
|
||||
self.detail.push((pos, value));
|
||||
}
|
||||
fn iter(&self) -> Iter<(LodPos, Option<Self::DETAIL>)> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ impl<D: DeltaStore, T, const L: u8> VecNestDelta<D, T, { L }> {
|
||||
}
|
||||
|
||||
impl<D: DeltaStore, C: DetailStore, T, I: ToOptionUsize, const L: u8>
|
||||
DeltaWriter<'_, HashNestLayer<C, T, I, { L }>, VecNestDelta<D, T, { L }>>
|
||||
DeltaWriter<'_, T, HashNestLayer<C, T, I, { L }>, VecNestDelta<D, T, { L }>>
|
||||
{
|
||||
pub fn trav<'a>(
|
||||
&'a self,
|
||||
pos: LodPos,
|
||||
) -> DataWriterIter<
|
||||
VecDeltaIter<'a, VecNestDelta<D, T, { L }>>,
|
||||
HashIter<'a, HashNestLayer<C, T, I, { L }>>,
|
||||
VecDeltaIter<'a, VecNestDelta<D, T, { L }>>,
|
||||
> {
|
||||
DataWriterIter {
|
||||
delta_iter: self.delta.trav(pos),
|
||||
@ -69,8 +69,8 @@ impl<D: DeltaStore, C: DetailStore, T, I: ToOptionUsize, const L: u8>
|
||||
&'a mut self,
|
||||
pos: LodPos,
|
||||
) -> DataWriterIter<
|
||||
VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>,
|
||||
HashIterMut<'a, HashNestLayer<C, T, I, { L }>>,
|
||||
VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>,
|
||||
> {
|
||||
DataWriterIter {
|
||||
delta_iter: self.delta.trav_mut(pos),
|
||||
|
@ -75,8 +75,8 @@ impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIterMut<'a, L>
|
||||
|
||||
///////////////// delta types
|
||||
|
||||
impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a>
|
||||
for DataWriterIter<DT, CT>
|
||||
impl<'a, CT: Materializeable<'a>, DT: Deltalizeable> Materializeable<'a>
|
||||
for DataWriterIter<CT, DT>
|
||||
{
|
||||
type MAT_CHILD = CT::MAT_CHILD;
|
||||
|
||||
|
@ -148,13 +148,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DT: Traversable, CT: Traversable> Traversable for DataWriterIter<DT, CT> {
|
||||
type TRAV_CHILD = DataWriterIter<DT::TRAV_CHILD, CT::TRAV_CHILD>;
|
||||
impl<CT: Traversable, DT: Traversable> Traversable for DataWriterIter<CT, DT> {
|
||||
type TRAV_CHILD = DataWriterIter<CT::TRAV_CHILD, DT::TRAV_CHILD>;
|
||||
|
||||
fn get(self) -> DataWriterIter<DT::TRAV_CHILD, CT::TRAV_CHILD> {
|
||||
fn get(self) -> DataWriterIter<CT::TRAV_CHILD, DT::TRAV_CHILD> {
|
||||
DataWriterIter {
|
||||
delta_iter: self.delta_iter.get(),
|
||||
data_iter: self.data_iter.get(),
|
||||
delta_iter: self.delta_iter.get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user