diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2026-01-13 10:51:30 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-13 10:51:30 -0600 |
| commit | d5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (patch) | |
| tree | ea04702f96ad170fb1d90e5ed2dc875ae8166495 /azalea-world/src/world.rs | |
| parent | efb36d5fc0fe56a98f5795c53dfa109887cd5aae (diff) | |
| download | azalea-drasl-d5fa5e32b37754b3b5c136e58821e48cd3b7c2ff.tar.xz | |
Rename Instance to World (#304)
Diffstat (limited to 'azalea-world/src/world.rs')
| -rw-r--r-- | azalea-world/src/world.rs | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs index a6ee1a63..74390ee4 100644 --- a/azalea-world/src/world.rs +++ b/azalea-world/src/world.rs @@ -14,30 +14,30 @@ use nohash_hasher::IntMap; use crate::{ChunkStorage, PartialChunkStorage}; -/// PartialInstances are usually owned by clients, and hold strong references to -/// chunks and entities in [`Instance`]s. +/// A reference to a slice of the world, as seen by an individual client. /// -/// Basically, they hold the chunks and entities that are within render -/// distance but can still access chunks and entities owned by other -/// `PartialInstance`s that have the same `Instance`. +/// A `PartialWorld` will typically be owned by a client, and it holds strong +/// references to chunks and entities in a [`World`]s. /// -/// This is primarily useful for having multiple clients in the same Instance. -pub struct PartialInstance { +/// In other words, this type holds the chunks and entities that are within +/// render distance for a client. The same chunk/entity may be referenced by +/// more than one `PartialWorld`. +pub struct PartialWorld { pub chunks: PartialChunkStorage, /// Some metadata about entities, like what entities are in certain chunks. /// This does not contain the entity data itself, that's in the ECS. pub entity_infos: PartialEntityInfos, } -impl PartialInstance { +impl PartialWorld { pub fn new(chunk_radius: u32, owner_entity: Option<Entity>) -> Self { - PartialInstance { + PartialWorld { chunks: PartialChunkStorage::new(chunk_radius), entity_infos: PartialEntityInfos::new(owner_entity), } } - /// Clears the internal references to chunks in the PartialInstance and + /// Clears the internal references to chunks in the [`PartialWorld`] and /// resets the view center. pub fn reset(&mut self) { self.chunks = PartialChunkStorage::new(self.chunks.chunk_radius); @@ -75,16 +75,21 @@ impl PartialEntityInfos { } } -/// A world where the chunks are stored as weak pointers. This is used for -/// shared worlds. +/// A Minecraft world, sometimes referred to as a dimension. /// -/// Also see [`PartialInstance`]. +/// This is the most commonly used type to interact with the world that a client +/// is in. In here, all chunks are stored as weak pointers, which means that +/// clients in different areas of the same world can share the same `World` +/// instance. /// -/// This is sometimes interchangeably called a "world". However, this type is -/// called `Instance` to avoid colliding with the `World` type from Bevy ECS. +/// Also see [`PartialWorld`]. +/// +/// Note that this is distinct from Bevy's `World` type, which contains all of +/// the data for every client. When referring to the Bevy `World` within Azalea, +/// the term "ECS" is generally used instead. #[derive(Debug, Default)] -#[doc(alias("world", "dimension"))] -pub struct Instance { +#[doc(alias("instance", "dimension", "level"))] +pub struct World { pub chunks: ChunkStorage, /// An index of all the entities we know are in the chunks of the world @@ -101,7 +106,10 @@ pub struct Instance { pub registries: RegistryHolder, } -impl Instance { +#[deprecated = "renamed to `World`."] +pub type Instance = World; + +impl World { /// Get the block at the given position, or `None` if it's outside of the /// world that we have loaded. pub fn get_block_state(&self, pos: BlockPos) -> Option<BlockState> { @@ -131,17 +139,17 @@ impl Instance { } } -impl Debug for PartialInstance { +impl Debug for PartialWorld { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("PartialInstance") + f.debug_struct("PartialWorld") .field("chunks", &self.chunks) .field("entity_infos", &self.entity_infos) .finish() } } -impl Default for PartialInstance { - /// Creates a completely self-contained `PartialInstance`. This is only for +impl Default for PartialWorld { + /// Creates a completely self-contained [`PartialWorld`]. This is only for /// testing and shouldn't be used in actual code! fn default() -> Self { let chunk_storage = PartialChunkStorage::default(); @@ -153,7 +161,7 @@ impl Default for PartialInstance { } } -impl From<ChunkStorage> for Instance { +impl From<ChunkStorage> for World { /// Make an empty world from this `ChunkStorage`. This is meant to be a /// convenience function for tests. fn from(chunks: ChunkStorage) -> Self { |
