From 28c5886841b4aa9a8700270cc0441542db8642d4 Mon Sep 17 00:00:00 2001 From: haslersn Date: Wed, 28 Aug 2019 11:17:04 +0200 Subject: [PATCH] common: Rename `VolMap{2d, 3d}` -> `VolGrid{2d, 3d}` --- common/src/state.rs | 14 +++---- common/src/sys/movement.rs | 4 +- common/src/sys/phys.rs | 4 +- common/src/terrain/mod.rs | 4 +- common/src/volumes/mod.rs | 4 +- .../volumes/{vol_map_2d.rs => vol_grid_2d.rs} | 40 +++++++++---------- .../volumes/{vol_map_3d.rs => vol_grid_3d.rs} | 40 +++++++++---------- server/src/lib.rs | 6 +-- voxygen/src/mesh/terrain.rs | 6 +-- voxygen/src/scene/terrain.rs | 14 +++---- 10 files changed, 68 insertions(+), 68 deletions(-) rename common/src/volumes/{vol_map_2d.rs => vol_grid_2d.rs} (80%) rename common/src/volumes/{vol_map_3d.rs => vol_grid_3d.rs} (80%) diff --git a/common/src/state.rs b/common/src/state.rs index 6d18e06fea..5f4a847e15 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -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::::default()); @@ -220,12 +220,12 @@ impl State { } /// Get a reference to this state's terrain. - pub fn terrain(&self) -> Fetch { + pub fn terrain(&self) -> Fetch { self.ecs.read_resource() } /// Get a writable reference to this state's terrain. - pub fn terrain_mut(&self) -> FetchMut { + pub fn terrain_mut(&self) -> FetchMut { self.ecs.write_resource() } @@ -251,7 +251,7 @@ impl State { pub fn insert_chunk(&mut self, key: Vec2, chunk: TerrainChunk) { if self .ecs - .write_resource::() + .write_resource::() .insert(key, Arc::new(chunk)) .is_some() { @@ -271,7 +271,7 @@ impl State { pub fn remove_chunk(&mut self, key: Vec2) { if self .ecs - .write_resource::() + .write_resource::() .remove(key) .is_some() { @@ -302,7 +302,7 @@ impl State { self.ecs.maintain(); // Apply terrain changes - let mut terrain = self.ecs.write_resource::(); + let mut terrain = self.ecs.write_resource::(); self.ecs .read_resource::() .blocks diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index 3acabeb997..38a5d95ea4 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -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>, diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index cd16ee87a3..7f9f5df273 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -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>, ReadStorage<'a, Scale>, diff --git a/common/src/terrain/mod.rs b/common/src/terrain/mod.rs index 5df7397554..a97d585eac 100644 --- a/common/src/terrain/mod.rs +++ b/common/src/terrain/mod.rs @@ -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; -pub type TerrainMap = VolMap2d; +pub type TerrainGrid = VolGrid2d; diff --git a/common/src/volumes/mod.rs b/common/src/volumes/mod.rs index 16efd93253..2a0a2c597a 100644 --- a/common/src/volumes/mod.rs +++ b/common/src/volumes/mod.rs @@ -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; diff --git a/common/src/volumes/vol_map_2d.rs b/common/src/volumes/vol_grid_2d.rs similarity index 80% rename from common/src/volumes/vol_map_2d.rs rename to common/src/volumes/vol_grid_2d.rs index 4fb1fd3be8..14b3faecb2 100644 --- a/common/src/volumes/vol_map_2d.rs +++ b/common/src/volumes/vol_grid_2d.rs @@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc}; use vek::*; #[derive(Debug, Clone)] -pub enum VolMap2dError { +pub enum VolGrid2dError { NoSuchChunk, ChunkError(V::Error), DynaError(DynaError), @@ -18,12 +18,12 @@ pub enum VolMap2dError { // S = Size (replace with a const when const generics is a thing) // M = Chunk metadata #[derive(Clone)] -pub struct VolMap2d { +pub struct VolGrid2d { chunks: HashMap, Arc>, phantom: PhantomData, } -impl VolMap2d { +impl VolGrid2d { #[inline(always)] pub fn chunk_key>>(pos: P) -> Vec2 { pos.into() @@ -37,37 +37,37 @@ impl VolMap2d { } } -impl BaseVol for VolMap2d { +impl BaseVol for VolGrid2d { type Vox = V::Vox; - type Error = VolMap2dError; + type Error = VolGrid2dError; } -impl ReadVol for VolMap2d { +impl ReadVol for VolGrid2d { #[inline(always)] - fn get(&self, pos: Vec3) -> Result<&V::Vox, VolMap2dError> { + fn get(&self, pos: Vec3) -> Result<&V::Vox, VolGrid2dError> { 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>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for VolMap2d { - type Sample = VolMap2d; +impl>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for VolGrid2d { + type Sample = VolGrid2d; /// 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> { + fn sample(&self, range: I) -> Result> { 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>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol } } -impl WriteVol for VolMap2d { +impl WriteVol for VolGrid2d { #[inline(always)] - fn set(&mut self, pos: Vec3, vox: V::Vox) -> Result<(), VolMap2dError> { + fn set(&mut self, pos: Vec3, vox: V::Vox) -> Result<(), VolGrid2dError> { 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 VolMap2d { - pub fn new() -> Result> { +impl VolGrid2d { + pub fn new() -> Result> { if Self::chunk_size() .map(|e| e.is_power_of_two() && e > 0) .reduce_and() @@ -113,7 +113,7 @@ impl VolMap2d { phantom: PhantomData, }) } else { - Err(VolMap2dError::InvalidChunkSize) + Err(VolGrid2dError::InvalidChunkSize) } } diff --git a/common/src/volumes/vol_map_3d.rs b/common/src/volumes/vol_grid_3d.rs similarity index 80% rename from common/src/volumes/vol_map_3d.rs rename to common/src/volumes/vol_grid_3d.rs index 57f7263561..67422fb8c3 100644 --- a/common/src/volumes/vol_map_3d.rs +++ b/common/src/volumes/vol_grid_3d.rs @@ -7,7 +7,7 @@ use std::{fmt::Debug, marker::PhantomData, sync::Arc}; use vek::*; #[derive(Debug)] -pub enum VolMap3dError { +pub enum VolGrid3dError { NoSuchChunk, ChunkErr(V::Error), DynaError(DynaError), @@ -18,12 +18,12 @@ pub enum VolMap3dError { // S = Size (replace with a const when const generics is a thing) // M = Chunk metadata #[derive(Clone)] -pub struct VolMap3d { +pub struct VolGrid3d { chunks: HashMap, Arc>, phantom: PhantomData, } -impl VolMap3d { +impl VolGrid3d { #[inline(always)] pub fn chunk_key(pos: Vec3) -> Vec3 { pos.map2(S::SIZE, |e, sz| { @@ -42,36 +42,36 @@ impl VolMap3d { } } -impl BaseVol for VolMap3d { +impl BaseVol for VolGrid3d { type Vox = V::Vox; - type Error = VolMap3dError; + type Error = VolGrid3dError; } -impl ReadVol for VolMap3d { +impl ReadVol for VolGrid3d { #[inline(always)] - fn get(&self, pos: Vec3) -> Result<&V::Vox, VolMap3dError> { + fn get(&self, pos: Vec3) -> Result<&V::Vox, VolGrid3dError> { 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>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for VolMap3d { - type Sample = VolMap3d; +impl>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for VolGrid3d { + type Sample = VolGrid3d; /// 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> { + fn sample(&self, range: I) -> Result> { 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>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol } } -impl WriteVol for VolMap3d { +impl WriteVol for VolGrid3d { #[inline(always)] - fn set(&mut self, pos: Vec3, vox: V::Vox) -> Result<(), VolMap3dError> { + fn set(&mut self, pos: Vec3, vox: V::Vox) -> Result<(), VolGrid3dError> { 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 VolMap3d { - pub fn new() -> Result> { +impl VolGrid3d { + pub fn new() -> Result> { if Self::chunk_size() .map(|e| e.is_power_of_two() && e > 0) .reduce_and() @@ -119,7 +119,7 @@ impl VolMap3d { phantom: PhantomData, }) } else { - Err(VolMap3dError::InvalidChunkSize) + Err(VolGrid3dError::InvalidChunkSize) } } diff --git a/server/src/lib.rs b/server/src/lib.rs index 606b143923..61fe68df39 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -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::(); let _ = ecs - .read_resource::() + .read_resource::() .ray(pos, pos + dir * radius) .until(|_| rand::random::() < 0.05) .for_each(|pos| block_change.set(pos, Block::empty())) @@ -462,7 +462,7 @@ impl Server { fn chunk_in_vd( player_pos: Vec3, chunk_pos: Vec2, - terrain: &TerrainMap, + terrain: &TerrainGrid, vd: u32, ) -> bool { let player_chunk_pos = terrain.pos_key(player_pos.map(|e| e as i32)); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index b3d479a672..f1c8c608e0 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -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 + ReadVol + Debug, S: VolSize + Clone> - Meshable for VolMap2d + Meshable for VolGrid2d { type Pipeline = TerrainPipeline; type TranslucentPipeline = FluidPipeline; @@ -126,7 +126,7 @@ impl + ReadVol + Debug, S: VolSize + Clone> } /* -impl + ReadVol + Debug, S: VolSize + Clone> Meshable for VolMap3d { +impl + ReadVol + Debug, S: VolSize + Clone> Meshable for VolGrid3d { type Pipeline = TerrainPipeline; type Supplement = Aabb; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 3b0947505c..cda4b7b2e7 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -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, z_bounds: (f32, f32), started_tick: u64, - volume: >>::Sample, + volume: >>::Sample, range: Aabb, ) -> 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 }), )