Skip to main content

BakePool

Struct BakePool 

Source
pub struct BakePool { /* private fields */ }
Expand description

Worker pool resampling chunk surfaces off the main thread.

Implementations§

Source§

impl BakePool

Source

pub fn new( provider: Arc<dyn CpuSurfaceProvider>, tile_res: u32, n_workers: usize, result_cap: usize, ) -> Self

Spawn n_workers baking tile_res × tile_res surfaces via provider.

result_cap bounds the number of FINISHED-but-undrained results held on the heap (each one a full ChunkSurface); pass the caller’s in-flight bound. 0 means “use [DEFAULT_RESULT_CAP]”.

Source

pub fn set_provider(&mut self, provider: Arc<dyn CpuSurfaceProvider>)

Install a fresh provider (e.g. after a live editor param edit) and open a new GENERATION. Combine with a cache invalidate_all + clearing any ready surfaces so every chunk re-bakes with the new params.

Bumping the generation is what makes a live edit atomic across the planet. Without it, the bakes ALREADY RUNNING when the edit lands finish against the OLD params and are applied anyway, so those chunks keep old-param terrain (e.g. the old water_height) while every other chunk shows the new value — the planet ends up remembering two different values at once. Releasing in_flight matters just as much: otherwise request’s dedup sees those chunks as still pending and SILENTLY SKIPS their re-bake, so they are never refreshed at all.

Source

pub fn set_wanted(&self, ids: HashSet<ChunkId>)

Replace the wanted-chunk set (the current cut) workers use to cancel stale queued bakes. None initial state means everything is wanted.

Source

pub fn request(&mut self, frame: &FaceFrame, chunk: &Chunk)

Queue a bake for chunk unless one is already queued/running. The job is stamped with the CURRENT generation (its “request time”): if a param edit lands before the result comes back, poll rejects it.

Source

pub fn generation(&self) -> u64

The current generation (bumped by every set_provider). The planet stamps its own per-chunk bookkeeping (ready surfaces) with this so a surface can also be rejected at RENDER time, not just on arrival.

Source

pub fn in_flight(&self, id: ChunkId) -> bool

Is a bake for id queued or running?

Source

pub fn in_flight_len(&self) -> usize

Number of queued/running bakes (backpressure signal).

Source

pub fn poll(&mut self) -> Vec<BakeResult>

Drain completed bakes non-blocking.

Results whose REQUEST predates the current generation (a param edit has landed since they were queued) are DROPPED, never handed back. The chunk was already released from in_flight by [set_provider], so the caller’s re-request re-bakes it with the current params.

Trait Implementations§

Source§

impl Drop for BakePool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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.

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, 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.