Skip to main content

ChunkHolder

Struct ChunkHolder 

Source
pub struct ChunkHolder {
Show 22 fields data: OnceLock<Chunk>, published_status: AtomicU8, status_changed: Notify, generation_task: SyncMutex<Option<Arc<ChunkGenerationTask>>>, generation_task_target: AtomicU8, pos: ChunkPos, load_level: AtomicU8, simulation_level: AtomicU8, started_work: AtomicUsize, active_save_dependencies: AtomicUsize, save_lifecycle: AtomicU8, highest_allowed_status: AtomicU8, min_y: i32, height: i32, has_changed_sections: AtomicBool, queued_for_broadcast: AtomicBool, packet_content_revision: AtomicU64, ticking_readiness: AtomicU64, full_status_initialized: AtomicBool, full_publications: Weak<FullPublicationQueue>, changed_blocks_per_section: Box<[SyncMutex<FxHashSet<PackedSectionBlockPos>>]>, changed_light_sections: SyncMutex<ChangedLightSectionSets>,
}
Expand description

Holds chunk data and coordinates asynchronous generation work.

published_status is released only after the corresponding data and Full tick containers are installed. Synchronous readers acquire it before reading data; status_changed wakes async waiters so they can re-check the atomic state.

Fields§

§data: OnceLock<Chunk>§published_status: AtomicU8§status_changed: Notify§generation_task: SyncMutex<Option<Arc<ChunkGenerationTask>>>§generation_task_target: AtomicU8§pos: ChunkPos§load_level: AtomicU8

The current loading ticket level of the chunk.

§simulation_level: AtomicU8

The current simulation ticket level of the chunk.

§started_work: AtomicUsize

The highest status that has started work.

§active_save_dependencies: AtomicUsize

Number of save dependencies that have not completed yet.

§save_lifecycle: AtomicU8

Coordinates unloading revival with the short immutable save-preparation phase.

§highest_allowed_status: AtomicU8

The highest status that generation is allowed to reach.

§min_y: i32

The minimum Y coordinate of the world.

§height: i32

The total height of the world.

§has_changed_sections: AtomicBool

Whether any sections have pending block changes.

§queued_for_broadcast: AtomicBool

Whether this holder is already queued for the next broadcast flush.

§packet_content_revision: AtomicU64

Monotonic revision for client-visible chunk packet content.

§ticking_readiness: AtomicU64

Packed ticking readiness generation. The low two bits store TickingReadiness.

§full_status_initialized: AtomicBool

Whether Full post-load initialization completed and was published for readiness.

§full_publications: Weak<FullPublicationQueue>

Weak sink for Full status publication notifications.

§changed_blocks_per_section: Box<[SyncMutex<FxHashSet<PackedSectionBlockPos>>]>

Per-section sets of changed block positions. Index is (block_y - min_y) / 16.

§changed_light_sections: SyncMutex<ChangedLightSectionSets>

Changed light sections grouped by light layer.

Implementations§

Source§

impl ChunkHolder

Source

pub const fn get_pos(&self) -> ChunkPos

Gets the chunk position.

Source

pub const fn min_y(&self) -> i32

Gets the minimum Y coordinate of the world.

Source

pub const fn height(&self) -> i32

Gets the total height of the world.

Source

pub fn new( pos: ChunkPos, load_level: ChunkTicketLevel, simulation_level: Option<ChunkTicketLevel>, min_y: i32, height: i32, ) -> Self

Creates a new chunk holder.

Source

pub(crate) fn new_with_full_publications( pos: ChunkPos, load_level: ChunkTicketLevel, simulation_level: Option<ChunkTicketLevel>, min_y: i32, height: i32, full_publications: Weak<FullPublicationQueue>, ) -> Self

Source

pub fn load_level(&self) -> Option<ChunkTicketLevel>

Returns the current load ticket level.

Source

pub(crate) fn swap_load_level( &self, level: ChunkTicketLevel, ) -> Option<ChunkTicketLevel>

Stores the current load ticket level and returns the previous level.

Source

pub(crate) fn clear_load_level(&self)

Clears the current load ticket level.

Source

pub fn simulation_level(&self) -> Option<ChunkTicketLevel>

Returns the current simulation ticket level.

Source

pub(crate) fn set_simulation_level(&self, level: Option<ChunkTicketLevel>)

Stores the current simulation ticket level.

Source

pub(crate) fn entity_visibility(&self) -> EntityVisibility

Source

pub fn update_highest_allowed_status( &self, ticket_level: Option<ChunkTicketLevel>, )

Updates the highest allowed generation status based on the ticket level.

Source

pub fn block_changed(&self, pos: BlockPos) -> bool

Records a block change at the given position. Returns true if this is the first change (chunk should be added to broadcast list).

Source

pub fn light_changed(&self, layer: LightLayer, section_pos: SectionPos) -> bool

Records a light-section change for a full chunk and marks saved light data dirty.

Returns true if this is the first pending broadcast change for the chunk holder.

Source

pub fn mark_light_section_dirty(&self, section_pos: SectionPos) -> bool

Marks saved light data dirty without queuing client-visible changes.

Source

fn mark_valid_light_section_dirty( &self, section_pos: SectionPos, ) -> Option<bool>

Source

pub fn has_changes_to_broadcast(&self) -> bool

Returns whether there are pending changes to broadcast.

Source

pub fn clear_broadcast_queued(&self)

Allows later changes to enqueue this holder for a future broadcast.

Source

pub fn take_changed_blocks( &self, ) -> Vec<(usize, FxHashSet<PackedSectionBlockPos>)>

Takes all pending block changes, grouped by section index. Returns a vec of (section_index, set of packed positions).

Source

pub fn take_changed_light_sections(&self) -> ChangedLightSections

Takes all pending light-section changes.

Source

pub fn mark_packet_content_changed(&self)

Marks the holder’s client-visible chunk packet content as changed.

Source

pub fn packet_content_revision(&self) -> u64

Returns the current client-visible content revision.

Source

pub(crate) fn ticking_readiness_snapshot(&self) -> TickingReadinessSnapshot

Source

pub(crate) fn is_full_status_initialized(&self) -> bool

Source

pub(crate) fn transition_ticking_readiness( &self, target: TickingReadiness, ) -> Option<TickingReadiness>

Source

pub fn section_count(&self) -> usize

Returns the number of sections in this chunk.

Source

pub fn is_status_disallowed(&self, status: ChunkStatus) -> bool

Checks if the given status is disallowed.

Source

pub(crate) fn schedule_chunk_generation_task_b( &self, status: ChunkStatus, chunk_map: &Arc<ChunkMap>, ) -> bool

Schedules a generation task for this chunk if needed.

Returns true if a new task was actually scheduled, false if the chunk already has a suitable task or is already at the target status.

Source

pub(crate) fn reschedule_chunk_task_b( &self, status: ChunkStatus, chunk_map: &Arc<ChunkMap>, )

Reschedules the chunk task to the given status.

Source

pub fn try_chunk(&self, status: ChunkStatus) -> Option<&Chunk>

Gets access to the chunk if it has reached the given status.

Source

pub fn try_full_chunk(&self) -> Option<FullChunkRef<'_>>

Gets the Full-only capability after Full status is published.

Source

pub async fn await_chunk(&self, status: ChunkStatus) -> Option<&Chunk>

Waits until the chunk has reached the given status.

Source

pub async fn await_chunk_status( &self, status: ChunkStatus, ) -> Option<ChunkStatus>

Waits until the chunk has reached the given status without reading chunk data.

Source

async fn await_claimed_chunk_status( &self, status: ChunkStatus, ) -> Option<ChunkStatus>

Source

pub fn published_status(&self) -> Option<ChunkStatus>

Gets the published status of the chunk.

Source

pub fn is_ready_for_saving(&self) -> bool

Returns whether vanilla timed tickets may age for this chunk.

Source

pub(crate) fn add_save_dependency(self: &Arc<Self>) -> ChunkSaveDependency

Source

pub(crate) fn begin_unloading(&self)

Moves an active holder into the unloading lifecycle.

Source

pub(crate) fn try_begin_save_preparation( self: &Arc<Self>, ) -> Option<ChunkSavePreparationGuard>

Reserves the unloading holder while its immutable save input is assembled.

Source

pub(crate) fn try_revive_from_unloading(&self) -> bool

Attempts to reactivate an unloading holder without waiting for save preparation.

Source

pub fn apply_step( self: &Arc<Self>, step: &'static ChunkStep, chunk_map: &Arc<ChunkMap>, cache: &Arc<StaticCache2D<Arc<ChunkHolder>>>, thread_pool: Arc<ThreadPool>, ) -> Option<NeighborReady>

Applies a step to the chunk.

Cancellation is handled structurally by the owning generation task: its run loop races the whole join_all of dependency-wait futures against its cancel token and drops them on cancellation, so the returned futures don’t each re-check it. A failed dependency surfaces as await_chunk_status returning None.

§Panics

Panics if the target status is not Empty and has no parent, or if the chunk status is invalid during generation.

Source

fn await_light_work_window_and_apply_step( holder: Arc<Self>, step: &'static ChunkStep, chunk_map: Arc<ChunkMap>, cache: Arc<StaticCache2D<Arc<ChunkHolder>>>, thread_pool: Arc<ThreadPool>, light_work_window_gate: Arc<LightWorkWindowGate>, ) -> NeighborReady

Source

fn apply_step_with_light_work_window_reservation( self: &Arc<Self>, step: &'static ChunkStep, chunk_map: &Arc<ChunkMap>, cache: &Arc<StaticCache2D<Arc<ChunkHolder>>>, thread_pool: Arc<ThreadPool>, light_work_window_reservation: Option<LightWorkWindowReservation>, ) -> Option<NeighborReady>

Source

async fn apply_empty_step( holder: Arc<Self>, step: &'static ChunkStep, context: Arc<WorldGenContext>, cache: Arc<StaticCache2D<Arc<ChunkHolder>>>, storage: Arc<ChunkStorage>, thread_pool: Arc<ThreadPool>, ) -> Option<()>

Source

async fn apply_existing_empty_step( holder: &Arc<Self>, target_status: ChunkStatus, context: &Arc<WorldGenContext>, storage: &Arc<ChunkStorage>, thread_pool: &ThreadPool, ) -> Option<bool>

Source

async fn apply_generated_step( holder: Arc<Self>, step: &'static ChunkStep, context: Arc<WorldGenContext>, cache: Arc<StaticCache2D<Arc<ChunkHolder>>>, thread_pool: Arc<ThreadPool>, light_work_window_reservation: Option<LightWorkWindowReservation>, ) -> Option<()>

Source

async fn run_step_task( thread_pool: Arc<ThreadPool>, step: &'static ChunkStep, context: Arc<WorldGenContext>, cache: Arc<StaticCache2D<Arc<ChunkHolder>>>, holder: Arc<Self>, )

Source

fn claim_status_work( self: &Arc<Self>, status: ChunkStatus, ) -> Option<StatusWorkClaim>

Source

fn release_status_work_claim(&self, status: ChunkStatus)

Source

fn mark_status_work_published(&self, status: ChunkStatus)

Source

fn status_work_covers(&self, status: ChunkStatus) -> bool

Source

pub(crate) fn upgrade_to_full(&self)

Upgrades the chunk to a full chunk.

If the chunk is already Full (e.g., loaded from disk), this is a no-op.

§Panics

Panics if no chunk has been installed or Full runtime initialization repeats.

Source

pub(crate) fn post_process_generation( &self, ) -> Result<usize, PostProcessGenerationError>

Runs Full-load post-processing and returns the number of packed positions attempted.

Source

fn finish_generation_status(self: &Arc<Self>, status: ChunkStatus)

Finishes a generated status on the async scheduler after the Rayon task returns.

Source

pub fn insert_chunk(self: &Arc<Self>, chunk: Chunk, status: ChunkStatus)

Inserts a chunk into the holder with a specific status. This notifies watchers - use insert_chunk_no_notify + separate notification if calling from a rayon thread to avoid contention.

§Panics

Panics if status claims Full without initialized Full runtime state, or if initialized Full runtime state is paired with a lower status.

Source

fn store_and_publish_chunk_status(&self, chunk: Chunk, status: ChunkStatus)

Source

fn publish_generated_status(&self, status: ChunkStatus)

Source

fn register_full_chunk_ticks(&self)

Registers tick queues before Full status becomes observable to watchers.

Source

fn publish_full(self: &Arc<Self>)

Source

pub(crate) fn insert_chunk_no_notify(&self, chunk: Chunk)

Inserts a chunk into the holder without notifying watchers. The caller is responsible for notifying via the completion channel.

Source

pub fn wake_all_watchers(&self)

Wakes all await_chunk watchers without changing the chunk result. This allows waiting futures to re-check is_status_disallowed and bail out during chunk unload.

Source

pub fn cancel_generation_task(&self)

Cancels the current generation task.

Source

pub(crate) fn clear_generation_task_if_current( &self, task: &Arc<ChunkGenerationTask>, )

Clears the current generation task if it is still the supplied task.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more