pub struct ChunkGenerationTask {
pub chunk_map: Arc<ChunkMap>,
pub pos: ChunkPos,
pub target_status: ChunkStatus,
pub scheduled_status: SyncMutex<Option<ChunkStatus>>,
pub cancel_token: CancellationToken,
cancelled: AtomicBool,
pub neighbor_ready: SyncMutex<Vec<NeighborReady>>,
pub cache: Arc<StaticCache2D<Arc<ChunkHolder>>>,
pub center_holder: Arc<ChunkHolder>,
pub needs_generation: AtomicBool,
pub thread_pool: Arc<ThreadPool>,
}Expand description
A task responsible for driving a chunk to a target status.
It works in form of layers. Imagine a pyramid, to get to the top you first need to generate the base layer. And so on. This works in the same way but with chunk dependencies.
This is achieved using the Generation Pyramid and Loading Pyramid.
To make sure a chunk is only put through a stage once it uses an atomic with a CAS operation. Loading Pyramid must also be advanced with noop functions so this atomic can be driven forward.
Fields§
§chunk_map: Arc<ChunkMap>The chunk map associated with this task.
pos: ChunkPosThe chunk position.
target_status: ChunkStatusThe target generation status.
scheduled_status: SyncMutex<Option<ChunkStatus>>The status scheduled for generation. Protected by a mutex for safe concurrent access.
cancel_token: CancellationTokenCancellation token — cancelled when this task should stop.
cancelled: AtomicBoolCheap cancellation flag for scheduler-side filtering.
neighbor_ready: SyncMutex<Vec<NeighborReady>>Futures for neighbors. Protected by a mutex.
cache: Arc<StaticCache2D<Arc<ChunkHolder>>>Cache of required chunks.
center_holder: Arc<ChunkHolder>Holder for the chunk this task is targeting.
needs_generation: AtomicBoolWhether generation is required for this task.
thread_pool: Arc<ThreadPool>The thread pool to use for generation.
Implementations§
Source§impl ChunkGenerationTask
impl ChunkGenerationTask
Sourcepub fn new(
pos: ChunkPos,
target_status: ChunkStatus,
chunk_map: Arc<ChunkMap>,
thread_pool: Arc<ThreadPool>,
cancel_token: CancellationToken,
) -> Self
pub fn new( pos: ChunkPos, target_status: ChunkStatus, chunk_map: Arc<ChunkMap>, thread_pool: Arc<ThreadPool>, cancel_token: CancellationToken, ) -> Self
Creates a new generation task.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns whether this task has been explicitly cancelled.
Sourcepub(crate) const fn center_holder(&self) -> &Arc<ChunkHolder> ⓘ
pub(crate) const fn center_holder(&self) -> &Arc<ChunkHolder> ⓘ
Returns the holder for the chunk this task is targeting.
Sourcepub fn schedule_chunk_in_layer(
&self,
status: ChunkStatus,
needs_generation: bool,
chunk_holder: &Arc<ChunkHolder>,
) -> bool
pub fn schedule_chunk_in_layer( &self, status: ChunkStatus, needs_generation: bool, chunk_holder: &Arc<ChunkHolder>, ) -> bool
Sourcepub fn schedule_layer(&self, status: ChunkStatus, needs_generation: bool)
pub fn schedule_layer(&self, status: ChunkStatus, needs_generation: bool)
Schedules tasks for the current layer’s neighbors.
const fn get_radius_for_layer( &self, status: ChunkStatus, needs_generation: bool, ) -> i32
Sourcepub fn schedule_next_layer(&self)
pub fn schedule_next_layer(&self)
fn can_load_without_generation(&self) -> bool
Sourcepub async fn wait_for_scheduled_layers(&self)
pub async fn wait_for_scheduled_layers(&self)
Waits for all scheduled neighbor tasks to complete.
Auto Trait Implementations§
impl !Freeze for ChunkGenerationTask
impl !RefUnwindSafe for ChunkGenerationTask
impl !UnwindSafe for ChunkGenerationTask
impl Send for ChunkGenerationTask
impl Sync for ChunkGenerationTask
impl Unpin for ChunkGenerationTask
impl UnsafeUnpin for ChunkGenerationTask
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<>>