From 77980f0018eca3a192994021b76ad5d05bff88ea Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 25 Jun 2022 14:24:56 -0500 Subject: [PATCH] rename World to dimension A world is a collection of dimensions --- azalea-client/src/client.rs | 22 ++++++++++++---------- azalea-client/src/player.rs | 4 ++-- azalea-world/src/chunk.rs | 15 +++++++++------ azalea-world/src/lib.rs | 11 ++++++----- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index dfefe4ad..2bc73551 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -23,7 +23,7 @@ use azalea_protocol::{ }, resolver, ServerAddress, }; -use azalea_world::World; +use azalea_world::Dimension; use owning_ref::OwningRef; use std::{ fmt::Debug, @@ -37,7 +37,7 @@ use tokio::{ #[derive(Default)] pub struct ClientState { pub player: Player, - pub world: Option, + pub world: Option, } #[derive(Debug, Clone)] @@ -294,13 +294,15 @@ impl Client { // the 16 here is our render distance // i'll make this an actual setting later - state_lock.world = Some(World::new(16, height, min_y)); + state_lock.world = Some(Dimension::new(16, height, min_y)); let entity = Entity::new(p.player_id, game_profile.uuid, EntityPos::default()); state_lock .world .as_mut() - .expect("World doesn't exist! We should've gotten a login packet by now.") + .expect( + "Dimension doesn't exist! We should've gotten a login packet by now.", + ) .add_entity(entity); state_lock.player.set_entity_id(p.player_id); @@ -461,7 +463,7 @@ impl Client { .lock()? .world .as_mut() - .expect("World doesn't exist! We should've gotten a login packet by now.") + .expect("Dimension doesn't exist! We should've gotten a login packet by now.") .replace_with_packet_data(&pos, &mut p.chunk_data.data.as_slice()) .unwrap(); } @@ -475,7 +477,7 @@ impl Client { .lock()? .world .as_mut() - .expect("World doesn't exist! We should've gotten a login packet by now.") + .expect("Dimension doesn't exist! We should've gotten a login packet by now.") .add_entity(entity); } GamePacket::ClientboundSetEntityDataPacket(_p) => { @@ -497,7 +499,7 @@ impl Client { .lock()? .world .as_mut() - .expect("World doesn't exist! We should've gotten a login packet by now.") + .expect("Dimension doesn't exist! We should've gotten a login packet by now.") .add_entity(entity); } GamePacket::ClientboundInitializeBorderPacket(p) => { @@ -640,14 +642,14 @@ impl Client { tx.send(Event::GameTick).unwrap(); } - /// Gets the `World` the client is in. + /// Gets the `Dimension` the client is in. /// /// This is basically a shortcut for `client.state.lock().unwrap().world.as_ref().unwrap()`. /// If the client hasn't received a login packet yet, this will panic. - pub fn world(&self) -> OwningRef, World> { + pub fn world(&self) -> OwningRef, Dimension> { let state_lock: std::sync::MutexGuard = self.state.lock().unwrap(); let state_lock_ref = OwningRef::new(state_lock); - state_lock_ref.map(|state| state.world.as_ref().expect("World doesn't exist!")) + state_lock_ref.map(|state| state.world.as_ref().expect("Dimension doesn't exist!")) } /// Gets the `Player` struct for our player. diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs index ee0b9718..7501eede 100644 --- a/azalea-client/src/player.rs +++ b/azalea-client/src/player.rs @@ -1,5 +1,5 @@ use azalea_entity::Entity; -use azalea_world::World; +use azalea_world::Dimension; use uuid::Uuid; #[derive(Default, Debug)] @@ -12,7 +12,7 @@ pub struct Player { impl Player { /// Get the entity of the player in the world. - pub fn entity<'a>(&self, world: &'a World) -> Option<&'a Entity> { + pub fn entity<'a>(&self, world: &'a Dimension) -> Option<&'a Entity> { // world.entity_by_uuid(&self.uuid) world.entity_by_id(self.entity_id) } diff --git a/azalea-world/src/chunk.rs b/azalea-world/src/chunk.rs index a19ece8c..e4893ace 100644 --- a/azalea-world/src/chunk.rs +++ b/azalea-world/src/chunk.rs @@ -1,6 +1,6 @@ use crate::palette::PalettedContainer; use crate::palette::PalettedContainerType; -use crate::World; +use crate::Dimension; use azalea_block::BlockState; use azalea_buf::{McBufReadable, McBufWritable}; use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos}; @@ -78,7 +78,7 @@ impl ChunkStorage { return Ok(()); } - let chunk = Arc::new(Mutex::new(Chunk::read_with_world_height( + let chunk = Arc::new(Mutex::new(Chunk::read_with_dimension_height( data, self.height, )?)); @@ -109,12 +109,15 @@ pub struct Chunk { } impl Chunk { - pub fn read_with_world(buf: &mut impl Read, data: &World) -> Result { - Self::read_with_world_height(buf, data.height()) + pub fn read_with_dimension(buf: &mut impl Read, data: &Dimension) -> Result { + Self::read_with_dimension_height(buf, data.height()) } - pub fn read_with_world_height(buf: &mut impl Read, world_height: u32) -> Result { - let section_count = world_height / SECTION_HEIGHT; + pub fn read_with_dimension_height( + buf: &mut impl Read, + dimension_height: u32, + ) -> Result { + let section_count = dimension_height / SECTION_HEIGHT; let mut sections = Vec::with_capacity(section_count as usize); for _ in 0..section_count { let section = Section::read_from(buf)?; diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 3afa4fee..7822dcc4 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -27,15 +27,16 @@ mod tests { } } +/// A dimension is a collection of chunks and entities. #[derive(Debug)] -pub struct World { +pub struct Dimension { chunk_storage: ChunkStorage, entity_storage: EntityStorage, } -impl World { +impl Dimension { pub fn new(chunk_radius: u32, height: u32, min_y: i32) -> Self { - World { + Dimension { chunk_storage: ChunkStorage::new(chunk_radius, height, min_y), entity_storage: EntityStorage::new(), } @@ -135,14 +136,14 @@ impl World { } } -impl Index<&ChunkPos> for World { +impl Index<&ChunkPos> for Dimension { type Output = Option>>; fn index(&self, pos: &ChunkPos) -> &Self::Output { &self.chunk_storage[pos] } } -impl IndexMut<&ChunkPos> for World { +impl IndexMut<&ChunkPos> for Dimension { fn index_mut<'a>(&'a mut self, pos: &ChunkPos) -> &'a mut Self::Output { &mut self.chunk_storage[pos] }