diff options
| author | mat <git@matdoes.dev> | 2025-10-12 23:01:54 +0300 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-10-12 23:01:54 +0300 |
| commit | ee2575794e91b9457a74a95daf1dcc707058cd58 (patch) | |
| tree | df725850ef18ded5ce3f6552e17095d0f704ae84 /azalea-world/src | |
| parent | 1a1402954b07cd77615d0afc026c73b008787f51 (diff) | |
| download | azalea-drasl-ee2575794e91b9457a74a95daf1dcc707058cd58.tar.xz | |
upgrade deps and clean up lots of doc comments
Diffstat (limited to 'azalea-world/src')
| -rw-r--r-- | azalea-world/src/chunk_storage.rs | 39 | ||||
| -rw-r--r-- | azalea-world/src/container.rs | 11 | ||||
| -rw-r--r-- | azalea-world/src/find_blocks.rs | 2 | ||||
| -rw-r--r-- | azalea-world/src/iterators.rs | 5 | ||||
| -rw-r--r-- | azalea-world/src/palette/container.rs | 26 | ||||
| -rw-r--r-- | azalea-world/src/palette/tests.rs | 4 | ||||
| -rw-r--r-- | azalea-world/src/world.rs | 11 |
7 files changed, 55 insertions, 43 deletions
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index d38c5ef9..35d8cac3 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -28,7 +28,9 @@ use crate::{ const SECTION_HEIGHT: u32 = 16; /// An efficient storage of chunks for a client that has a limited render -/// distance. This has support for using a shared [`ChunkStorage`]. +/// distance. +/// +/// This has support for using a shared [`ChunkStorage`]. pub struct PartialChunkStorage { /// The center of the view, i.e. the chunk the player is currently in. view_center: ChunkPos, @@ -39,8 +41,9 @@ pub struct PartialChunkStorage { } /// A storage for chunks where they're only stored weakly, so if they're not -/// actively being used somewhere else they'll be forgotten. This is used for -/// shared worlds. +/// actively being used somewhere else they'll be forgotten. +/// +/// This is used for shared worlds. /// /// This is relatively cheap to clone since it's just an `IntMap` with `Weak` /// pointers. @@ -51,10 +54,11 @@ pub struct ChunkStorage { pub map: IntMap<ChunkPos, Weak<RwLock<Chunk>>>, } -/// A single chunk in a world (16*?*16 blocks). This only contains the blocks -/// and biomes. You can derive the height of the chunk from the number of -/// sections, but you need a [`ChunkStorage`] to get the minimum Y -/// coordinate. +/// A single chunk in a world (16*?*16 blocks). +/// +/// This only contains blocks and biomes. You can derive the height of the chunk +/// from the number of sections, but you need a [`ChunkStorage`] to get the +/// minimum Y coordinate. #[derive(Debug)] pub struct Chunk { pub sections: Box<[Section]>, @@ -72,8 +76,9 @@ pub struct Section { pub biomes: PalettedContainer<Biome>, } -/// Get the actual stored view distance for the selected view distance. For some -/// reason Minecraft actually stores an extra 3 chunks. +/// Get the actual stored view distance for the selected view distance. +/// +/// For some reason, Minecraft stores an extra 3 chunks. pub fn calculate_chunk_storage_range(view_distance: u32) -> u32 { u32::max(view_distance, 2) + 3 } @@ -98,8 +103,10 @@ impl PartialChunkStorage { } } - /// Update the chunk to center the view on. This should be called when the - /// client receives a `SetChunkCacheCenter` packet. + /// Update the chunk to center the view on. + /// + /// This should be called when the client receives a `SetChunkCacheCenter` + /// packet. pub fn update_view_center(&mut self, view_center: ChunkPos) { // this code block makes it force unload the chunks that are out of range after // updating the view center. it's usually fine without it but the commented code @@ -211,8 +218,9 @@ impl PartialChunkStorage { self.chunks[index].as_ref() } /// Get a mutable reference to a [`Chunk`] within render distance, or - /// `None` if it's not loaded. Use [`ChunkStorage::get`] to get - /// a chunk from the shared storage. + /// `None` if it's not loaded. + /// + /// Use [`ChunkStorage::get`] to get a chunk from the shared storage. pub fn limited_get_mut(&mut self, pos: &ChunkPos) -> Option<&mut Option<Arc<RwLock<Chunk>>>> { if !self.in_range(pos) { return None; @@ -224,8 +232,9 @@ impl PartialChunkStorage { } /// Set a chunk in the shared storage and reference it from the limited - /// storage. Use [`Self::limited_set`] if you already have an - /// `Arc<RwLock<Chunk>>`. + /// storage. + /// + /// Use [`Self::limited_set`] if you already have an `Arc<RwLock<Chunk>>`. /// /// # Panics /// If the chunk is not in the render distance. diff --git a/azalea-world/src/container.rs b/azalea-world/src/container.rs index bb8ade70..279f3061 100644 --- a/azalea-world/src/container.rs +++ b/azalea-world/src/container.rs @@ -13,8 +13,10 @@ use tracing::{debug, error}; use crate::{ChunkStorage, Instance}; -/// A container of [`Instance`]s (aka worlds). Instances are stored as a Weak -/// pointer here, so if no clients are using an instance it will be forgotten. +/// A container of [`Instance`]s (aka worlds). +/// +/// Instances are stored as a Weak pointer here, so if no clients are using an +/// instance it will be forgotten. #[derive(Default, Resource)] pub struct InstanceContainer { // We just refer to the chunks here and don't include entities because there's not that many @@ -85,8 +87,9 @@ impl InstanceContainer { } } -/// The name of the [`Instance`](crate::Instance) (world) the entity is -/// in. If two entities share the same instance name, we assume they're in the +/// The name of the [`Instance`] (aka world/dimension) that the entity is in. +/// +/// If two entities share the same instance name, we assume they're in the /// same instance. #[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)] #[doc(alias("worldname", "world name"))] diff --git a/azalea-world/src/find_blocks.rs b/azalea-world/src/find_blocks.rs index 4086358f..17e66754 100644 --- a/azalea-world/src/find_blocks.rs +++ b/azalea-world/src/find_blocks.rs @@ -224,7 +224,7 @@ pub fn find_blocks_in_chunk( let block_state = section.states.get_at_index(i); if block_states.contains(&block_state) { - let section_pos = section.states.coords_from_index(i); + let section_pos = section.states.pos_from_index(i); let (x, y, z) = ( chunk_pos.x * 16 + (section_pos.x as i32), min_y + (section_index * 16) as i32 + section_pos.y as i32, diff --git a/azalea-world/src/iterators.rs b/azalea-world/src/iterators.rs index 3362487b..eb6b2052 100644 --- a/azalea-world/src/iterators.rs +++ b/azalea-world/src/iterators.rs @@ -77,8 +77,9 @@ impl Iterator for BlockIterator { } } -/// A spiral iterator, useful for iterating over chunks in a world. Use -/// `ChunkIterator` to sort by x+y+z (Manhattan) distance. +/// A spiral iterator, useful for iterating over chunks in a world. +/// +/// You can use [`ChunkIterator`] instead to sort by x+y+z (Manhattan) distance. /// /// ``` /// # use azalea_core::position::ChunkPos; diff --git a/azalea-world/src/palette/container.rs b/azalea-world/src/palette/container.rs index 0ddac6c2..4aae64de 100644 --- a/azalea-world/src/palette/container.rs +++ b/azalea-world/src/palette/container.rs @@ -151,14 +151,14 @@ impl<S: PalletedContainerKind> PalettedContainer<S> { }) } - /// Calculates the index of the given coordinates. - pub fn index_from_coords(&self, pos: S::SectionPos) -> usize { + /// Calculates the index of the given position. + pub fn index_from_pos(&self, pos: S::SectionPos) -> usize { let size_bits = S::size_bits(); let (x, y, z) = pos.coords(); (((y << size_bits) | z) << size_bits) | x } - pub fn coords_from_index(&self, index: usize) -> S::SectionPos { + pub fn pos_from_index(&self, index: usize) -> S::SectionPos { let size_bits = S::size_bits(); let mask = (1 << size_bits) - 1; S::SectionPos::new( @@ -173,8 +173,8 @@ impl<S: PalletedContainerKind> PalettedContainer<S> { /// # Panics /// /// This function panics if the index is greater than or equal to the number - /// of things in the storage. (So for block states, it must be less than - /// 4096). + /// of things in the storage. For example, for block states, it must be less + /// than 4096. pub fn get_at_index(&self, index: usize) -> S { // first get the palette id let paletted_value = self.storage.get(index); @@ -182,32 +182,30 @@ impl<S: PalletedContainerKind> PalettedContainer<S> { self.palette.value_for(paletted_value as usize) } - /// Returns the value at the given coordinates. + /// Returns the value at the given position. pub fn get(&self, pos: S::SectionPos) -> S { - // let paletted_value = self.storage.get(self.get_index(x, y, z)); - // self.palette.value_for(paletted_value as usize) - self.get_at_index(self.index_from_coords(pos)) + self.get_at_index(self.index_from_pos(pos)) } - /// Sets the id at the given coordinates and return the previous id + /// Sets the ID at the given position and return the previous ID. pub fn get_and_set(&mut self, pos: S::SectionPos, value: S) -> S { let paletted_value = self.id_for(value); let old_paletted_value = self .storage - .get_and_set(self.index_from_coords(pos), paletted_value as u64); + .get_and_set(self.index_from_pos(pos), paletted_value as u64); self.palette.value_for(old_paletted_value as usize) } - /// Sets the id at the given index and return the previous id. You probably + /// Sets the ID at the given index and return the previous ID. You probably /// want `.set` instead. pub fn set_at_index(&mut self, index: usize, value: S) { let paletted_value = self.id_for(value); self.storage.set(index, paletted_value as u64); } - /// Sets the id at the given coordinates and return the previous id + /// Sets the ID at the given position and return the previous ID. pub fn set(&mut self, pos: S::SectionPos, value: S) { - self.set_at_index(self.index_from_coords(pos), value); + self.set_at_index(self.index_from_pos(pos), value); } fn create_or_reuse_data(&self, bits_per_entry: u8) -> PalettedContainer<S> { diff --git a/azalea-world/src/palette/tests.rs b/azalea-world/src/palette/tests.rs index d1423306..39031a38 100644 --- a/azalea-world/src/palette/tests.rs +++ b/azalea-world/src/palette/tests.rs @@ -69,8 +69,8 @@ fn test_coords_from_index() { for y in 0..15 { for z in 0..15 { assert_eq!( - palette_container.coords_from_index( - palette_container.index_from_coords(ChunkSectionBlockPos::new(x, y, z)) + palette_container.pos_from_index( + palette_container.index_from_pos(ChunkSectionBlockPos::new(x, y, z)) ), ChunkSectionBlockPos::new(x, y, z) ); diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs index 082ba7bc..969b7d36 100644 --- a/azalea-world/src/world.rs +++ b/azalea-world/src/world.rs @@ -119,11 +119,10 @@ impl From<u32> for MinecraftEntityId { /// world. #[derive(Debug, Default)] pub struct PartialEntityInfos { - // note: using MinecraftEntityId for entity ids is acceptable here since - // there's no chance of collisions here - /// The entity id of the player that owns this partial world. This will - /// make `RelativeEntityUpdate` pretend this entity doesn't exist so - /// it doesn't get modified from outside sources. + /// The entity ID of the player that owns this partial world. + /// + /// This will make `RelativeEntityUpdate` pretend this entity doesn't exist + /// so it doesn't get modified from outside sources. pub owner_entity: Option<Entity>, /// A counter for each entity that tracks how many updates we've observed /// for it. @@ -131,6 +130,8 @@ pub struct PartialEntityInfos { /// This is used for shared worlds (i.e. swarms), to make sure we don't /// update entities twice on accident. pub updates_received: IntMap<MinecraftEntityId, u32>, + // ^ note: using MinecraftEntityId for entity ids is acceptable here since + // there's no chance of collisions } impl PartialEntityInfos { |
