common: Rename VolMap{2d, 3d} -> VolGrid{2d, 3d}

This commit is contained in:
haslersn 2019-08-28 11:17:04 +02:00
parent 4bc1a644ec
commit 28c5886841
10 changed files with 68 additions and 68 deletions

View File

@ -6,7 +6,7 @@ use crate::{
event::{EventBus, LocalEvent, ServerEvent},
msg::{EcsCompPacket, EcsResPacket},
sys,
terrain::{Block, TerrainChunk, TerrainMap},
terrain::{Block, TerrainChunk, TerrainGrid},
vol::WriteVol,
};
use hashbrown::{HashMap, HashSet};
@ -153,7 +153,7 @@ impl State {
// Register unsynced resources used by the ECS.
ecs.add_resource(Time(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(TerrainChanges::default());
ecs.add_resource(EventBus::<ServerEvent>::default());
@ -220,12 +220,12 @@ impl State {
}
/// Get a reference to this state's terrain.
pub fn terrain(&self) -> Fetch<TerrainMap> {
pub fn terrain(&self) -> Fetch<TerrainGrid> {
self.ecs.read_resource()
}
/// 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()
}
@ -251,7 +251,7 @@ impl State {
pub fn insert_chunk(&mut self, key: Vec2<i32>, chunk: TerrainChunk) {
if self
.ecs
.write_resource::<TerrainMap>()
.write_resource::<TerrainGrid>()
.insert(key, Arc::new(chunk))
.is_some()
{
@ -271,7 +271,7 @@ impl State {
pub fn remove_chunk(&mut self, key: Vec2<i32>) {
if self
.ecs
.write_resource::<TerrainMap>()
.write_resource::<TerrainGrid>()
.remove(key)
.is_some()
{
@ -302,7 +302,7 @@ impl State {
self.ecs.maintain();
// Apply terrain changes
let mut terrain = self.ecs.write_resource::<TerrainMap>();
let mut terrain = self.ecs.write_resource::<TerrainGrid>();
self.ecs
.read_resource::<BlockChange>()
.blocks

View File

@ -4,7 +4,7 @@ use crate::{
Stats, Vel,
},
state::DeltaTime,
terrain::TerrainMap,
terrain::TerrainGrid,
vol::{ReadVol, Vox},
};
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
@ -32,7 +32,7 @@ pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
Entities<'a>,
ReadExpect<'a, TerrainMap>,
ReadExpect<'a, TerrainGrid>,
Read<'a, DeltaTime>,
ReadStorage<'a, Stats>,
ReadStorage<'a, Controller>,

View File

@ -3,7 +3,7 @@ use {
comp::{Body, MovementState::*, Ori, PhysicsState, Pos, Scale, Stats, Vel},
event::{EventBus, LocalEvent},
state::DeltaTime,
terrain::TerrainMap,
terrain::TerrainGrid,
vol::{ReadVol, Vox},
},
specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage},
@ -32,7 +32,7 @@ pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
Entities<'a>,
ReadExpect<'a, TerrainMap>,
ReadExpect<'a, TerrainGrid>,
Read<'a, DeltaTime>,
Read<'a, EventBus<LocalEvent>>,
ReadStorage<'a, Scale>,

View File

@ -10,7 +10,7 @@ pub use self::{
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 vek::*;
@ -62,4 +62,4 @@ impl TerrainChunkMeta {
// Terrain type aliases
pub type TerrainChunk = chonk::Chonk<Block, TerrainChunkSize, TerrainChunkMeta>;
pub type TerrainMap = VolMap2d<TerrainChunk, TerrainChunkSize>;
pub type TerrainGrid = VolGrid2d<TerrainChunk, TerrainChunkSize>;

View File

@ -1,5 +1,5 @@
pub mod chunk;
pub mod dyna;
pub mod morton;
pub mod vol_map_2d;
pub mod vol_map_3d;
pub mod vol_grid_2d;
pub mod vol_grid_3d;

View File

@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug, Clone)]
pub enum VolMap2dError<V: BaseVol> {
pub enum VolGrid2dError<V: BaseVol> {
NoSuchChunk,
ChunkError(V::Error),
DynaError(DynaError),
@ -18,12 +18,12 @@ pub enum VolMap2dError<V: BaseVol> {
// S = Size (replace with a const when const generics is a thing)
// M = Chunk metadata
#[derive(Clone)]
pub struct VolMap2d<V: BaseVol, S: VolSize> {
pub struct VolGrid2d<V: BaseVol, S: VolSize> {
chunks: HashMap<Vec2<i32>, Arc<V>>,
phantom: PhantomData<S>,
}
impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
impl<V: BaseVol, S: VolSize> VolGrid2d<V, S> {
#[inline(always)]
pub fn chunk_key<P: Into<Vec2<i32>>>(pos: P) -> Vec2<i32> {
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 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)]
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);
self.chunks
.get(&ck)
.ok_or(VolMap2dError::NoSuchChunk)
.ok_or(VolGrid2dError::NoSuchChunk)
.and_then(|chunk| {
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: Should this be changed, perhaps?
impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolMap2d<V, S> {
type Sample = VolMap2d<V, S>;
impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolGrid2d<V, S> {
type Sample = VolGrid2d<V, S>;
/// 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.
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 mut sample = VolMap2d::new()?;
let mut sample = VolGrid2d::new()?;
let chunk_min = Self::chunk_key(range.min);
let chunk_max = Self::chunk_key(range.max);
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)]
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);
self.chunks
.get_mut(&ck)
.ok_or(VolMap2dError::NoSuchChunk)
.ok_or(VolGrid2dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
Arc::make_mut(chunk)
.set(co, vox)
.map_err(VolMap2dError::ChunkError)
.map_err(VolGrid2dError::ChunkError)
})
}
}
impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
pub fn new() -> Result<Self, VolMap2dError<V>> {
impl<V: BaseVol, S: VolSize> VolGrid2d<V, S> {
pub fn new() -> Result<Self, VolGrid2dError<V>> {
if Self::chunk_size()
.map(|e| e.is_power_of_two() && e > 0)
.reduce_and()
@ -113,7 +113,7 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
phantom: PhantomData,
})
} else {
Err(VolMap2dError::InvalidChunkSize)
Err(VolGrid2dError::InvalidChunkSize)
}
}

View File

@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug)]
pub enum VolMap3dError<V: BaseVol> {
pub enum VolGrid3dError<V: BaseVol> {
NoSuchChunk,
ChunkErr(V::Error),
DynaError(DynaError),
@ -18,12 +18,12 @@ pub enum VolMap3dError<V: BaseVol> {
// S = Size (replace with a const when const generics is a thing)
// M = Chunk metadata
#[derive(Clone)]
pub struct VolMap3d<V: BaseVol, S: VolSize> {
pub struct VolGrid3d<V: BaseVol, S: VolSize> {
chunks: HashMap<Vec3<i32>, Arc<V>>,
phantom: PhantomData<S>,
}
impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
impl<V: BaseVol, S: VolSize> VolGrid3d<V, S> {
#[inline(always)]
pub fn chunk_key(pos: Vec3<i32>) -> Vec3<i32> {
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 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)]
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);
self.chunks
.get(&ck)
.ok_or(VolMap3dError::NoSuchChunk)
.ok_or(VolGrid3dError::NoSuchChunk)
.and_then(|chunk| {
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: Should this be changed, perhaps?
impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolMap3d<V, S> {
type Sample = VolMap3d<V, S>;
impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I> for VolGrid3d<V, S> {
type Sample = VolGrid3d<V, S>;
/// 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.
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 mut sample = VolMap3d::new()?;
let mut sample = VolGrid3d::new()?;
let chunk_min = Self::chunk_key(range.min);
let chunk_max = Self::chunk_key(range.max);
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)]
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);
self.chunks
.get_mut(&ck)
.ok_or(VolMap3dError::NoSuchChunk)
.ok_or(VolGrid3dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
Arc::make_mut(chunk)
.set(co, vox)
.map_err(VolMap3dError::ChunkErr)
.map_err(VolGrid3dError::ChunkErr)
})
}
}
impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
pub fn new() -> Result<Self, VolMap3dError<V>> {
impl<V: BaseVol, S: VolSize> VolGrid3d<V, S> {
pub fn new() -> Result<Self, VolGrid3dError<V>> {
if Self::chunk_size()
.map(|e| e.is_power_of_two() && e > 0)
.reduce_and()
@ -119,7 +119,7 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
phantom: PhantomData,
})
} else {
Err(VolMap3dError::InvalidChunkSize)
Err(VolGrid3dError::InvalidChunkSize)
}
}

View File

@ -22,7 +22,7 @@ use common::{
msg::{ClientMsg, ClientState, RequestStateError, ServerError, ServerInfo, ServerMsg},
net::PostOffice,
state::{BlockChange, State, TimeOfDay, Uid},
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainMap},
terrain::{block::Block, TerrainChunk, TerrainChunkSize, TerrainGrid},
vol::Vox,
vol::{ReadVol, VolSize},
};
@ -258,7 +258,7 @@ impl Server {
let mut block_change = ecs.write_resource::<BlockChange>();
let _ = ecs
.read_resource::<TerrainMap>()
.read_resource::<TerrainGrid>()
.ray(pos, pos + dir * radius)
.until(|_| rand::random::<f32>() < 0.05)
.for_each(|pos| block_change.set(pos, Block::empty()))
@ -462,7 +462,7 @@ impl Server {
fn chunk_in_vd(
player_pos: Vec3<f32>,
chunk_pos: Vec2<i32>,
terrain: &TerrainMap,
terrain: &TerrainGrid,
vd: u32,
) -> bool {
let player_chunk_pos = terrain.pos_key(player_pos.map(|e| e as i32));

View File

@ -5,7 +5,7 @@ use crate::{
use common::{
terrain::{Block, BlockKind},
vol::{BaseVol, ReadVol, VolSize},
volumes::vol_map_2d::VolMap2d,
volumes::vol_grid_2d::VolGrid2d,
};
use std::fmt::Debug;
use vek::*;
@ -25,7 +25,7 @@ fn block_shadow_density(kind: BlockKind) -> (f32, f32) {
}
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 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 Supplement = Aabb<i32>;

View File

@ -9,9 +9,9 @@ use client::Client;
use common::{
assets,
figure::Segment,
terrain::{Block, BlockKind, TerrainChunkSize, TerrainMap},
terrain::{Block, BlockKind, TerrainChunkSize, TerrainGrid},
vol::{ReadVol, SampleVol, VolSize, Vox},
volumes::vol_map_2d::VolMap2dError,
volumes::vol_grid_2d::VolGrid2dError,
};
use crossbeam::channel;
use dot_vox::DotVoxData;
@ -114,7 +114,7 @@ fn mesh_worker(
pos: Vec2<i32>,
z_bounds: (f32, f32),
started_tick: u64,
volume: <TerrainMap as SampleVol<Aabr<i32>>>::Sample,
volume: <TerrainGrid as SampleVol<Aabr<i32>>>::Sample,
range: Aabb<i32>,
) -> MeshWorkerResponse {
let (opaque_mesh, fluid_mesh) = volume.generate_mesh(range);
@ -455,10 +455,10 @@ impl Terrain {
let aabr = Aabr {
min: todo
.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
.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
@ -467,7 +467,7 @@ impl Terrain {
Ok(sample) => sample,
// 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.
Err(VolMap2dError::NoSuchChunk) => return,
Err(VolGrid2dError::NoSuchChunk) => return,
_ => panic!("Unhandled edge case"),
};
@ -534,7 +534,7 @@ impl Terrain {
locals: renderer
.create_consts(&[TerrainLocals {
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
}),
)