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: AtomicU8The current loading ticket level of the chunk.
simulation_level: AtomicU8The current simulation ticket level of the chunk.
started_work: AtomicUsizeThe highest status that has started work.
active_save_dependencies: AtomicUsizeNumber of save dependencies that have not completed yet.
save_lifecycle: AtomicU8Coordinates unloading revival with the short immutable save-preparation phase.
highest_allowed_status: AtomicU8The highest status that generation is allowed to reach.
min_y: i32The minimum Y coordinate of the world.
height: i32The total height of the world.
has_changed_sections: AtomicBoolWhether any sections have pending block changes.
queued_for_broadcast: AtomicBoolWhether this holder is already queued for the next broadcast flush.
packet_content_revision: AtomicU64Monotonic revision for client-visible chunk packet content.
ticking_readiness: AtomicU64Packed ticking readiness generation. The low two bits store TickingReadiness.
full_status_initialized: AtomicBoolWhether 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
impl ChunkHolder
Sourcepub fn new(
pos: ChunkPos,
load_level: ChunkTicketLevel,
simulation_level: Option<ChunkTicketLevel>,
min_y: i32,
height: i32,
) -> Self
pub fn new( pos: ChunkPos, load_level: ChunkTicketLevel, simulation_level: Option<ChunkTicketLevel>, min_y: i32, height: i32, ) -> Self
Creates a new chunk holder.
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
Sourcepub fn load_level(&self) -> Option<ChunkTicketLevel>
pub fn load_level(&self) -> Option<ChunkTicketLevel>
Returns the current load ticket level.
Sourcepub(crate) fn swap_load_level(
&self,
level: ChunkTicketLevel,
) -> Option<ChunkTicketLevel>
pub(crate) fn swap_load_level( &self, level: ChunkTicketLevel, ) -> Option<ChunkTicketLevel>
Stores the current load ticket level and returns the previous level.
Sourcepub(crate) fn clear_load_level(&self)
pub(crate) fn clear_load_level(&self)
Clears the current load ticket level.
Sourcepub fn simulation_level(&self) -> Option<ChunkTicketLevel>
pub fn simulation_level(&self) -> Option<ChunkTicketLevel>
Returns the current simulation ticket level.
Sourcepub(crate) fn set_simulation_level(&self, level: Option<ChunkTicketLevel>)
pub(crate) fn set_simulation_level(&self, level: Option<ChunkTicketLevel>)
Stores the current simulation ticket level.
pub(crate) fn entity_visibility(&self) -> EntityVisibility
Sourcepub fn update_highest_allowed_status(
&self,
ticket_level: Option<ChunkTicketLevel>,
)
pub fn update_highest_allowed_status( &self, ticket_level: Option<ChunkTicketLevel>, )
Updates the highest allowed generation status based on the ticket level.
Sourcepub fn block_changed(&self, pos: BlockPos) -> bool
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).
Sourcepub fn light_changed(&self, layer: LightLayer, section_pos: SectionPos) -> bool
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.
Sourcepub fn mark_light_section_dirty(&self, section_pos: SectionPos) -> bool
pub fn mark_light_section_dirty(&self, section_pos: SectionPos) -> bool
Marks saved light data dirty without queuing client-visible changes.
fn mark_valid_light_section_dirty( &self, section_pos: SectionPos, ) -> Option<bool>
Sourcepub fn has_changes_to_broadcast(&self) -> bool
pub fn has_changes_to_broadcast(&self) -> bool
Returns whether there are pending changes to broadcast.
Sourcepub fn clear_broadcast_queued(&self)
pub fn clear_broadcast_queued(&self)
Allows later changes to enqueue this holder for a future broadcast.
Sourcepub fn take_changed_blocks(
&self,
) -> Vec<(usize, FxHashSet<PackedSectionBlockPos>)>
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).
Sourcepub fn take_changed_light_sections(&self) -> ChangedLightSections
pub fn take_changed_light_sections(&self) -> ChangedLightSections
Takes all pending light-section changes.
Sourcepub fn mark_packet_content_changed(&self)
pub fn mark_packet_content_changed(&self)
Marks the holder’s client-visible chunk packet content as changed.
Sourcepub fn packet_content_revision(&self) -> u64
pub fn packet_content_revision(&self) -> u64
Returns the current client-visible content revision.
pub(crate) fn ticking_readiness_snapshot(&self) -> TickingReadinessSnapshot
pub(crate) fn is_full_status_initialized(&self) -> bool
pub(crate) fn transition_ticking_readiness( &self, target: TickingReadiness, ) -> Option<TickingReadiness>
Sourcepub fn section_count(&self) -> usize
pub fn section_count(&self) -> usize
Returns the number of sections in this chunk.
Sourcepub fn is_status_disallowed(&self, status: ChunkStatus) -> bool
pub fn is_status_disallowed(&self, status: ChunkStatus) -> bool
Checks if the given status is disallowed.
Sourcepub(crate) fn schedule_chunk_generation_task_b(
&self,
status: ChunkStatus,
chunk_map: &Arc<ChunkMap>,
) -> bool
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.
Sourcepub(crate) fn reschedule_chunk_task_b(
&self,
status: ChunkStatus,
chunk_map: &Arc<ChunkMap>,
)
pub(crate) fn reschedule_chunk_task_b( &self, status: ChunkStatus, chunk_map: &Arc<ChunkMap>, )
Reschedules the chunk task to the given status.
Sourcepub fn try_chunk(&self, status: ChunkStatus) -> Option<&Chunk>
pub fn try_chunk(&self, status: ChunkStatus) -> Option<&Chunk>
Gets access to the chunk if it has reached the given status.
Sourcepub fn try_full_chunk(&self) -> Option<FullChunkRef<'_>>
pub fn try_full_chunk(&self) -> Option<FullChunkRef<'_>>
Gets the Full-only capability after Full status is published.
Sourcepub async fn await_chunk(&self, status: ChunkStatus) -> Option<&Chunk>
pub async fn await_chunk(&self, status: ChunkStatus) -> Option<&Chunk>
Waits until the chunk has reached the given status.
Sourcepub async fn await_chunk_status(
&self,
status: ChunkStatus,
) -> Option<ChunkStatus>
pub async fn await_chunk_status( &self, status: ChunkStatus, ) -> Option<ChunkStatus>
Waits until the chunk has reached the given status without reading chunk data.
async fn await_claimed_chunk_status( &self, status: ChunkStatus, ) -> Option<ChunkStatus>
Sourcepub fn published_status(&self) -> Option<ChunkStatus>
pub fn published_status(&self) -> Option<ChunkStatus>
Gets the published status of the chunk.
Sourcepub fn is_ready_for_saving(&self) -> bool
pub fn is_ready_for_saving(&self) -> bool
Returns whether vanilla timed tickets may age for this chunk.
pub(crate) fn add_save_dependency(self: &Arc<Self>) -> ChunkSaveDependency
Sourcepub(crate) fn begin_unloading(&self)
pub(crate) fn begin_unloading(&self)
Moves an active holder into the unloading lifecycle.
Sourcepub(crate) fn try_begin_save_preparation(
self: &Arc<Self>,
) -> Option<ChunkSavePreparationGuard>
pub(crate) fn try_begin_save_preparation( self: &Arc<Self>, ) -> Option<ChunkSavePreparationGuard>
Reserves the unloading holder while its immutable save input is assembled.
Sourcepub(crate) fn try_revive_from_unloading(&self) -> bool
pub(crate) fn try_revive_from_unloading(&self) -> bool
Attempts to reactivate an unloading holder without waiting for save preparation.
Sourcepub fn apply_step(
self: &Arc<Self>,
step: &'static ChunkStep,
chunk_map: &Arc<ChunkMap>,
cache: &Arc<StaticCache2D<Arc<ChunkHolder>>>,
thread_pool: Arc<ThreadPool>,
) -> Option<NeighborReady>
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.
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
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>
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<()>
async fn apply_existing_empty_step( holder: &Arc<Self>, target_status: ChunkStatus, context: &Arc<WorldGenContext>, storage: &Arc<ChunkStorage>, thread_pool: &ThreadPool, ) -> Option<bool>
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<()>
async fn run_step_task( thread_pool: Arc<ThreadPool>, step: &'static ChunkStep, context: Arc<WorldGenContext>, cache: Arc<StaticCache2D<Arc<ChunkHolder>>>, holder: Arc<Self>, )
fn claim_status_work( self: &Arc<Self>, status: ChunkStatus, ) -> Option<StatusWorkClaim>
fn release_status_work_claim(&self, status: ChunkStatus)
fn mark_status_work_published(&self, status: ChunkStatus)
fn status_work_covers(&self, status: ChunkStatus) -> bool
Sourcepub(crate) fn upgrade_to_full(&self)
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.
Sourcepub(crate) fn post_process_generation(
&self,
) -> Result<usize, PostProcessGenerationError>
pub(crate) fn post_process_generation( &self, ) -> Result<usize, PostProcessGenerationError>
Runs Full-load post-processing and returns the number of packed positions attempted.
Sourcefn finish_generation_status(self: &Arc<Self>, status: ChunkStatus)
fn finish_generation_status(self: &Arc<Self>, status: ChunkStatus)
Finishes a generated status on the async scheduler after the Rayon task returns.
Sourcepub fn insert_chunk(self: &Arc<Self>, chunk: Chunk, status: ChunkStatus)
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.
fn store_and_publish_chunk_status(&self, chunk: Chunk, status: ChunkStatus)
fn publish_generated_status(&self, status: ChunkStatus)
Sourcefn register_full_chunk_ticks(&self)
fn register_full_chunk_ticks(&self)
Registers tick queues before Full status becomes observable to watchers.
fn publish_full(self: &Arc<Self>)
Sourcepub(crate) fn insert_chunk_no_notify(&self, chunk: Chunk)
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.
Sourcepub fn wake_all_watchers(&self)
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.
Sourcepub fn cancel_generation_task(&self)
pub fn cancel_generation_task(&self)
Cancels the current generation task.
Sourcepub(crate) fn clear_generation_task_if_current(
&self,
task: &Arc<ChunkGenerationTask>,
)
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§
impl !Freeze for ChunkHolder
impl !RefUnwindSafe for ChunkHolder
impl !UnwindSafe for ChunkHolder
impl Send for ChunkHolder
impl Sync for ChunkHolder
impl Unpin for ChunkHolder
impl UnsafeUnpin for ChunkHolder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>