mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
general worldsim cleanup
This commit is contained in:
parent
b297f3b479
commit
d58b78d92b
@ -28,10 +28,10 @@ use structopt::StructOpt;
|
|||||||
use tracing::{info, trace};
|
use tracing::{info, trace};
|
||||||
|
|
||||||
use worldsim::{
|
use worldsim::{
|
||||||
regionmanager::{RegionManager, meta::RegionManagerMsg},
|
|
||||||
server::meta::{ServerMsg},
|
|
||||||
job::JobManager,
|
job::JobManager,
|
||||||
region::Region,
|
region::Region,
|
||||||
|
regionmanager::{meta::RegionManagerMsg, RegionManager},
|
||||||
|
server::meta::ServerMsg,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
@ -169,11 +169,12 @@ fn main() -> io::Result<()> {
|
|||||||
|
|
||||||
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 mut job_manager: Arc<JobManager> = Arc::new(JobManager::new());
|
||||||
let mut server = worldsim::server::Server::new(server_tx,region_manager_rx,job_manager.clone());
|
let mut server =
|
||||||
let mut region = Region::new((0,0),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());
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
let mut server = Server::new(
|
let mut server = Server::new(
|
||||||
|
@ -2,21 +2,18 @@ use std::thread;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/*only have one JobManager per System because it bounds to all threads*/
|
/*only have one JobManager per System because it bounds to all threads*/
|
||||||
pub struct JobManager {
|
pub struct JobManager {}
|
||||||
|
|
||||||
}
|
impl JobManager {
|
||||||
|
|
||||||
impl JobManager{
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn repeat<F>(&self, mut f: F) where F: FnMut() -> bool, F: Send + 'static {
|
pub fn repeat<F>(&self, mut f: F)
|
||||||
let worker = thread::spawn(move || {
|
where
|
||||||
while f() {
|
F: FnMut() -> bool,
|
||||||
|
F: Send + 'static,
|
||||||
}
|
{
|
||||||
});
|
let _worker = thread::spawn(move || while f() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#![feature(const_generics, associated_type_bounds, euclidean_division, duration_float, trait_alias, bind_by_move_pattern_guards, test)]
|
#![feature(const_generics, test)]
|
||||||
|
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -6,10 +6,10 @@ extern crate log;
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
pub mod job;
|
pub mod job;
|
||||||
pub mod regionmanager;
|
|
||||||
pub mod region;
|
|
||||||
pub mod server;
|
|
||||||
pub mod lodstore;
|
pub mod lodstore;
|
||||||
|
pub mod region;
|
||||||
|
pub mod regionmanager;
|
||||||
|
pub mod server;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use super::lodpos::{
|
use super::lodpos::LodPos;
|
||||||
LodPos,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A LodArea is the area between 2 LodIndex
|
A LodArea is the area between 2 LodIndex
|
||||||
@ -14,18 +12,18 @@ pub struct LodArea {
|
|||||||
|
|
||||||
impl LodArea {
|
impl LodArea {
|
||||||
pub fn new(lower: LodPos, upper: LodPos) -> Self {
|
pub fn new(lower: LodPos, upper: LodPos) -> Self {
|
||||||
LodArea {
|
LodArea { lower, upper }
|
||||||
lower,
|
|
||||||
upper,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_inside(&self, lod: LodPos) -> bool {
|
pub fn is_inside(&self, lod: LodPos) -> bool {
|
||||||
let lower = self.lower.get();
|
let lower = self.lower.get();
|
||||||
let upper = self.upper.get();
|
let upper = self.upper.get();
|
||||||
let lod = lod.get();
|
let lod = lod.get();
|
||||||
lod[0] >= lower[0] && lod[0] <= upper[0] &&
|
lod[0] >= lower[0]
|
||||||
lod[1] >= lower[1] && lod[1] <= upper[1] &&
|
&& lod[0] <= upper[0]
|
||||||
lod[2] >= lower[2] && lod[2] <= upper[2]
|
&& lod[1] >= lower[1]
|
||||||
|
&& lod[1] <= upper[1]
|
||||||
|
&& lod[2] >= lower[2]
|
||||||
|
&& lod[2] <= upper[2]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,6 @@
|
|||||||
use super::area::LodArea;
|
|
||||||
//use super::delta::LodDelta;
|
|
||||||
use super::lodpos::{self, multily_with_2_pow_n, relative_to_1d, two_pow_u32, AbsIndex, LodPos};
|
|
||||||
use super::index::ToOptionUsize;
|
use super::index::ToOptionUsize;
|
||||||
|
use super::lodpos::{multily_with_2_pow_n, relative_to_1d, two_pow_u32, LodPos};
|
||||||
use fxhash::FxHashMap;
|
use fxhash::FxHashMap;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::{u16, u32};
|
use std::{u16, u32};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -20,7 +17,7 @@ use vek::*;
|
|||||||
|
|
||||||
traits:
|
traits:
|
||||||
- Layer: Every layer must implement this. KEY is the storage Type and either usize/LodPos. Layer is also defined here.
|
- Layer: Every layer must implement this. KEY is the storage Type and either usize/LodPos. Layer is also defined here.
|
||||||
- ParentLayer: Is a Layer that contains a CHILD layer and some const functions based on their const properties
|
- ParentLayer: Is a Layer that contains a CHILD layer and some const properties
|
||||||
- IndexStore: Every layer must implement this for their Layer::KEY and INDEX is often u16/u32.
|
- IndexStore: Every layer must implement this for their Layer::KEY and INDEX is often u16/u32.
|
||||||
The index is accessed by this layer to get the corresponding child.
|
The index is accessed by this layer to get the corresponding child.
|
||||||
Every Indexstore is a ParentLayer.
|
Every Indexstore is a ParentLayer.
|
||||||
@ -52,19 +49,13 @@ pub trait Layer {
|
|||||||
pub trait ParentLayer: Layer {
|
pub trait ParentLayer: Layer {
|
||||||
type CHILD: Layer;
|
type CHILD: Layer;
|
||||||
fn child(&self) -> &Self::CHILD;
|
fn child(&self) -> &Self::CHILD;
|
||||||
fn CHILDS_PER_OWN_TOTAL() -> usize {
|
const CHILDS_PER_OWN_TOTAL: usize = two_pow_u32(Self::LOG2_OF_CHILDS_PER_OWN_TOTAL) as usize;
|
||||||
two_pow_u32(Self::LOG2_OF_CHILDS_PER_OWN_TOTAL()) as usize
|
const LOG2_OF_CHILDS_PER_OWN_TOTAL: u8 = 3 * ({ Self::LEVEL } - Self::CHILD::LEVEL);
|
||||||
}
|
const CHILDS_PER_OWN: Vec3<u32> = Vec3 {
|
||||||
fn LOG2_OF_CHILDS_PER_OWN_TOTAL() -> u8 {
|
x: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
||||||
3 * ({ Self::LEVEL } - Self::CHILD::LEVEL)
|
y: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
||||||
}
|
z: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
||||||
fn CHILDS_PER_OWN() -> Vec3<u32> {
|
};
|
||||||
Vec3 {
|
|
||||||
x: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
|
||||||
y: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
|
||||||
z: two_pow_u32(Self::LEVEL - Self::CHILD::LEVEL) as u32,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IndexStore: ParentLayer {
|
pub trait IndexStore: ParentLayer {
|
||||||
@ -86,21 +77,21 @@ pub trait Materializeable<T> {
|
|||||||
|
|
||||||
//#######################################################
|
//#######################################################
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone)]
|
||||||
pub struct VecLayer<T, const L: u8> {
|
pub struct VecLayer<T, const L: u8> {
|
||||||
pub detail: Vec<T>,
|
pub detail: Vec<T>,
|
||||||
}
|
}
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone)]
|
||||||
pub struct HashLayer<T, const L: u8> {
|
pub struct HashLayer<T, const L: u8> {
|
||||||
pub detail: FxHashMap<LodPos, T>,
|
pub detail: FxHashMap<LodPos, T>,
|
||||||
}
|
}
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone)]
|
||||||
pub struct VecNestLayer<C: DetailStore, T, I: ToOptionUsize, const L: u8> {
|
pub struct VecNestLayer<C: DetailStore, T, I: ToOptionUsize, const L: u8> {
|
||||||
pub detail: Vec<T>,
|
pub detail: Vec<T>,
|
||||||
pub index: Vec<I>,
|
pub index: Vec<I>,
|
||||||
pub child: C,
|
pub child: C,
|
||||||
}
|
}
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone)]
|
||||||
pub struct HashNestLayer<C: DetailStore, T, I: ToOptionUsize, const L: u8> {
|
pub struct HashNestLayer<C: DetailStore, T, I: ToOptionUsize, const L: u8> {
|
||||||
pub detail_index: FxHashMap<LodPos, (T, I)>,
|
pub detail_index: FxHashMap<LodPos, (T, I)>,
|
||||||
pub child: C,
|
pub child: C,
|
||||||
@ -118,35 +109,42 @@ pub struct VecIter<'a, C: DetailStore> {
|
|||||||
layer_key: usize,
|
layer_key: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<T, const L: u8> Layer for VecLayer<T, { L }> {
|
impl<T, const L: u8> Layer for VecLayer<T, { L }> {
|
||||||
type KEY = ( usize ); const LEVEL: u8 = { L };
|
type KEY = (usize);
|
||||||
|
const LEVEL: u8 = { L };
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<T, const L: u8> Layer for HashLayer<T, { L }> {
|
impl<T, const L: u8> Layer for HashLayer<T, { L }> {
|
||||||
type KEY = ( LodPos ); const LEVEL: u8 = { L };
|
type KEY = (LodPos);
|
||||||
|
const LEVEL: u8 = { L };
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> Layer for VecNestLayer<C, T, I, { L }> {
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> Layer for VecNestLayer<C, T, I, { L }> {
|
||||||
type KEY = ( usize ); const LEVEL: u8 = { L };
|
type KEY = (usize);
|
||||||
|
const LEVEL: u8 = { L };
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> Layer for HashNestLayer<C, T, I, { L }> {
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> Layer for HashNestLayer<C, T, I, { L }> {
|
||||||
type KEY = ( LodPos ); const LEVEL: u8 = { L };
|
type KEY = (LodPos);
|
||||||
|
const LEVEL: u8 = { L };
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> ParentLayer
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> ParentLayer for VecNestLayer<C, T, I, { L }> {
|
for VecNestLayer<C, T, I, { L }>
|
||||||
|
{
|
||||||
type CHILD = C;
|
type CHILD = C;
|
||||||
fn child(&self) -> &Self::CHILD { &self.child }
|
fn child(&self) -> &Self::CHILD {
|
||||||
|
&self.child
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> ParentLayer
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> ParentLayer for HashNestLayer<C, T, I, { L }> {
|
for HashNestLayer<C, T, I, { L }>
|
||||||
|
{
|
||||||
type CHILD = C;
|
type CHILD = C;
|
||||||
fn child(&self) -> &Self::CHILD { &self.child }
|
fn child(&self) -> &Self::CHILD {
|
||||||
|
&self.child
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 }> {
|
||||||
|
#[allow(dead_code)]
|
||||||
fn trav(&self, pos: LodPos) -> HashIter<Self> {
|
fn trav(&self, pos: LodPos) -> HashIter<Self> {
|
||||||
HashIter {
|
HashIter {
|
||||||
layer: &self,
|
layer: &self,
|
||||||
@ -156,43 +154,44 @@ impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> HashNestLayer<C, T, I, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> IndexStore for VecNestLayer<C, T, I, { L }> {
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> IndexStore for VecNestLayer<C, T, I, { L }> {
|
||||||
type INDEX = I;
|
type INDEX = I;
|
||||||
fn load(&self, key: Self::KEY) -> Self::INDEX { self.index[key] }
|
fn load(&self, key: Self::KEY) -> Self::INDEX {
|
||||||
|
self.index[key]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> IndexStore
|
||||||
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> IndexStore for HashNestLayer<C, T, I, { L }> {
|
for HashNestLayer<C, T, I, { L }>
|
||||||
|
{
|
||||||
type INDEX = I;
|
type INDEX = I;
|
||||||
fn load(&self, key: Self::KEY) -> Self::INDEX {
|
fn load(&self, key: Self::KEY) -> Self::INDEX {
|
||||||
debug_assert_eq!(key, key.align_to_level({ L }));
|
debug_assert_eq!(key, key.align_to_level({ L }));
|
||||||
self.detail_index[&key].1
|
self.detail_index[&key].1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl<C: DetailStore, I: ToOptionUsize, T, const L: u8> DetailStore
|
||||||
#[rustfmt::skip]
|
for VecNestLayer<C, T, I, { L }>
|
||||||
impl<C: DetailStore, I: ToOptionUsize, T, const L: u8> DetailStore for VecNestLayer<C, T, I, { L }> {
|
{
|
||||||
type DETAIL = T;
|
type DETAIL = T;
|
||||||
fn load(&self, key: Self::KEY) -> &Self::DETAIL {
|
fn load(&self, key: Self::KEY) -> &Self::DETAIL {
|
||||||
&self.detail[key]
|
&self.detail[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
impl<C: DetailStore, I: ToOptionUsize, T, const L: u8> DetailStore
|
||||||
impl<C: DetailStore, I: ToOptionUsize, T, const L: u8> DetailStore for HashNestLayer<C, T, I, { L }> {
|
for HashNestLayer<C, T, I, { L }>
|
||||||
|
{
|
||||||
type DETAIL = T;
|
type DETAIL = T;
|
||||||
fn load(&self, key: LodPos) -> &Self::DETAIL {
|
fn load(&self, key: LodPos) -> &Self::DETAIL {
|
||||||
debug_assert_eq!(key, key.align_to_level({ L }));
|
debug_assert_eq!(key, key.align_to_level({ L }));
|
||||||
&self.detail_index[&key].0
|
&self.detail_index[&key].0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<T, const L: u8> DetailStore for VecLayer<T, { L }> {
|
impl<T, const L: u8> DetailStore for VecLayer<T, { L }> {
|
||||||
type DETAIL = T;
|
type DETAIL = T;
|
||||||
fn load(&self, key: usize) -> &Self::DETAIL {
|
fn load(&self, key: usize) -> &Self::DETAIL {
|
||||||
&self.detail[key]
|
&self.detail[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
|
||||||
impl<T, const L: u8> DetailStore for HashLayer<T, { L }> {
|
impl<T, const L: u8> DetailStore for HashLayer<T, { L }> {
|
||||||
type DETAIL = T;
|
type DETAIL = T;
|
||||||
fn load(&self, key: LodPos) -> &Self::DETAIL {
|
fn load(&self, key: LodPos) -> &Self::DETAIL {
|
||||||
@ -202,13 +201,22 @@ impl<T, const L: u8> DetailStore for HashLayer<T, { L }> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, L: DetailStore<KEY = LodPos> + IndexStore> Traversable<VecIter<'a, L::CHILD>>
|
impl<'a, L: DetailStore<KEY = LodPos> + IndexStore> Traversable<VecIter<'a, L::CHILD>>
|
||||||
for HashIter<'a, L>
|
for HashIter<'a, L>
|
||||||
where
|
where
|
||||||
L::CHILD: DetailStore, {
|
L::CHILD: DetailStore,
|
||||||
|
{
|
||||||
fn get(self) -> VecIter<'a, L::CHILD> {
|
fn get(self) -> VecIter<'a, L::CHILD> {
|
||||||
let child_lod = self.wanted.align_to_level(L::CHILD::LEVEL );
|
let child_lod = self.wanted.align_to_level(L::CHILD::LEVEL);
|
||||||
let pos_offset = relative_to_1d(child_lod, self.layer_lod, L::CHILD::LEVEL, L::CHILDS_PER_OWN());
|
let pos_offset = relative_to_1d(
|
||||||
let layer_key = ( multily_with_2_pow_n( IndexStore::load(self.layer, self.layer_lod).into_usize(), L::LOG2_OF_CHILDS_PER_OWN_TOTAL()) ) + pos_offset;
|
child_lod,
|
||||||
|
self.layer_lod,
|
||||||
|
L::CHILD::LEVEL,
|
||||||
|
L::CHILDS_PER_OWN,
|
||||||
|
);
|
||||||
|
let layer_key = (multily_with_2_pow_n(
|
||||||
|
IndexStore::load(self.layer, self.layer_lod).into_usize(),
|
||||||
|
L::LOG2_OF_CHILDS_PER_OWN_TOTAL,
|
||||||
|
)) + pos_offset;
|
||||||
VecIter {
|
VecIter {
|
||||||
layer: self.layer.child(),
|
layer: self.layer.child(),
|
||||||
wanted: self.wanted,
|
wanted: self.wanted,
|
||||||
@ -219,13 +227,22 @@ for HashIter<'a, L>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, L: DetailStore<KEY = usize> + IndexStore> Traversable<VecIter<'a, L::CHILD>>
|
impl<'a, L: DetailStore<KEY = usize> + IndexStore> Traversable<VecIter<'a, L::CHILD>>
|
||||||
for VecIter<'a, L>
|
for VecIter<'a, L>
|
||||||
where
|
where
|
||||||
L::CHILD: DetailStore, {
|
L::CHILD: DetailStore,
|
||||||
|
{
|
||||||
fn get(self) -> VecIter<'a, L::CHILD> {
|
fn get(self) -> VecIter<'a, L::CHILD> {
|
||||||
let child_lod = self.wanted.align_to_level(L::CHILD::LEVEL );
|
let child_lod = self.wanted.align_to_level(L::CHILD::LEVEL);
|
||||||
let pos_offset = relative_to_1d(child_lod, self.layer_lod, L::CHILD::LEVEL, L::CHILDS_PER_OWN());
|
let pos_offset = relative_to_1d(
|
||||||
let layer_key = ( multily_with_2_pow_n( IndexStore::load(self.layer, self.layer_key).into_usize(), L::LOG2_OF_CHILDS_PER_OWN_TOTAL()) ) + pos_offset;
|
child_lod,
|
||||||
|
self.layer_lod,
|
||||||
|
L::CHILD::LEVEL,
|
||||||
|
L::CHILDS_PER_OWN,
|
||||||
|
);
|
||||||
|
let layer_key = (multily_with_2_pow_n(
|
||||||
|
IndexStore::load(self.layer, self.layer_key).into_usize(),
|
||||||
|
L::LOG2_OF_CHILDS_PER_OWN_TOTAL,
|
||||||
|
)) + pos_offset;
|
||||||
VecIter {
|
VecIter {
|
||||||
layer: self.layer.child(),
|
layer: self.layer.child(),
|
||||||
wanted: self.wanted,
|
wanted: self.wanted,
|
||||||
@ -235,13 +252,13 @@ for VecIter<'a, L>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, L: DetailStore<KEY=LodPos>> Materializeable<&'a L::DETAIL> for HashIter<'a, L> {
|
impl<'a, L: DetailStore<KEY = LodPos>> Materializeable<&'a L::DETAIL> for HashIter<'a, L> {
|
||||||
fn mat(self) -> &'a L::DETAIL {
|
fn mat(self) -> &'a L::DETAIL {
|
||||||
DetailStore::load(self.layer, self.layer_lod)
|
DetailStore::load(self.layer, self.layer_lod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, L: DetailStore<KEY=usize>> Materializeable<&'a L::DETAIL> for VecIter<'a, L> {
|
impl<'a, L: DetailStore<KEY = usize>> Materializeable<&'a L::DETAIL> for VecIter<'a, L> {
|
||||||
fn mat(self) -> &'a L::DETAIL {
|
fn mat(self) -> &'a L::DETAIL {
|
||||||
DetailStore::load(self.layer, self.layer_key)
|
DetailStore::load(self.layer, self.layer_key)
|
||||||
}
|
}
|
||||||
@ -270,20 +287,57 @@ mod tests {
|
|||||||
ExampleData {
|
ExampleData {
|
||||||
detail_index,
|
detail_index,
|
||||||
child: VecNestLayer {
|
child: VecNestLayer {
|
||||||
detail: vec!((),(),()),
|
detail: vec![(), (), ()],
|
||||||
index: vec!(0,1,u32::MAX),
|
index: vec![0, 1, u32::MAX],
|
||||||
child: VecNestLayer {
|
child: VecNestLayer {
|
||||||
detail: vec!(None,None,None,Some(()),Some(()),None,None,None,None,None,None,None,None,None,None,None),
|
detail: vec![
|
||||||
index: vec!(0,u16::MAX,u16::MAX,0,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX,u16::MAX),
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(()),
|
||||||
|
Some(()),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
],
|
||||||
|
index: vec![
|
||||||
|
0,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
0,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
u16::MAX,
|
||||||
|
],
|
||||||
child: VecLayer {
|
child: VecLayer {
|
||||||
detail: vec!(7,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
|
detail: vec![
|
||||||
|
7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compilation() {
|
fn compilation() {
|
||||||
let x = ExampleData::default();
|
let x = ExampleData::default();
|
||||||
@ -291,7 +345,7 @@ mod tests {
|
|||||||
if false {
|
if false {
|
||||||
let y = x.trav(i);
|
let y = x.trav(i);
|
||||||
let ttc = y.get().get().get();
|
let ttc = y.get().get().get();
|
||||||
let tt = ttc.mat();
|
let _tt = ttc.mat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
use vek::*;
|
|
||||||
use std::ops::Sub;
|
|
||||||
use std::ops::Add;
|
|
||||||
use std::cmp;
|
|
||||||
use std::fmt;
|
|
||||||
use std::{u16, u32};
|
use std::{u16, u32};
|
||||||
|
|
||||||
pub trait ToOptionUsize: Copy {
|
pub trait ToOptionUsize: Copy {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use vek::*;
|
|
||||||
use std::ops::Sub;
|
|
||||||
use std::ops::Add;
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::ops::Add;
|
||||||
|
use std::ops::Sub;
|
||||||
|
use vek::*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A region owns the Values from in (0, 2048) in steps of 1/32.
|
A region owns the Values from in (0, 2048) in steps of 1/32.
|
||||||
@ -33,9 +33,12 @@ pub struct LodPos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*does not work on big endian!*/
|
/*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_X_MASK: u64 =
|
||||||
const BIT_Y_MASK: u64 = 0b0000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1100_0000_0000_0000_0000;
|
0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0011_1111_1111_1111_1111;
|
||||||
const BIT_Z_MASK: u64 = 0b0000_0000_0011_1111_1111_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000;
|
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;
|
const BIT_X_MASK32: u32 = 0b0000_0000_0000_0011_1111_1111_1111_1111;
|
||||||
const BIT_Y_OFFSET: u8 = 18;
|
const BIT_Y_OFFSET: u8 = 18;
|
||||||
const BIT_Z_OFFSET: u8 = 36;
|
const BIT_Z_OFFSET: u8 = 36;
|
||||||
@ -43,16 +46,18 @@ const BIT_Z_OFFSET: u8 = 36;
|
|||||||
//TODO: Optimize!
|
//TODO: Optimize!
|
||||||
impl LodPos {
|
impl LodPos {
|
||||||
pub fn new(data: Vec3<u32>) -> Self {
|
pub fn new(data: Vec3<u32>) -> Self {
|
||||||
let mut index = LodPos {data: 0};
|
let mut index = LodPos { data: 0 };
|
||||||
index.set(data);
|
index.set(data);
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn xyz(x: u32, y: u32, z: u32) -> Self {
|
pub fn xyz(x: u32, y: u32, z: u32) -> Self {
|
||||||
LodPos {data: Self::encode(&x, &y, &z)}
|
LodPos {
|
||||||
|
data: Self::encode(&x, &y, &z),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self) -> Vec3<u32> {
|
pub fn get(&self) -> Vec3<u32> {
|
||||||
Vec3::from(Self::decode(&self.data))
|
Vec3::from(Self::decode(&self.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,30 +67,33 @@ impl LodPos {
|
|||||||
|
|
||||||
fn encode(x: &u32, y: &u32, z: &u32) -> u64 {
|
fn encode(x: &u32, y: &u32, z: &u32) -> u64 {
|
||||||
let x = (x & BIT_X_MASK32) as u64;
|
let x = (x & BIT_X_MASK32) as u64;
|
||||||
let y = ((y & BIT_X_MASK32) as u64 ) << BIT_Y_OFFSET;
|
let y = ((y & BIT_X_MASK32) as u64) << BIT_Y_OFFSET;
|
||||||
let z = ((z & BIT_X_MASK32) as u64 ) << BIT_Z_OFFSET;
|
let z = ((z & BIT_X_MASK32) as u64) << BIT_Z_OFFSET;
|
||||||
x + y + z
|
x + y + z
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode(data: &u64) -> (u32, u32, u32) {
|
fn decode(data: &u64) -> (u32, u32, u32) {
|
||||||
let x = (data & BIT_X_MASK) as u32;
|
let x = (data & BIT_X_MASK) as u32;
|
||||||
let y = ((data & BIT_Y_MASK) >> BIT_Y_OFFSET ) as u32;
|
let y = ((data & BIT_Y_MASK) >> BIT_Y_OFFSET) as u32;
|
||||||
let z = ((data & BIT_Z_MASK) >> BIT_Z_OFFSET ) as u32;
|
let z = ((data & BIT_Z_MASK) >> BIT_Z_OFFSET) as u32;
|
||||||
(x,y,z)
|
(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn align_to_level(&self, layer: u8) -> LodPos {
|
pub fn align_to_level(&self, layer: u8) -> LodPos {
|
||||||
let xyz = self.get();
|
let xyz = self.get();
|
||||||
let f = two_pow_u(layer) as u32;
|
let f = two_pow_u(layer) as u32;
|
||||||
LodPos::new(xyz.map(|i| {
|
LodPos::new(xyz.map(|i| (i / f) * f))
|
||||||
(i / f) * f
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_highest_level_that_fits(&self) -> u8 {
|
pub fn get_highest_level_that_fits(&self) -> u8 {
|
||||||
let pos = self.get();
|
let pos = self.get();
|
||||||
cmp::min( cmp::min(cmp::min(pos[0].trailing_zeros(),
|
cmp::min(
|
||||||
pos[1].trailing_zeros()), pos[2].trailing_zeros()), 15) as u8
|
cmp::min(
|
||||||
|
cmp::min(pos[0].trailing_zeros(), pos[1].trailing_zeros()),
|
||||||
|
pos[2].trailing_zeros(),
|
||||||
|
),
|
||||||
|
15,
|
||||||
|
) as u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +113,7 @@ pub struct AbsIndex {
|
|||||||
|
|
||||||
impl AbsIndex {
|
impl AbsIndex {
|
||||||
pub fn new(layer: u8, index: usize) -> Self {
|
pub fn new(layer: u8, index: usize) -> Self {
|
||||||
AbsIndex {
|
AbsIndex { layer, index }
|
||||||
layer,
|
|
||||||
index,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +127,7 @@ impl Sub for LodPos {
|
|||||||
type Output = LodPos;
|
type Output = LodPos;
|
||||||
fn sub(self, rhs: LodPos) -> Self::Output {
|
fn sub(self, rhs: LodPos) -> Self::Output {
|
||||||
LodPos {
|
LodPos {
|
||||||
data: self.data - rhs.data /*fast but has overflow issues*/
|
data: self.data - rhs.data, /*fast but has overflow issues*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +136,7 @@ impl Add for LodPos {
|
|||||||
type Output = LodPos;
|
type Output = LodPos;
|
||||||
fn add(self, rhs: LodPos) -> Self::Output {
|
fn add(self, rhs: LodPos) -> Self::Output {
|
||||||
LodPos {
|
LodPos {
|
||||||
data: self.data + rhs.data /*fast but has overflow issues*/
|
data: self.data + rhs.data, /*fast but has overflow issues*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,26 +148,33 @@ pub const fn two_pow_u32(n: u8) -> u32 {
|
|||||||
1 << n
|
1 << n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn multily_with_2_pow_n(a: usize, n: u8) -> usize { //return a * 2^n but fast
|
pub const fn multily_with_2_pow_n(a: usize, n: u8) -> usize {
|
||||||
|
//return a * 2^n but fast
|
||||||
a << n
|
a << n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn relative_to_1d(child_lod: LodPos, parent_lod: LodPos, child_layer: u8, relative_size: Vec3<u32>) -> usize {
|
pub fn relative_to_1d(
|
||||||
|
child_lod: LodPos,
|
||||||
|
parent_lod: LodPos,
|
||||||
|
child_layer: u8,
|
||||||
|
relative_size: Vec3<u32>,
|
||||||
|
) -> usize {
|
||||||
let width = two_pow_u32(child_layer) as u32;
|
let width = two_pow_u32(child_layer) as u32;
|
||||||
let index = (child_lod.get() - parent_lod.get()).map(|e| e / width);
|
let index = (child_lod.get() - parent_lod.get()).map(|e| e / width);
|
||||||
(index[0] * relative_size[2] * relative_size[1] + index[1] * relative_size[2] + index[2]) as usize
|
(index[0] * relative_size[2] * relative_size[1] + index[1] * relative_size[2] + index[2])
|
||||||
|
as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min(lhs: LodPos, rhs: LodPos) -> LodPos {
|
pub fn min(lhs: LodPos, rhs: LodPos) -> LodPos {
|
||||||
let lhs = lhs.get();
|
let lhs = lhs.get();
|
||||||
let rhs = rhs.get();
|
let rhs = rhs.get();
|
||||||
LodPos::new(lhs.map2(rhs, |a,b| cmp::min(a,b)))
|
LodPos::new(lhs.map2(rhs, |a, b| cmp::min(a, b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max(lhs: LodPos, rhs: LodPos) -> LodPos {
|
pub fn max(lhs: LodPos, rhs: LodPos) -> LodPos {
|
||||||
let lhs = lhs.get();
|
let lhs = lhs.get();
|
||||||
let rhs = rhs.get();
|
let rhs = rhs.get();
|
||||||
LodPos::new(lhs.map2(rhs, |a,b| cmp::max(a,b)))
|
LodPos::new(lhs.map2(rhs, |a, b| cmp::max(a, b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************
|
/*************
|
||||||
@ -171,110 +183,107 @@ pub fn max(lhs: LodPos, rhs: LodPos) -> LodPos {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{lodstore::lodpos::two_pow_u32, lodstore::lodpos::LodPos};
|
||||||
lodstore::lodpos::LodPos,
|
|
||||||
lodstore::lodpos::two_pow_u32,
|
|
||||||
};
|
|
||||||
use vek::*;
|
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
use vek::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn setter_getter() {
|
fn setter_getter() {
|
||||||
let i = LodPos::xyz(0,0,0);
|
let i = LodPos::xyz(0, 0, 0);
|
||||||
assert_eq!(i.get(), Vec3::new(0,0,0));
|
assert_eq!(i.get(), Vec3::new(0, 0, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(1337,0,0);
|
let i = LodPos::xyz(1337, 0, 0);
|
||||||
assert_eq!(i.get(), Vec3::new(1337,0,0));
|
assert_eq!(i.get(), Vec3::new(1337, 0, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(0,1337,0);
|
let i = LodPos::xyz(0, 1337, 0);
|
||||||
assert_eq!(i.get(), Vec3::new(0,1337,0));
|
assert_eq!(i.get(), Vec3::new(0, 1337, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(0,0,1337);
|
let i = LodPos::xyz(0, 0, 1337);
|
||||||
assert_eq!(i.get(), Vec3::new(0,0,1337));
|
assert_eq!(i.get(), Vec3::new(0, 0, 1337));
|
||||||
|
|
||||||
let i = LodPos::xyz(1,1,1);
|
let i = LodPos::xyz(1, 1, 1);
|
||||||
assert_eq!(i.get(), Vec3::new(1,1,1));
|
assert_eq!(i.get(), Vec3::new(1, 1, 1));
|
||||||
|
|
||||||
let i = LodPos::xyz(262143,262143,262143);
|
let i = LodPos::xyz(262143, 262143, 262143);
|
||||||
assert_eq!(i.get(), Vec3::new(262143,262143,262143));
|
assert_eq!(i.get(), Vec3::new(262143, 262143, 262143));
|
||||||
|
|
||||||
let i = LodPos::xyz(262144,262144,262144); //overflow
|
let i = LodPos::xyz(262144, 262144, 262144); //overflow
|
||||||
assert_eq!(i.get(), Vec3::new(0,0,0));
|
assert_eq!(i.get(), Vec3::new(0, 0, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(42,1337,69);
|
let i = LodPos::xyz(42, 1337, 69);
|
||||||
assert_eq!(i.get(), Vec3::new(42,1337,69));
|
assert_eq!(i.get(), Vec3::new(42, 1337, 69));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn align() {
|
fn align() {
|
||||||
let i = LodPos::xyz(1337,0,0).align_to_level(4);
|
let i = LodPos::xyz(1337, 0, 0).align_to_level(4);
|
||||||
assert_eq!(i.get(), Vec3::new(1328,0,0));
|
assert_eq!(i.get(), Vec3::new(1328, 0, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(1337,1800,0).align_to_level(5);
|
let i = LodPos::xyz(1337, 1800, 0).align_to_level(5);
|
||||||
assert_eq!(i.get(), Vec3::new(1312,1792,0));
|
assert_eq!(i.get(), Vec3::new(1312, 1792, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(1337,0,50).align_to_level(3);
|
let i = LodPos::xyz(1337, 0, 50).align_to_level(3);
|
||||||
assert_eq!(i.get(), Vec3::new(1336,0,48));
|
assert_eq!(i.get(), Vec3::new(1336, 0, 48));
|
||||||
|
|
||||||
let i = LodPos::xyz(1335,0,0).align_to_level(3);
|
let i = LodPos::xyz(1335, 0, 0).align_to_level(3);
|
||||||
assert_eq!(i.get(), Vec3::new(1328,0,0));
|
assert_eq!(i.get(), Vec3::new(1328, 0, 0));
|
||||||
|
|
||||||
let i = LodPos::xyz(31337,22000,25000).align_to_level(7);
|
let i = LodPos::xyz(31337, 22000, 25000).align_to_level(7);
|
||||||
assert_eq!(i.get(), Vec3::new(31232,21888,24960));
|
assert_eq!(i.get(), Vec3::new(31232, 21888, 24960));
|
||||||
|
|
||||||
let i = LodPos::xyz(31337,22000,25000).align_to_level(0);
|
let i = LodPos::xyz(31337, 22000, 25000).align_to_level(0);
|
||||||
assert_eq!(i.get(), Vec3::new(31337,22000,25000));
|
assert_eq!(i.get(), Vec3::new(31337, 22000, 25000));
|
||||||
|
|
||||||
let i = LodPos::xyz(0,0,0).align_to_level(4);
|
let i = LodPos::xyz(0, 0, 0).align_to_level(4);
|
||||||
assert_eq!(i.get(), Vec3::new(0,0,0));
|
assert_eq!(i.get(), Vec3::new(0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_highest_level_that_fits() {
|
fn get_highest_level_that_fits() {
|
||||||
let i = LodPos::xyz(0,0,0);
|
let i = LodPos::xyz(0, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 15);
|
assert_eq!(i.get_highest_level_that_fits(), 15);
|
||||||
let i = LodPos::xyz(1,0,0);
|
let i = LodPos::xyz(1, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 0);
|
assert_eq!(i.get_highest_level_that_fits(), 0);
|
||||||
let i = LodPos::xyz(2,0,0);
|
let i = LodPos::xyz(2, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 1);
|
assert_eq!(i.get_highest_level_that_fits(), 1);
|
||||||
let i = LodPos::xyz(3,0,0);
|
let i = LodPos::xyz(3, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 0);
|
assert_eq!(i.get_highest_level_that_fits(), 0);
|
||||||
let i = LodPos::xyz(4,0,0);
|
let i = LodPos::xyz(4, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 2);
|
assert_eq!(i.get_highest_level_that_fits(), 2);
|
||||||
let i = LodPos::xyz(5,0,0);
|
let i = LodPos::xyz(5, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 0);
|
assert_eq!(i.get_highest_level_that_fits(), 0);
|
||||||
|
|
||||||
let i = LodPos::xyz(1337,0,0);
|
let i = LodPos::xyz(1337, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 0);
|
assert_eq!(i.get_highest_level_that_fits(), 0);
|
||||||
|
|
||||||
let i = LodPos::xyz(1337,1800,0);
|
let i = LodPos::xyz(1337, 1800, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 0);
|
assert_eq!(i.get_highest_level_that_fits(), 0);
|
||||||
|
|
||||||
let i = LodPos::xyz(1338,0,50);
|
let i = LodPos::xyz(1338, 0, 50);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 1);
|
assert_eq!(i.get_highest_level_that_fits(), 1);
|
||||||
|
|
||||||
let i = LodPos::xyz(1336,0,0);
|
let i = LodPos::xyz(1336, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 3);
|
assert_eq!(i.get_highest_level_that_fits(), 3);
|
||||||
|
|
||||||
let i = LodPos::xyz(31348,22000,25000);
|
let i = LodPos::xyz(31348, 22000, 25000);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 2);
|
assert_eq!(i.get_highest_level_that_fits(), 2);
|
||||||
|
|
||||||
let i = LodPos::xyz(0,0,0);
|
let i = LodPos::xyz(0, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 15);
|
assert_eq!(i.get_highest_level_that_fits(), 15);
|
||||||
|
|
||||||
let i = LodPos::xyz(65536,0,0);
|
let i = LodPos::xyz(65536, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 15);
|
assert_eq!(i.get_highest_level_that_fits(), 15);
|
||||||
|
|
||||||
let i = LodPos::xyz(32768,0,0);
|
let i = LodPos::xyz(32768, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 15);
|
assert_eq!(i.get_highest_level_that_fits(), 15);
|
||||||
|
|
||||||
let i = LodPos::xyz(16384,0,0);
|
let i = LodPos::xyz(16384, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 14);
|
assert_eq!(i.get_highest_level_that_fits(), 14);
|
||||||
|
|
||||||
let i = LodPos::xyz(8192,0,0);
|
let i = LodPos::xyz(8192, 0, 0);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 13);
|
assert_eq!(i.get_highest_level_that_fits(), 13);
|
||||||
|
|
||||||
let i = LodPos::xyz(65536,0,8192);
|
let i = LodPos::xyz(65536, 0, 8192);
|
||||||
assert_eq!(i.get_highest_level_that_fits(), 13);
|
assert_eq!(i.get_highest_level_that_fits(), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,4 +298,3 @@ mod tests {
|
|||||||
b.iter(|| access.align_to_level(6));
|
b.iter(|| access.align_to_level(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
pub mod lodpos;
|
|
||||||
pub mod area;
|
pub mod area;
|
||||||
pub mod index;
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod delta;
|
pub mod delta;
|
||||||
pub use data::{
|
pub mod index;
|
||||||
HashNestLayer,
|
pub mod lodpos;
|
||||||
VecNestLayer,
|
pub use data::{HashLayer, HashNestLayer, VecLayer, VecNestLayer};
|
||||||
HashLayer,
|
|
||||||
VecLayer,
|
|
||||||
};
|
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
use crate::lodstore::{
|
use crate::lodstore::{HashNestLayer, VecLayer, VecNestLayer};
|
||||||
HashNestLayer,
|
|
||||||
VecNestLayer,
|
|
||||||
HashLayer,
|
|
||||||
VecLayer,
|
|
||||||
lodpos::LodPos,
|
|
||||||
lodpos::AbsIndex,
|
|
||||||
};
|
|
||||||
use vek::*;
|
|
||||||
use std::u32;
|
|
||||||
pub type LodIndex = LodPos;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
@ -36,7 +26,6 @@ pub struct SubBlock {
|
|||||||
material: u32,
|
material: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub type TerrainLod =
|
pub type TerrainLod =
|
||||||
HashNestLayer<
|
HashNestLayer<
|
||||||
|
@ -7,8 +7,6 @@ pub struct RegionMeta {
|
|||||||
|
|
||||||
impl RegionMeta {
|
impl RegionMeta {
|
||||||
pub fn new(id: RegionId) -> Self {
|
pub fn new(id: RegionId) -> Self {
|
||||||
Self {
|
Self { id }
|
||||||
id,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,11 @@
|
|||||||
pub mod meta;
|
|
||||||
mod lod;
|
mod lod;
|
||||||
|
pub mod meta;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{job::JobManager, regionmanager::meta::RegionId};
|
||||||
regionmanager::meta::RegionId,
|
|
||||||
job::JobManager,
|
|
||||||
};
|
|
||||||
use lod::terrain::TerrainLod;
|
use lod::terrain::TerrainLod;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
id: RegionId,
|
id: RegionId,
|
||||||
jobmanager: Arc<JobManager>,
|
jobmanager: Arc<JobManager>,
|
||||||
@ -34,39 +31,33 @@ impl Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rasterize(region: &Region) -> Vec<u64> {
|
fn _rasterize(_region: &Region) -> Vec<u64> {
|
||||||
let mut res = Vec::new();
|
let mut _res = Vec::new();
|
||||||
|
|
||||||
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
||||||
//region.block
|
//region.block
|
||||||
|
|
||||||
res
|
_res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn _plant_trees(_region: &Region) -> Vec<u64> {
|
||||||
|
let mut _res = Vec::new();
|
||||||
fn plant_trees(region: &Region) -> Vec<u64> {
|
|
||||||
let mut res = Vec::new();
|
|
||||||
|
|
||||||
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
||||||
// acces blocks around
|
// acces blocks around
|
||||||
|
|
||||||
res
|
_res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn _corrosion(_region: &Region) -> Vec<u64> {
|
||||||
|
let mut _res = Vec::new();
|
||||||
fn corrosion(region: &Region) -> Vec<u64> {
|
|
||||||
let mut res = Vec::new();
|
|
||||||
|
|
||||||
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
// iterate over all Region9 / chunk5 / Block0 / subBlock that dont have children in RECT XYZ
|
||||||
// access neighbours
|
// access neighbours
|
||||||
|
|
||||||
res
|
_res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
pub type aaa = LodLayer<e::Terain>;
|
pub type aaa = LodLayer<e::Terain>;
|
||||||
|
@ -7,25 +7,37 @@ pub struct Server {
|
|||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub fn new(connection_details: String) -> Self {
|
pub fn new(connection_details: String) -> Self {
|
||||||
Self {
|
Self { connection_details }
|
||||||
connection_details,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum RegionManagerMsg {
|
pub enum RegionManagerMsg {
|
||||||
Attached{server_id: u64, seed: u64},
|
Attached {
|
||||||
NewServerInMesh{server_id: u64, server_connection_details: ()},
|
server_id: u64,
|
||||||
CreateRegion{region_id: RegionId},
|
seed: u64,
|
||||||
TakeOverRegionFrom{region_id: RegionId, server_id: u64},
|
},
|
||||||
|
NewServerInMesh {
|
||||||
|
server_id: u64,
|
||||||
|
server_connection_details: (),
|
||||||
|
},
|
||||||
|
CreateRegion {
|
||||||
|
region_id: RegionId,
|
||||||
|
},
|
||||||
|
TakeOverRegionFrom {
|
||||||
|
region_id: RegionId,
|
||||||
|
server_id: u64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type RegionIdSize = i8;
|
pub type RegionIdSize = i8;
|
||||||
pub type RegionId = (/*x*/RegionIdSize, /*y*/RegionIdSize /*z = 0*/);
|
pub type RegionId = (
|
||||||
|
/*x*/ RegionIdSize,
|
||||||
|
/*y*/ RegionIdSize, /*z = 0*/
|
||||||
|
);
|
||||||
|
|
||||||
pub const RegionMIN:i8 = -64;
|
pub const REGION_MIN: i8 = -64;
|
||||||
pub const RegionMAX:i8 = 63;
|
pub const REGION_MAX: i8 = 63;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
pub mod meta;
|
pub mod meta;
|
||||||
|
use crate::{
|
||||||
|
regionmanager::meta::{Region, RegionId, RegionManagerMsg, Server, REGION_MAX, REGION_MIN},
|
||||||
|
server::meta::ServerMsg,
|
||||||
|
};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
Arc,
|
|
||||||
mpsc,
|
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
|
mpsc, Arc,
|
||||||
};
|
};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use crate::{
|
|
||||||
regionmanager::meta::{
|
|
||||||
Server, Region, RegionId, RegionManagerMsg, RegionMIN, RegionMAX,
|
|
||||||
},
|
|
||||||
server::meta::{
|
|
||||||
ServerMsg,
|
|
||||||
},
|
|
||||||
job::JobManager,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RegionManager {
|
pub struct RegionManager {
|
||||||
@ -26,17 +20,16 @@ pub struct RegionManager {
|
|||||||
regions: HashMap<RegionId, Region>,
|
regions: HashMap<RegionId, Region>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegionManager{
|
impl RegionManager {
|
||||||
pub fn new(tx: mpsc::Sender<RegionManagerMsg>, rx: mpsc::Receiver<ServerMsg>) -> Self {
|
pub fn new(tx: mpsc::Sender<RegionManagerMsg>, rx: mpsc::Receiver<ServerMsg>) -> Self {
|
||||||
|
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
|
|
||||||
let mut servers = vec!();
|
let servers = vec![];
|
||||||
let mut regions = HashMap::new();
|
let mut regions = HashMap::new();
|
||||||
|
|
||||||
for x in RegionMIN..RegionMAX {
|
for x in REGION_MIN..REGION_MAX {
|
||||||
for y in RegionMIN..RegionMAX {
|
for y in REGION_MIN..REGION_MAX {
|
||||||
regions.insert((x,y), Region::new(None));
|
regions.insert((x, y), Region::new(None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,19 +47,27 @@ impl RegionManager{
|
|||||||
//It is widely important, that it causes as minimal shifting as necessary
|
//It is widely important, that it causes as minimal shifting as necessary
|
||||||
|
|
||||||
//.... fell f*** it for now
|
//.... fell f*** it for now
|
||||||
for x in RegionMIN..RegionMAX {
|
for x in REGION_MIN..REGION_MAX {
|
||||||
for y in RegionMIN..RegionMAX {
|
for y in REGION_MIN..REGION_MAX {
|
||||||
if !self.servers.is_empty() {
|
if !self.servers.is_empty() {
|
||||||
let old = self.regions.get(&(x,y)).unwrap().server_id;
|
let old = self.regions.get(&(x, y)).unwrap().server_id;
|
||||||
|
|
||||||
self.regions.get_mut(&(x,y)).unwrap().server_id = Some(((x as usize) % self.servers.len()) as u8);
|
self.regions.get_mut(&(x, y)).unwrap().server_id =
|
||||||
|
Some(((x as usize) % self.servers.len()) as u8);
|
||||||
if let Some(id) = old {
|
if let Some(id) = old {
|
||||||
self.tx.send(RegionManagerMsg::TakeOverRegionFrom{region_id: (x,y), server_id: id as u64});
|
self.tx
|
||||||
|
.send(RegionManagerMsg::TakeOverRegionFrom {
|
||||||
|
region_id: (x, y),
|
||||||
|
server_id: id as u64,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
self.tx.send(RegionManagerMsg::CreateRegion{region_id: (x,y)});
|
self.tx
|
||||||
|
.send(RegionManagerMsg::CreateRegion { region_id: (x, y) })
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.regions.get_mut(&(x,y)).unwrap().server_id = None;
|
self.regions.get_mut(&(x, y)).unwrap().server_id = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,15 +82,20 @@ impl RegionManager{
|
|||||||
match msg {
|
match msg {
|
||||||
ServerMsg::Attach() => {
|
ServerMsg::Attach() => {
|
||||||
//ERROR i cannot acceess self here ...
|
//ERROR i cannot acceess self here ...
|
||||||
self.servers.push(Server::new("Hello".to_string()) );
|
self.servers.push(Server::new("Hello".to_string()));
|
||||||
self.tx.send(RegionManagerMsg::Attached{server_id: self.servers.len() as u64 , seed: 1337});
|
self.tx
|
||||||
|
.send(RegionManagerMsg::Attached {
|
||||||
|
server_id: self.servers.len() as u64,
|
||||||
|
seed: 1337,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
error!("yay");
|
error!("yay");
|
||||||
println!("attached");
|
println!("attached");
|
||||||
self.rearange();
|
self.rearange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(_e) => {
|
||||||
//panic!("Work error {:?}", e);
|
//panic!("Work error {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ pub enum ServerMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type RegionIdSize = i8;
|
pub type RegionIdSize = i8;
|
||||||
pub type RegionId = (/*x*/RegionIdSize, /*y*/RegionIdSize /*z = 0*/);
|
pub type RegionId = (
|
||||||
|
/*x*/ RegionIdSize,
|
||||||
|
/*y*/ RegionIdSize, /*z = 0*/
|
||||||
|
);
|
||||||
|
|
||||||
pub const RegionMIN:i8 = -64;
|
pub const REGION_MIN: i8 = -64;
|
||||||
pub const RegionMAX:i8 = 63;
|
pub const REGION_MAX: i8 = 63;
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
pub mod meta;
|
pub mod meta;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
mpsc,
|
|
||||||
Arc,
|
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
|
mpsc, Arc,
|
||||||
};
|
};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
job::JobManager,
|
job::JobManager, region::Region, regionmanager::meta::RegionManagerMsg, server::meta::RegionId,
|
||||||
regionmanager::meta::RegionManagerMsg,
|
|
||||||
region::Region,
|
|
||||||
server::meta::RegionId,
|
|
||||||
server::meta::ServerMsg,
|
server::meta::ServerMsg,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
one server per physical host
|
one server per physical host
|
||||||
*/
|
*/
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
tx: mpsc::Sender<ServerMsg>,
|
tx: mpsc::Sender<ServerMsg>,
|
||||||
rx: mpsc::Receiver<RegionManagerMsg>,
|
rx: mpsc::Receiver<RegionManagerMsg>,
|
||||||
@ -27,12 +22,16 @@ pub struct Server {
|
|||||||
id: Option<u64>,
|
id: Option<u64>,
|
||||||
seed: Option<u64>,
|
seed: Option<u64>,
|
||||||
state: u64,
|
state: u64,
|
||||||
jobmanager: Arc<JobManager>,
|
_jobmanager: Arc<JobManager>,
|
||||||
region: HashMap<RegionId,Region>,
|
_region: HashMap<RegionId, Region>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub fn new(tx: mpsc::Sender<ServerMsg>, rx: mpsc::Receiver<RegionManagerMsg>, jobmanager: Arc<JobManager>) -> Self {
|
pub fn new(
|
||||||
|
tx: mpsc::Sender<ServerMsg>,
|
||||||
|
rx: mpsc::Receiver<RegionManagerMsg>,
|
||||||
|
jobmanager: Arc<JobManager>,
|
||||||
|
) -> Self {
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -42,8 +41,8 @@ impl Server {
|
|||||||
id: None,
|
id: None,
|
||||||
seed: None,
|
seed: None,
|
||||||
state: 0,
|
state: 0,
|
||||||
jobmanager: jobmanager.clone(),
|
_jobmanager: jobmanager.clone(),
|
||||||
region: HashMap::new(),
|
_region: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,43 +52,53 @@ impl Server {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
match self.state {
|
match self.state {
|
||||||
0 => {
|
0 => {
|
||||||
self.tx.send(ServerMsg::Attach());
|
self.tx.send(ServerMsg::Attach()).unwrap();
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
},
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.rx.try_recv() {
|
match self.rx.try_recv() {
|
||||||
Ok(msg) => {
|
Ok(msg) => {
|
||||||
match msg {
|
match msg {
|
||||||
RegionManagerMsg::Attached{server_id, seed} => {
|
RegionManagerMsg::Attached { server_id, seed } => {
|
||||||
self.id = Some(server_id);
|
self.id = Some(server_id);
|
||||||
self.seed = Some(seed);
|
self.seed = Some(seed);
|
||||||
},
|
}
|
||||||
RegionManagerMsg::NewServerInMesh{server_id, server_connection_details} => {
|
RegionManagerMsg::NewServerInMesh {
|
||||||
println!("new server found");
|
server_id,
|
||||||
},
|
server_connection_details,
|
||||||
RegionManagerMsg::CreateRegion{region_id} => {
|
} => {
|
||||||
|
println!(
|
||||||
|
"new server found {}, details: {:?}",
|
||||||
|
server_id, server_connection_details
|
||||||
|
);
|
||||||
|
}
|
||||||
|
RegionManagerMsg::CreateRegion { region_id } => {
|
||||||
/*
|
/*
|
||||||
let mut r = Region::new(region_id, self.jobmanager.clone());
|
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);
|
r.block.make_at_least(Vec3::new(0,0,0), Vec3::new(65535,65535,65535), 9);
|
||||||
self.region.insert(region_id, r);
|
self.region.insert(region_id, r);
|
||||||
*/
|
*/
|
||||||
println!("create region");
|
println!("create region {:?}", region_id);
|
||||||
},
|
}
|
||||||
RegionManagerMsg::TakeOverRegionFrom{region_id, server_id} => {
|
RegionManagerMsg::TakeOverRegionFrom {
|
||||||
println!("new server in mesh");
|
region_id,
|
||||||
},
|
server_id,
|
||||||
_ => (),
|
} => {
|
||||||
|
println!(
|
||||||
|
"new server in mesh, region: {:?}, server {}",
|
||||||
|
region_id, server_id
|
||||||
|
);
|
||||||
|
} //_ => (),
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
//panic!("Work error {:?}", e);
|
debug!("Work error {:?}", e);
|
||||||
sleep(Duration::from_millis(10));
|
sleep(Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.running.load(Ordering::Relaxed)
|
self.running.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user