pub trait CpuSurfaceProvider: Send + Sync {
// Required method
fn bake(
&self,
frame: &FaceFrame,
chunk: &Chunk,
tile_res: u32,
) -> ChunkSurface;
// Provided methods
fn sample_height(&self, _dir: Vector3) -> Option<f32> { ... }
fn poll_refresh(&self) -> Vec<Chunk> { ... }
fn set_wanted(&self, _ids: &HashSet<ChunkId>) { ... }
fn base_ready(&self) -> bool { ... }
fn height_scale(&self) -> f32 { ... }
fn resources_in_flight(&self) -> usize { ... }
fn cache_dir(&self) -> Option<String> { ... }
}Expand description
A source of CPU-baked chunk surfaces (colour/height/normal). Implementors run
on the bake worker pool (bake is called off the main thread,
so it must be Send + Sync and use interior mutability for any shared state).
The other hooks run on the main thread.
Required Methods§
Sourcefn bake(&self, frame: &FaceFrame, chunk: &Chunk, tile_res: u32) -> ChunkSurface
fn bake(&self, frame: &FaceFrame, chunk: &Chunk, tile_res: u32) -> ChunkSurface
Resample this chunk’s surface at tile_res × tile_res. Called on a bake
worker thread. A streaming provider may also enqueue any data it still
needs (a side effect) so poll_refresh can later
report the chunk for a re-bake once that data arrives.
Provided Methods§
Sourcefn sample_height(&self, _dir: Vector3) -> Option<f32>
fn sample_height(&self, _dir: Vector3) -> Option<f32>
Surface displacement at dir, in the height buffer’s unit (multiply by
height_scale · radius for world units). Steers LOD
toward the displaced surface. None ⇒ no data (treated as sea level).
Sourcefn poll_refresh(&self) -> Vec<Chunk>
fn poll_refresh(&self) -> Vec<Chunk>
Chunks whose awaited data has arrived and should be re-baked (streaming).
Called each frame on the main thread; a non-streaming provider returns
empty. Returns whole [Chunk]s (not just ids) so the caller can re-queue
a bake directly.
Sourcefn set_wanted(&self, _ids: &HashSet<ChunkId>)
fn set_wanted(&self, _ids: &HashSet<ChunkId>)
Camera-driven cancellation hint: the set of chunk ids still in view. Streaming providers drop bookkeeping / downloads for anything else.
Sourcefn base_ready(&self) -> bool
fn base_ready(&self) -> bool
Is enough data present for the surface to be shown (the GPU
surface_enabled gate)? A streaming provider returns false until its base
map lands; a self-contained provider (noise) is always ready.
Sourcefn height_scale(&self) -> f32
fn height_scale(&self) -> f32
Per-height-unit displaced-radius factor for the GPU: the surface radius
becomes radius · (1 + height · height_scale).
Sourcefn resources_in_flight(&self) -> usize
fn resources_in_flight(&self) -> usize
External resource fetches in flight (streaming providers; for the HUD).