Skip to main content

Module async_bake

Module async_bake 

Source
Expand description

The async GDScript bake contract (CEL-86): pure helpers + the submission queue a crate::builder::CesBuilder hands results back through.

A GDScript builder that defines _bake_requested(requests) is baked ASYNCHRONOUSLY: the planet hands it a batch of chunks each frame and the builder submits surfaces back — from any thread, at any time, any number of times per chunk — via submit_chunk. Submissions land in SubmitQueue, which the planet drains on the main thread into the SAME ready_surfaces map the Rust crate::bake_pool::BakePool fills. Admission gating, coarse ancestor stand-ins and per-frame throttling therefore apply unchanged — they never knew where a surface came from.

Re-submitting an already-resident chunk marks it dirty and re-realizes it, which is exactly the streaming refinement path (a coarse tile now, a finer one when the download lands) with no extra API.

Everything here is pure and unit-tested; the Godot glue lives in builder.rs (the #[func]s) and celestial.rs (drain / request / gate).

Structs§

RawSubmission
A raw submit_chunk payload as GDScript handed it over. Held as plain Vecs (not PackedArrays, which are not Send) so the queue can cross threads. Validated at drain time, where tile_res is known.
Submission
A validated surface. normal == None ⇒ finite-difference it (the planet has the chunk geometry; the builder may not).
SubmitQueue
The mutex-guarded hand-back channel owned by a CesBuilder.

Enums§

SubmitError
Why a submit_chunk payload was rejected.

Constants§

MAX_HANDLE_DEPTH
Deepest chunk depth a handle can encode. ChunkId::path spends 2 bits per level, so depth <= 20 fits the 40 path bits below.
TAG_BITS
Per-planet tag, so two planets sharing one builder .tres cannot have their submissions cross-wired: a planet ignores any handle not bearing its tag.
TAG_MASK
Mask a raw planet tag down to the bits a handle can carry.

Functions§

chunk_dirs
The texel-centre world directions of a chunk, row-major, tile_res² of them.
fd_normals
pack_normals with no builder-supplied normals: pure finite difference.
handle_decode
Unpack a handle, rejecting anything not stamped with tag (a submission meant for a different planet) and anything negative or over-wide.
handle_encode
Pack (tag, id) into the opaque i64 handle GDScript sees. Returns None for a chunk too deep to encode (depth > MAX_HANDLE_DEPTH) — such a chunk is simply never handed to an async builder.
pack_normals
Pack a chunk’s rgba8 world normals: each texel uses over[i] when the builder supplied one, else a curvature-correct finite difference of the height grid — the same construction NoiseProvider uses (the chunk’s edge vectors are projected perpendicular to the radial direction before the height gradient is added along it).
validate_submission
Validate and convert a raw submit_chunk payload.