cleanup after the fix which is now possible

This commit is contained in:
Marcel Märtens 2019-11-19 14:14:21 +01:00
parent a4a5cf048e
commit 4726c93f1c
9 changed files with 185 additions and 218 deletions

View File

@ -168,10 +168,10 @@ fn main() -> io::Result<()> {
let (server_tx, server_rx) = mpsc::channel::<ServerMsg>(); let (server_tx, server_rx) = mpsc::channel::<ServerMsg>();
let mut region_manager = RegionManager::new(region_manager_tx, server_rx); let mut region_manager = RegionManager::new(region_manager_tx, server_rx);
let mut job_manager: Arc<JobManager> = Arc::new(JobManager::new()); let job_manager: Arc<JobManager> = Arc::new(JobManager::new());
let mut server = let mut server =
worldsim::server::Server::new(server_tx, region_manager_rx, job_manager.clone()); worldsim::server::Server::new(server_tx, region_manager_rx, job_manager.clone());
let mut region = Region::new((0, 0), job_manager.clone()); let _region = Region::new((0, 0), job_manager.clone());
job_manager.repeat(move || region_manager.work()); job_manager.repeat(move || region_manager.work());
job_manager.repeat(move || server.work()); job_manager.repeat(move || server.work());

View File

@ -1,12 +1,12 @@
use super::index::ToOptionUsize;
use super::lodpos::LodPos;
use super::layer::{Layer, ParentLayer};
#[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that
use super::traversable::Traversable;
#[allow(unused_imports)]
use super::materializeable::Materializeable;
#[allow(unused_imports)] #[allow(unused_imports)]
use super::entrylayer::EntryLayer; use super::entrylayer::EntryLayer;
use super::index::ToOptionUsize;
use super::layer::{Layer, ParentLayer};
use super::lodpos::LodPos;
#[allow(unused_imports)]
use super::materializeable::Materializeable;
#[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that
use super::traversable::Traversable;
use fxhash::FxHashMap; use fxhash::FxHashMap;
pub trait IndexStore: ParentLayer { pub trait IndexStore: ParentLayer {
@ -145,9 +145,9 @@ impl<T, const L: u8> DetailStore for HashLayer<T, { L }> {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use crate::lodstore::data::*; use crate::lodstore::data::*;
use test::Bencher;
use std::{u16, u32};
use crate::lodstore::traversable::Traversable; use crate::lodstore::traversable::Traversable;
use std::{u16, u32};
use test::Bencher;
#[rustfmt::skip] #[rustfmt::skip]
pub type ExampleData = pub type ExampleData =
@ -257,8 +257,15 @@ pub mod tests {
let mut x = gen_simple_example(); let mut x = gen_simple_example();
assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 7_i8); assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 7_i8);
assert_eq!(*x.trav(LodPos::xyz(0, 0, 1)).get().get().get().mat(), 6_i8); assert_eq!(*x.trav(LodPos::xyz(0, 0, 1)).get().get().get().mat(), 6_i8);
x.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().store(123); x.trav_mut(LodPos::xyz(0, 0, 0))
assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 123_i8); .get()
.get()
.get()
.store(123);
assert_eq!(
*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(),
123_i8
);
} }
#[test] #[test]
@ -266,8 +273,15 @@ pub mod tests {
let mut x = gen_simple_example(); let mut x = gen_simple_example();
assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 7_i8); assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 7_i8);
let c = *x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(); let c = *x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat();
x.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().store(111 + c); x.trav_mut(LodPos::xyz(0, 0, 0))
assert_eq!(*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(), 118_i8); .get()
.get()
.get()
.store(111 + c);
assert_eq!(
*x.trav(LodPos::xyz(0, 0, 0)).get().get().get().mat(),
118_i8
);
} }
/* allow this once we guarante get to be consistent even on Hash Lookups! /* allow this once we guarante get to be consistent even on Hash Lookups!
@ -313,28 +327,4 @@ pub mod tests {
} }
b.iter(|| x.trav(access).get().get().get().mat()); b.iter(|| x.trav(access).get().get().get().mat());
} }
/*
pub struct MyIterMut<'a, C> {
pub( super ) layer: &'a mut C,
}
#[derive(Default, Clone)]
pub struct Layer<C> {
pub child: C,
}
pub trait EntryPoint {
type TRAV_MUT<'a>;
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT;
}
impl<C> EntryPoint
for Layer<C>
{
type TRAV_MUT<'a> = MyIterMut<'a, Layer<C>>;
fn trav_mut<'a>(&'a mut self, pos: u8) -> Self::TRAV_MUT {
MyIterMut {
layer: self,
}
}
}*/
} }

View File

@ -1,12 +1,12 @@
use super::data::{DetailStore}; use super::data::DetailStore;
use super::lodpos::LodPos;
use super::layer::{Layer};
#[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that #[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that
use super::entrylayer::EntryLayer; use super::entrylayer::EntryLayer;
#[allow(unused_imports)] use super::layer::Layer;
use super::traversable::Traversable; use super::lodpos::LodPos;
#[allow(unused_imports)] #[allow(unused_imports)]
use super::materializeable::Materializeable; use super::materializeable::Materializeable;
#[allow(unused_imports)]
use super::traversable::Traversable;
/* /*
A LodDelta applies a change to a Lod A LodDelta applies a change to a Lod
The rules for LodDeltas are strict in order to make them as simple as possible. The rules for LodDeltas are strict in order to make them as simple as possible.
@ -132,13 +132,7 @@ mod stests {
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
assert_eq!(*w.trav_mut(i).get().get().get().mat(), 7_i8); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 7_i8);
}
{
let mut w = DeltaWriter::new(&mut d, &mut x);
w.trav_mut(i).get().get().get().store(123); w.trav_mut(i).get().get().get().store(123);
}
{ //TODO: this shouldnt be necessary but somehow it is...
let mut w = DeltaWriter::new(&mut d, &mut x);
assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8);
assert_eq!(d.detail.len(), 0); assert_eq!(d.detail.len(), 0);
assert_eq!(d.child.detail.len(), 0); assert_eq!(d.child.detail.len(), 0);
@ -156,25 +150,22 @@ mod stests {
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
assert_eq!(*w.trav_mut(i).get().get().get().mat(), 7_i8); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 7_i8);
}
{
let mut w = DeltaWriter::new(&mut d, &mut x);
w.trav_mut(i).get().get().get().store(123); w.trav_mut(i).get().get().get().store(123);
} w.trav_mut(LodPos::xyz(0, 0, 1))
{ .get()
let mut w = DeltaWriter::new(&mut d, &mut x); .get()
w.trav_mut(LodPos::xyz(0, 0, 1)).get().get().get().store(111); .get()
} .store(111);
{ w.trav_mut(LodPos::xyz(0, 0, 2))
let mut w = DeltaWriter::new(&mut d, &mut x); .get()
w.trav_mut(LodPos::xyz(0, 0, 2)).get().get().get().store(112); .get()
} .get()
{ .store(112);
let mut w = DeltaWriter::new(&mut d, &mut x); w.trav_mut(LodPos::xyz(0, 0, 3))
w.trav_mut(LodPos::xyz(0, 0, 3)).get().get().get().store(111); .get()
} .get()
{ //TODO: this shouldnt be necessary but somehow it is... .get()
let mut w = DeltaWriter::new(&mut d, &mut x); .store(111);
let i = LodPos::xyz(0, 0, 0); let i = LodPos::xyz(0, 0, 0);
assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8); assert_eq!(*w.trav_mut(i).get().get().get().mat(), 123_i8);
assert_eq!(x.detail_index.len(), 1); assert_eq!(x.detail_index.len(), 1);
@ -187,7 +178,9 @@ mod stests {
let mut d = ExampleDelta::default(); let mut d = ExampleDelta::default();
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0));}); b.iter(|| {
w.trav_mut(LodPos::xyz(0, 0, 0));
});
} }
} }
@ -197,7 +190,9 @@ mod stests {
let mut d = ExampleDelta::default(); let mut d = ExampleDelta::default();
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().mat();}); b.iter(|| {
w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().mat();
});
} }
} }
@ -207,14 +202,11 @@ mod stests {
let mut d = ExampleDelta::default(); let mut d = ExampleDelta::default();
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get()); b.iter(|| {
w.trav_mut(LodPos::xyz(0, 0, 0)); w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get();
w.trav_mut(LodPos::xyz(0, 0, 0)); });
} }
} }
fn ddd<'a,'b:'a, D>() {
}
#[bench] #[bench]
fn bench_trav(b: &mut Bencher) { fn bench_trav(b: &mut Bencher) {
@ -222,50 +214,9 @@ mod stests {
let mut d = ExampleDelta::default(); let mut d = ExampleDelta::default();
{ {
let mut w = DeltaWriter::new(&mut d, &mut x); let mut w = DeltaWriter::new(&mut d, &mut x);
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0));}); b.iter(|| {
w.trav_mut(LodPos::xyz(0, 0, 0));
});
} }
} }
/*
pub struct ThisWorks<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisWorks<'a> {
fn reff<'b>(&'b mut self) -> &'b mut u64 {
self.ddd
}
}
pub struct ThisDoestn<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisDoestn<'a> {
fn reff<'b>(&'b mut self) -> &'a mut u64 where 'a: 'b {
self.ddd
}
}
pub struct ThisDoestnNeither<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisDoestnNeither<'a> {
fn reff<'b: 'a>(&'b mut self) -> &'a mut u64 {
self.ddd
}
}
#[bench]
fn bench_travss(b: &mut Bencher) {
let mut u: u64 = 1;
let mut d = ThisWorks{ddd: &mut u};
{
b.iter(|| *d.ddd = *d.ddd + 1_u64);
b.iter(|| {d.reff();});
d.reff();
d.reff();
}
}
*/
} }

View File

@ -1,5 +1,5 @@
use super::lodpos::{LodPos};
use super::delta::{DeltaStore, VecDeltaIterMut}; use super::delta::{DeltaStore, VecDeltaIterMut};
use super::lodpos::LodPos;
pub trait Deltalizeable { pub trait Deltalizeable {
type DELTA: DeltaStore; type DELTA: DeltaStore;

View File

@ -1,7 +1,9 @@
use super::data::{DetailStore, HashIter, HashIterMut, HashNestLayer};
use super::delta::{
DataWriterIter, DeltaStore, DeltaWriter, VecDeltaIter, VecDeltaIterMut, VecNestDelta,
};
use super::index::ToOptionUsize; use super::index::ToOptionUsize;
use super::lodpos::LodPos; use super::lodpos::LodPos;
use super::data::{HashNestLayer, DetailStore, HashIter, HashIterMut};
use super::delta::{VecNestDelta, DeltaStore, VecDeltaIter, VecDeltaIterMut, DataWriterIter, DeltaWriter};
use super::traversable::Traversable; use super::traversable::Traversable;
//TODO: actually implement EntryLayer //TODO: actually implement EntryLayer
@ -13,8 +15,7 @@ pub trait EntryLayer {
} }
///////////////// data types ///////////////// data types
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> HashNestLayer<C, T, I, { L }> impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> HashNestLayer<C, T, I, { L }> {
{
pub fn trav<'a>(&'a self, pos: LodPos) -> HashIter<'a, HashNestLayer<C, T, I, { L }>> { pub fn trav<'a>(&'a self, pos: LodPos) -> HashIter<'a, HashNestLayer<C, T, I, { L }>> {
HashIter { HashIter {
layer: self, layer: self,
@ -23,7 +24,10 @@ impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> HashNestLayer<C, T, I, {
} }
} }
pub fn trav_mut<'a>(&'a mut self, pos: LodPos) -> HashIterMut<'a, HashNestLayer<C, T, I, { L }>> { pub fn trav_mut<'a>(
&'a mut self,
pos: LodPos,
) -> HashIterMut<'a, HashNestLayer<C, T, I, { L }>> {
HashIterMut { HashIterMut {
layer: self, layer: self,
wanted: pos, wanted: pos,
@ -37,21 +41,37 @@ impl<D: DeltaStore, T, const L: u8> VecNestDelta<D, T, { L }> {
pub fn trav<'a>(&'a self, _pos: LodPos) -> VecDeltaIter<'a, VecNestDelta<D, T, { L }>> { pub fn trav<'a>(&'a self, _pos: LodPos) -> VecDeltaIter<'a, VecNestDelta<D, T, { L }>> {
VecDeltaIter { layer: self } VecDeltaIter { layer: self }
} }
pub fn trav_mut<'a>(&'a mut self, _pos: LodPos) -> VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>> { pub fn trav_mut<'a>(
&'a mut self,
_pos: LodPos,
) -> VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>> {
VecDeltaIterMut { layer: self } VecDeltaIterMut { layer: self }
} }
} }
impl<D: DeltaStore, C: DetailStore, T, I: ToOptionUsize, const L: u8> DeltaWriter<'_, HashNestLayer<C, T, I, { L }>, 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 }>>
{ {
pub fn trav<'a>(&'a self, pos: LodPos) -> DataWriterIter<VecDeltaIter<'a, VecNestDelta<D, T, { L }>>, HashIter<'a, HashNestLayer<C, T, I, { L }>>> { pub fn trav<'a>(
&'a self,
pos: LodPos,
) -> DataWriterIter<
VecDeltaIter<'a, VecNestDelta<D, T, { L }>>,
HashIter<'a, HashNestLayer<C, T, I, { L }>>,
> {
DataWriterIter { DataWriterIter {
delta_iter: self.delta.trav(pos), delta_iter: self.delta.trav(pos),
data_iter: self.data.trav(pos), data_iter: self.data.trav(pos),
} }
} }
pub fn trav_mut<'a>(&'a mut self, pos: LodPos) -> DataWriterIter< VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>, HashIterMut<'a, HashNestLayer<C, T, I, { L }>>> { pub fn trav_mut<'a>(
&'a mut self,
pos: LodPos,
) -> DataWriterIter<
VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>,
HashIterMut<'a, HashNestLayer<C, T, I, { L }>>,
> {
DataWriterIter { DataWriterIter {
delta_iter: self.delta.trav_mut(pos), delta_iter: self.delta.trav_mut(pos),
data_iter: self.data.trav_mut(pos), data_iter: self.data.trav_mut(pos),

View File

@ -1,7 +1,7 @@
use super::data::{DetailStore, HashLayer, HashNestLayer, VecLayer, VecNestLayer};
use super::delta::{DeltaStore, VecDelta, VecNestDelta};
use super::index::ToOptionUsize; use super::index::ToOptionUsize;
use super::lodpos::{two_pow_u, LodPos}; use super::lodpos::{two_pow_u, LodPos};
use super::data::{VecLayer, HashLayer, VecNestLayer, HashNestLayer, DetailStore};
use super::delta::{VecDelta, VecNestDelta, DeltaStore};
use vek::Vec3; use vek::Vec3;
pub trait Layer { pub trait Layer {

View File

@ -1,7 +1,7 @@
use super::lodpos::{LodPos}; use super::data::{DetailStore, HashIter, HashIterMut, VecIter, VecIterMut};
use super::data::{DetailStore, HashIter, VecIter, HashIterMut, VecIterMut}; use super::delta::DataWriterIter;
use super::delta::{DataWriterIter}; use super::deltalizeable::Deltalizeable;
use super::deltalizeable::{Deltalizeable}; use super::lodpos::LodPos;
/* /*
@ -53,7 +53,9 @@ impl<'a, L: DetailStore<KEY = LodPos>> Materializeable<'a> for HashIterMut<'a, L
impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIter<'a, L> { impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIter<'a, L> {
type MAT_CHILD = L::DETAIL; type MAT_CHILD = L::DETAIL;
fn mat(self) -> &'a L::DETAIL { DetailStore::load(self.layer, self.layer_key) } fn mat(self) -> &'a L::DETAIL {
DetailStore::load(self.layer, self.layer_key)
}
fn store(self, _mat: L::DETAIL) { fn store(self, _mat: L::DETAIL) {
unimplemented!("only call on mut Iter"); unimplemented!("only call on mut Iter");
//DetailStore::save(self.layer, self.layer_key, mat) //DetailStore::save(self.layer, self.layer_key, mat)
@ -63,7 +65,9 @@ fn store(self, _mat: L::DETAIL) {
impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIterMut<'a, L> { impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIterMut<'a, L> {
type MAT_CHILD = L::DETAIL; type MAT_CHILD = L::DETAIL;
fn mat(self) -> &'a L::DETAIL { DetailStore::load(self.layer, self.layer_key) } fn mat(self) -> &'a L::DETAIL {
DetailStore::load(self.layer, self.layer_key)
}
fn store(self, mat: L::DETAIL) { fn store(self, mat: L::DETAIL) {
DetailStore::save(self.layer, self.layer_key, mat) DetailStore::save(self.layer, self.layer_key, mat)
} }
@ -71,7 +75,9 @@ impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIterMut<'a, L>
///////////////// delta types ///////////////// delta types
impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a> for DataWriterIter<DT, CT> { impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a>
for DataWriterIter<DT, CT>
{
type MAT_CHILD = CT::MAT_CHILD; type MAT_CHILD = CT::MAT_CHILD;
fn mat(self) -> &'a CT::MAT_CHILD { fn mat(self) -> &'a CT::MAT_CHILD {

View File

@ -1,14 +1,14 @@
pub mod lodpos;
pub mod lodarea;
pub mod layer;
pub mod traversable;
pub mod materializeable;
pub mod deltalizeable;
pub mod entrylayer;
pub mod data; pub mod data;
pub mod delta; pub mod delta;
pub mod deltalizeable;
pub mod drill; pub mod drill;
pub mod entrylayer;
pub mod index; pub mod index;
pub mod layer;
pub mod lodarea;
pub mod lodpos;
pub mod materializeable;
pub mod traversable;
pub use data::{HashLayer, HashNestLayer, VecLayer, VecNestLayer}; pub use data::{HashLayer, HashNestLayer, VecLayer, VecNestLayer};
/* /*

View File

@ -1,9 +1,9 @@
use super::data::{DetailStore, HashIter, HashIterMut, IndexStore, VecIter, VecIterMut};
use super::delta::{DataWriterIter, DeltaStore, VecDeltaIter, VecDeltaIterMut};
use super::index::ToOptionUsize; use super::index::ToOptionUsize;
use super::lodpos::{multily_with_2_pow_n, relative_to_1d, LodPos};
use super::data::{DetailStore, IndexStore, HashIter, VecIter, HashIterMut, VecIterMut};
use super::delta::{DeltaStore, VecDeltaIter, VecDeltaIterMut, DataWriterIter};
#[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that #[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that
use super::layer::{Layer, ParentLayer}; use super::layer::{Layer, ParentLayer};
use super::lodpos::{multily_with_2_pow_n, relative_to_1d, LodPos};
pub trait Traversable { pub trait Traversable {
type TRAV_CHILD; type TRAV_CHILD;