pub struct BakePool { /* private fields */ }Expand description
Worker pool resampling chunk surfaces off the main thread.
Implementations§
Source§impl BakePool
impl BakePool
Sourcepub fn new(
provider: Arc<dyn CpuSurfaceProvider>,
tile_res: u32,
n_workers: usize,
result_cap: usize,
) -> Self
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]”.
Sourcepub fn set_provider(&mut self, provider: Arc<dyn CpuSurfaceProvider>)
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.
Sourcepub fn set_wanted(&self, ids: HashSet<ChunkId>)
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.
Sourcepub fn request(&mut self, frame: &FaceFrame, chunk: &Chunk)
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.
Sourcepub fn generation(&self) -> u64
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.
Sourcepub fn in_flight_len(&self) -> usize
pub fn in_flight_len(&self) -> usize
Number of queued/running bakes (backpressure signal).
Sourcepub fn poll(&mut self) -> Vec<BakeResult>
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.