mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
common: Rename VolMap{2d, 3d}
-> VolGrid{2d, 3d}
This commit is contained in:
parent
4bc1a644ec
commit
28c5886841
@ -6,7 +6,7 @@ use crate::{
|
|||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
msg::{EcsCompPacket, EcsResPacket},
|
msg::{EcsCompPacket, EcsResPacket},
|
||||||
sys,
|
sys,
|
||||||
terrain::{Block, TerrainChunk, TerrainMap},
|
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||||
vol::WriteVol,
|
vol::WriteVol,
|
||||||
};
|
};
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
@ -153,7 +153,7 @@ impl State {
|
|||||||
// Register unsynced resources used by the ECS.
|
// Register unsynced resources used by the ECS.
|
||||||
ecs.add_resource(Time(0.0));
|
ecs.add_resource(Time(0.0));
|
||||||
ecs.add_resource(DeltaTime(0.0));
|
ecs.add_resource(DeltaTime(0.0));
|
||||||
ecs.add_resource(TerrainMap::new().unwrap());
|
ecs.add_resource(TerrainGrid::new().unwrap());
|
||||||
ecs.add_resource(BlockChange::default());
|
ecs.add_resource(BlockChange::default());
|
||||||
ecs.add_resource(TerrainChanges::default());
|
ecs.add_resource(TerrainChanges::default());
|
||||||
ecs.add_resource(EventBus::<ServerEvent>::default());
|
ecs.add_resource(EventBus::<ServerEvent>::default());
|
||||||
@ -220,12 +220,12 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to this state's terrain.
|
/// Get a reference to this state's terrain.
|
||||||
pub fn terrain(&self) -> Fetch<TerrainMap> {
|
pub fn terrain(&self) -> Fetch<TerrainGrid> {
|
||||||
self.ecs.read_resource()
|
self.ecs.read_resource()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a writable reference to this state's terrain.
|
/// Get a writable reference to this state's terrain.
|
||||||
pub fn terrain_mut(&self) -> FetchMut<TerrainMap> {
|
pub fn terrain_mut(&self) -> FetchMut<TerrainGrid> {
|
||||||
self.ecs.write_resource()
|
self.ecs.write_resource()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ impl State {
|
|||||||
pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: TerrainChunk) {
|
pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: TerrainChunk) {
|
||||||
if self
|
if self
|
||||||
.ecs
|
.ecs
|
||||||
.write_resource::<TerrainMap>()
|
.write_resource::<TerrainGrid>()
|
||||||
.insert(key, Arc::new(chunk))
|
.insert(key, Arc::new(chunk))
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
@ -271,7 +271,7 @@ impl State {
|
|||||||
pub fn remove_chunk(&mut self, key: Vec2<i32>) {
|
pub fn remove_chunk(&mut self, key: Vec2<i32>) {
|
||||||
if self
|
if self
|
||||||
.ecs
|
.ecs
|
||||||
.write_resource::<TerrainMap>()
|
.write_resource::<TerrainGrid>()
|
||||||
.remove(key)
|
.remove(key)
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
@ -302,7 +302,7 @@ impl State {
|
|||||||
self.ecs.maintain();
|
self.ecs.maintain();
|
||||||
|
|
||||||
// Apply terrain changes
|
// Apply terrain changes
|
||||||
let mut terrain = self.ecs.write_resource::<TerrainMap>();
|
let mut terrain = self.ecs.write_resource::<TerrainGrid>();
|
||||||
self.ecs
|
self.ecs
|
||||||
.read_resource::<BlockChange>()
|
.read_resource::<BlockChange>()
|
||||||
.blocks
|
.blocks
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
Stats, Vel,
|
Stats, Vel,
|
||||||
},
|
},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
terrain::TerrainMap,
|
terrain::TerrainGrid,
|
||||||
vol::{ReadVol, Vox},
|
vol::{ReadVol, Vox},
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
||||||
@ -32,7 +32,7 @@ pub struct Sys;
|
|||||||
impl<'a> System<'a> for Sys {
|
impl<'a> System<'a> for Sys {
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadExpect<'a, TerrainMap>,
|
ReadExpect<'a, TerrainGrid>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
ReadStorage<'a, Stats>,
|
ReadStorage<'a, Stats>,
|
||||||
ReadStorage<'a, Controller>,
|
ReadStorage<'a, Controller>,
|
||||||
|
@ -3,7 +3,7 @@ use {
|
|||||||
comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel},
|
comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel},
|
||||||
event::{EventBus, LocalEvent},
|
event::{EventBus, LocalEvent},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
terrain::TerrainMap,
|
terrain::TerrainGrid,
|
||||||
vol::{ReadVol, Vox},
|
vol::{ReadVol, Vox},
|
||||||
},
|
},
|
||||||
specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage},
|
specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage},
|
||||||
@ -32,7 +32,7 @@ pub struct Sys;
|
|||||||
impl<'a> System<'a> for Sys {
|
impl<'a> System<'a> for Sys {
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadExpect<'a, TerrainMap>,
|
ReadExpect<'a, TerrainGrid>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, EventBus<LocalEvent>>,
|
Read<'a, EventBus<LocalEvent>>,
|
||||||
ReadStorage<'a, Scale>,
|
ReadStorage<'a, Scale>,
|
||||||
|
@ -10,7 +10,7 @@ pub use self::{
|
|||||||
structure::Structure,
|
structure::Structure,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{vol::VolSize, volumes::vol_map_2d::VolMap2d};
|
use crate::{vol::VolSize, volumes::vol_grid_2d::VolGrid2d};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -62,4 +62,4 @@ impl TerrainChunkMeta {
|
|||||||
// Terrain type aliases
|
// Terrain type aliases
|
||||||
|
|
||||||
pub type TerrainChunk = chonk::Chonk<Block, TerrainChunkSize, TerrainChunkMeta>;
|
pub type TerrainChunk = chonk::Chonk<Block, TerrainChunkSize, TerrainChunkMeta>;
|
||||||
pub type TerrainMap = VolMap2d<TerrainChunk, TerrainChunkSize>;
|
pub type TerrainGrid = VolGrid2d<TerrainChunk, TerrainChunkSize>;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
pub mod chunk;
|
pub mod chunk;
|
||||||
pub mod dyna;
|
pub mod dyna;
|
||||||
pub mod morton;
|
pub mod morton;
|
||||||
pub mod vol_map_2d;
|
pub mod vol_grid_2d;
|
||||||
pub mod vol_map_3d;
|
pub mod vol_grid_3d;
|
||||||
|
@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc};
|
|||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum VolMap2dError<V: BaseVol> {
|
pub enum VolGrid2dError<V: BaseVol> {
|
||||||
NoSuchChunk,
|
NoSuchChunk,
|
||||||
ChunkError(V::Error),
|
ChunkError(V::Error),
|
||||||
DynaError(DynaError),
|
DynaError(DynaError),
|
||||||
@ -18,12 +18,12 @@ pub enum VolMap2dError<V: BaseVol> {
|
|||||||
// S = Size (replace with a const when const generics is a thing)
|
// S = Size (replace with a const when const generics is a thing)
|
||||||
// M = Chunk metadata
|
// M = Chunk metadata
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct VolMap2d<V: BaseVol, S: VolSize> {
|
pub struct VolGrid2d<V: BaseVol, S: VolSize> {
|
||||||
chunks: HashMap<Vec2<i32>, Arc<V>>,
|
chunks: HashMap<Vec2<i32>, Arc<V>>,
|
||||||
phantom: PhantomData<S>,
|
phantom: PhantomData<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
|
impl<V: BaseVol, S: VolSize> VolGrid2d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn chunk_key<P: Into<Vec2<i32>>>(pos: P) -> Vec2<i32> {
|
pub fn chunk_key<P: Into<Vec2<i32>>>(pos: P) -> Vec2<i32> {
|
||||||
pos.into()
|
pos.into()
|
||||||
@ -37,37 +37,37 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolMap2d<V, S> {
|
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolGrid2d<V, S> {
|
||||||
type Vox = V::Vox;
|
type Vox = V::Vox;
|
||||||
type Error = VolMap2dError<V>;
|
type Error = VolGrid2dError<V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolMap2d<V, S> {
|
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolGrid2d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap2dError<V>> {
|
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolGrid2dError<V>> {
|
||||||
let ck = Self::chunk_key(pos);
|
let ck = Self::chunk_key(pos);
|
||||||
self.chunks
|
self.chunks
|
||||||
.get(&ck)
|
.get(&ck)
|
||||||
.ok_or(VolMap2dError::NoSuchChunk)
|
.ok_or(VolGrid2dError::NoSuchChunk)
|
||||||
.and_then(|chunk| {
|
.and_then(|chunk| {
|
||||||
let co = Self::chunk_offs(pos);
|
let co = Self::chunk_offs(pos);
|
||||||
chunk.get(co).map_err(VolMap2dError::ChunkError)
|
chunk.get(co).map_err(VolGrid2dError::ChunkError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This actually breaks the API: samples are supposed to have an offset of zero!
|
// TODO: This actually breaks the API: samples are supposed to have an offset of zero!
|
||||||
// TODO: Should this be changed, perhaps?
|
// TODO: Should this be changed, perhaps?
|
||||||
impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolMap2d<V, S> {
|
impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolGrid2d<V, S> {
|
||||||
type Sample = VolMap2d<V, S>;
|
type Sample = VolGrid2d<V, S>;
|
||||||
|
|
||||||
/// Take a sample of the terrain by cloning the voxels within the provided range.
|
/// Take a sample of the terrain by cloning the voxels within the provided range.
|
||||||
///
|
///
|
||||||
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
||||||
fn sample(&self, range: I) -> Result<Self::Sample, VolMap2dError<V>> {
|
fn sample(&self, range: I) -> Result<Self::Sample, VolGrid2dError<V>> {
|
||||||
let range = range.into();
|
let range = range.into();
|
||||||
|
|
||||||
let mut sample = VolMap2d::new()?;
|
let mut sample = VolGrid2d::new()?;
|
||||||
let chunk_min = Self::chunk_key(range.min);
|
let chunk_min = Self::chunk_key(range.min);
|
||||||
let chunk_max = Self::chunk_key(range.max);
|
let chunk_max = Self::chunk_key(range.max);
|
||||||
for x in chunk_min.x..=chunk_max.x {
|
for x in chunk_min.x..=chunk_max.x {
|
||||||
@ -86,24 +86,24 @@ impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolMap2d<V, S> {
|
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolGrid2d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap2dError<V>> {
|
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolGrid2dError<V>> {
|
||||||
let ck = Self::chunk_key(pos);
|
let ck = Self::chunk_key(pos);
|
||||||
self.chunks
|
self.chunks
|
||||||
.get_mut(&ck)
|
.get_mut(&ck)
|
||||||
.ok_or(VolMap2dError::NoSuchChunk)
|
.ok_or(VolGrid2dError::NoSuchChunk)
|
||||||
.and_then(|chunk| {
|
.and_then(|chunk| {
|
||||||
let co = Self::chunk_offs(pos);
|
let co = Self::chunk_offs(pos);
|
||||||
Arc::make_mut(chunk)
|
Arc::make_mut(chunk)
|
||||||
.set(co, vox)
|
.set(co, vox)
|
||||||
.map_err(VolMap2dError::ChunkError)
|
.map_err(VolGrid2dError::ChunkError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
|
impl<V: BaseVol, S: VolSize> VolGrid2d<V, S> {
|
||||||
pub fn new() -> Result<Self, VolMap2dError<V>> {
|
pub fn new() -> Result<Self, VolGrid2dError<V>> {
|
||||||
if Self::chunk_size()
|
if Self::chunk_size()
|
||||||
.map(|e| e.is_power_of_two() && e > 0)
|
.map(|e| e.is_power_of_two() && e > 0)
|
||||||
.reduce_and()
|
.reduce_and()
|
||||||
@ -113,7 +113,7 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
|
|||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(VolMap2dError::InvalidChunkSize)
|
Err(VolGrid2dError::InvalidChunkSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc};
|
|||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum VolMap3dError<V: BaseVol> {
|
pub enum VolGrid3dError<V: BaseVol> {
|
||||||
NoSuchChunk,
|
NoSuchChunk,
|
||||||
ChunkErr(V::Error),
|
ChunkErr(V::Error),
|
||||||
DynaError(DynaError),
|
DynaError(DynaError),
|
||||||
@ -18,12 +18,12 @@ pub enum VolMap3dError<V: BaseVol> {
|
|||||||
// S = Size (replace with a const when const generics is a thing)
|
// S = Size (replace with a const when const generics is a thing)
|
||||||
// M = Chunk metadata
|
// M = Chunk metadata
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct VolMap3d<V: BaseVol, S: VolSize> {
|
pub struct VolGrid3d<V: BaseVol, S: VolSize> {
|
||||||
chunks: HashMap<Vec3<i32>, Arc<V>>,
|
chunks: HashMap<Vec3<i32>, Arc<V>>,
|
||||||
phantom: PhantomData<S>,
|
phantom: PhantomData<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
|
impl<V: BaseVol, S: VolSize> VolGrid3d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn chunk_key(pos: Vec3<i32>) -> Vec3<i32> {
|
pub fn chunk_key(pos: Vec3<i32>) -> Vec3<i32> {
|
||||||
pos.map2(S::SIZE, |e, sz| {
|
pos.map2(S::SIZE, |e, sz| {
|
||||||
@ -42,36 +42,36 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolMap3d<V, S> {
|
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolGrid3d<V, S> {
|
||||||
type Vox = V::Vox;
|
type Vox = V::Vox;
|
||||||
type Error = VolMap3dError<V>;
|
type Error = VolGrid3dError<V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolMap3d<V, S> {
|
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolGrid3d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap3dError<V>> {
|
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolGrid3dError<V>> {
|
||||||
let ck = Self::chunk_key(pos);
|
let ck = Self::chunk_key(pos);
|
||||||
self.chunks
|
self.chunks
|
||||||
.get(&ck)
|
.get(&ck)
|
||||||
.ok_or(VolMap3dError::NoSuchChunk)
|
.ok_or(VolGrid3dError::NoSuchChunk)
|
||||||
.and_then(|chunk| {
|
.and_then(|chunk| {
|
||||||
let co = Self::chunk_offs(pos);
|
let co = Self::chunk_offs(pos);
|
||||||
chunk.get(co).map_err(VolMap3dError::ChunkErr)
|
chunk.get(co).map_err(VolGrid3dError::ChunkErr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This actually breaks the API: samples are supposed to have an offset of zero!
|
// TODO: This actually breaks the API: samples are supposed to have an offset of zero!
|
||||||
// TODO: Should this be changed, perhaps?
|
// TODO: Should this be changed, perhaps?
|
||||||
impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolMap3d<V, S> {
|
impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolGrid3d<V, S> {
|
||||||
type Sample = VolMap3d<V, S>;
|
type Sample = VolGrid3d<V, S>;
|
||||||
|
|
||||||
/// Take a sample of the terrain by cloning the voxels within the provided range.
|
/// Take a sample of the terrain by cloning the voxels within the provided range.
|
||||||
///
|
///
|
||||||
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
||||||
fn sample(&self, range: I) -> Result<Self::Sample, VolMap3dError<V>> {
|
fn sample(&self, range: I) -> Result<Self::Sample, VolGrid3dError<V>> {
|
||||||
let range = range.into();
|
let range = range.into();
|
||||||
let mut sample = VolMap3d::new()?;
|
let mut sample = VolGrid3d::new()?;
|
||||||
let chunk_min = Self::chunk_key(range.min);
|
let chunk_min = Self::chunk_key(range.min);
|
||||||
let chunk_max = Self::chunk_key(range.max);
|
let chunk_max = Self::chunk_key(range.max);
|
||||||
for x in chunk_min.x..=chunk_max.x {
|
for x in chunk_min.x..=chunk_max.x {
|
||||||
@ -92,24 +92,24 @@ impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolMap3d<V, S> {
|
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolGrid3d<V, S> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap3dError<V>> {
|
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolGrid3dError<V>> {
|
||||||
let ck = Self::chunk_key(pos);
|
let ck = Self::chunk_key(pos);
|
||||||
self.chunks
|
self.chunks
|
||||||
.get_mut(&ck)
|
.get_mut(&ck)
|
||||||
.ok_or(VolMap3dError::NoSuchChunk)
|
.ok_or(VolGrid3dError::NoSuchChunk)
|
||||||
.and_then(|chunk| {
|
.and_then(|chunk| {
|
||||||
let co = Self::chunk_offs(pos);
|
let co = Self::chunk_offs(pos);
|
||||||
Arc::make_mut(chunk)
|
Arc::make_mut(chunk)
|
||||||
.set(co, vox)
|
.set(co, vox)
|
||||||
.map_err(VolMap3dError::ChunkErr)
|
.map_err(VolGrid3dError::ChunkErr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
|
impl<V: BaseVol, S: VolSize> VolGrid3d<V, S> {
|
||||||
pub fn new() -> Result<Self, VolMap3dError<V>> {
|
pub fn new() -> Result<Self, VolGrid3dError<V>> {
|
||||||
if Self::chunk_size()
|
if Self::chunk_size()
|
||||||
.map(|e| e.is_power_of_two() && e > 0)
|
.map(|e| e.is_power_of_two() && e > 0)
|
||||||
.reduce_and()
|
.reduce_and()
|
||||||
@ -119,7 +119,7 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
|
|||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(VolMap3dError::InvalidChunkSize)
|
Err(VolGrid3dError::InvalidChunkSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ use common::{
|
|||||||
msg::{ClientMsg, ClientState, RequestStateError, ServerError, ServerInfo, ServerMsg},
|
msg::{ClientMsg, ClientState, RequestStateError, ServerError, ServerInfo, ServerMsg},
|
||||||
net::PostOffice,
|
net::PostOffice,
|
||||||
state::{BlockChange, State, TimeOfDay, Uid},
|
state::{BlockChange, State, TimeOfDay, Uid},
|
||||||
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainMap},
|
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainGrid},
|
||||||
vol::Vox,
|
vol::Vox,
|
||||||
vol::{ReadVol, VolSize},
|
vol::{ReadVol, VolSize},
|
||||||
};
|
};
|
||||||
@ -258,7 +258,7 @@ impl Server {
|
|||||||
let mut block_change = ecs.write_resource::<BlockChange>();
|
let mut block_change = ecs.write_resource::<BlockChange>();
|
||||||
|
|
||||||
let _ = ecs
|
let _ = ecs
|
||||||
.read_resource::<TerrainMap>()
|
.read_resource::<TerrainGrid>()
|
||||||
.ray(pos, pos + dir * radius)
|
.ray(pos, pos + dir * radius)
|
||||||
.until(|_| rand::random::<f32>() < 0.05)
|
.until(|_| rand::random::<f32>() < 0.05)
|
||||||
.for_each(|pos| block_change.set(pos, Block::empty()))
|
.for_each(|pos| block_change.set(pos, Block::empty()))
|
||||||
@ -462,7 +462,7 @@ impl Server {
|
|||||||
fn chunk_in_vd(
|
fn chunk_in_vd(
|
||||||
player_pos: Vec3<f32>,
|
player_pos: Vec3<f32>,
|
||||||
chunk_pos: Vec2<i32>,
|
chunk_pos: Vec2<i32>,
|
||||||
terrain: &TerrainMap,
|
terrain: &TerrainGrid,
|
||||||
vd: u32,
|
vd: u32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let player_chunk_pos = terrain.pos_key(player_pos.map(|e| e as i32));
|
let player_chunk_pos = terrain.pos_key(player_pos.map(|e| e as i32));
|
||||||
|
@ -5,7 +5,7 @@ use crate::{
|
|||||||
use common::{
|
use common::{
|
||||||
terrain::{Block, BlockKind},
|
terrain::{Block, BlockKind},
|
||||||
vol::{BaseVol, ReadVol, VolSize},
|
vol::{BaseVol, ReadVol, VolSize},
|
||||||
volumes::vol_map_2d::VolMap2d,
|
volumes::vol_grid_2d::VolGrid2d,
|
||||||
};
|
};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -25,7 +25,7 @@ fn block_shadow_density(kind: BlockKind) -> (f32, f32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone>
|
impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone>
|
||||||
Meshable<TerrainPipeline, FluidPipeline> for VolMap2d<V, S>
|
Meshable<TerrainPipeline, FluidPipeline> for VolGrid2d<V, S>
|
||||||
{
|
{
|
||||||
type Pipeline = TerrainPipeline;
|
type Pipeline = TerrainPipeline;
|
||||||
type TranslucentPipeline = FluidPipeline;
|
type TranslucentPipeline = FluidPipeline;
|
||||||
@ -126,7 +126,7 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for VolMap3d<V, S> {
|
impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for VolGrid3d<V, S> {
|
||||||
type Pipeline = TerrainPipeline;
|
type Pipeline = TerrainPipeline;
|
||||||
type Supplement = Aabb<i32>;
|
type Supplement = Aabb<i32>;
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ use client::Client;
|
|||||||
use common::{
|
use common::{
|
||||||
assets,
|
assets,
|
||||||
figure::Segment,
|
figure::Segment,
|
||||||
terrain::{Block, BlockKind, TerrainChunkSize, TerrainMap},
|
terrain::{Block, BlockKind, TerrainChunkSize, TerrainGrid},
|
||||||
vol::{ReadVol, SampleVol, VolSize, Vox},
|
vol::{ReadVol, SampleVol, VolSize, Vox},
|
||||||
volumes::vol_map_2d::VolMap2dError,
|
volumes::vol_grid_2d::VolGrid2dError,
|
||||||
};
|
};
|
||||||
use crossbeam::channel;
|
use crossbeam::channel;
|
||||||
use dot_vox::DotVoxData;
|
use dot_vox::DotVoxData;
|
||||||
@ -114,7 +114,7 @@ fn mesh_worker(
|
|||||||
pos: Vec2<i32>,
|
pos: Vec2<i32>,
|
||||||
z_bounds: (f32, f32),
|
z_bounds: (f32, f32),
|
||||||
started_tick: u64,
|
started_tick: u64,
|
||||||
volume: <TerrainMap as SampleVol<Aabr<i32>>>::Sample,
|
volume: <TerrainGrid as SampleVol<Aabr<i32>>>::Sample,
|
||||||
range: Aabb<i32>,
|
range: Aabb<i32>,
|
||||||
) -> MeshWorkerResponse {
|
) -> MeshWorkerResponse {
|
||||||
let (opaque_mesh, fluid_mesh) = volume.generate_mesh(range);
|
let (opaque_mesh, fluid_mesh) = volume.generate_mesh(range);
|
||||||
@ -455,10 +455,10 @@ impl Terrain {
|
|||||||
let aabr = Aabr {
|
let aabr = Aabr {
|
||||||
min: todo
|
min: todo
|
||||||
.pos
|
.pos
|
||||||
.map2(TerrainMap::chunk_size(), |e, sz| e * sz as i32 - 1),
|
.map2(TerrainGrid::chunk_size(), |e, sz| e * sz as i32 - 1),
|
||||||
max: todo
|
max: todo
|
||||||
.pos
|
.pos
|
||||||
.map2(TerrainMap::chunk_size(), |e, sz| (e + 1) * sz as i32 + 1),
|
.map2(TerrainGrid::chunk_size(), |e, sz| (e + 1) * sz as i32 + 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy out the chunk data we need to perform the meshing. We do this by taking a
|
// Copy out the chunk data we need to perform the meshing. We do this by taking a
|
||||||
@ -467,7 +467,7 @@ impl Terrain {
|
|||||||
Ok(sample) => sample,
|
Ok(sample) => sample,
|
||||||
// Either this chunk or its neighbours doesn't yet exist, so we keep it in the
|
// Either this chunk or its neighbours doesn't yet exist, so we keep it in the
|
||||||
// queue to be processed at a later date when we have its neighbours.
|
// queue to be processed at a later date when we have its neighbours.
|
||||||
Err(VolMap2dError::NoSuchChunk) => return,
|
Err(VolGrid2dError::NoSuchChunk) => return,
|
||||||
_ => panic!("Unhandled edge case"),
|
_ => panic!("Unhandled edge case"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ impl Terrain {
|
|||||||
locals: renderer
|
locals: renderer
|
||||||
.create_consts(&[TerrainLocals {
|
.create_consts(&[TerrainLocals {
|
||||||
model_offs: Vec3::from(
|
model_offs: Vec3::from(
|
||||||
response.pos.map2(TerrainMap::chunk_size(), |e, sz| {
|
response.pos.map2(TerrainGrid::chunk_size(), |e, sz| {
|
||||||
e as f32 * sz as f32
|
e as f32 * sz as f32
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user