pub struct Scene { /* private fields */ }Expand description
Top-level scene container. Holds a flat collection of grids
keyed by GridId.
S2.0 only exposes registration / removal / lookup. Address math helpers (S2.x), edit API (S2.x), and rendering composition (S3) land in later sub-substages.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn to_snapshot(&self) -> SceneSnapshot
pub fn to_snapshot(&self) -> SceneSnapshot
Capture the scene’s full state as a serde-friendly value.
Each chunk is encoded via
roxlap_formats::vxl::serialize; the rest is plain field
data.
Grid iteration order in the produced snapshot is sorted by
GridId so two snapshots of the same scene produce
byte-identical output (the live HashMap iteration order
would be non-deterministic).
Sourcepub fn from_snapshot(snap: &SceneSnapshot) -> Result<Self, FromSnapshotError>
pub fn from_snapshot(snap: &SceneSnapshot) -> Result<Self, FromSnapshotError>
Restore a Scene from a snapshot. Each chunk’s bytes are
re-parsed via roxlap_formats::vxl::parse and re-armed
for edits via roxlap_formats::vxl::Vxl::reserve_edit_capacity.
§Errors
Returns FromSnapshotError::ChunkParse tagged with the
owning grid + chunk index if any chunk’s bytes fail to
parse. The partial scene is dropped — restoration is
all-or-nothing.
Source§impl Scene
impl Scene
Sourcepub fn grid_count(&self) -> usize
pub fn grid_count(&self) -> usize
Number of grids currently registered.
Sourcepub fn add_grid(&mut self, transform: GridTransform) -> GridId
pub fn add_grid(&mut self, transform: GridTransform) -> GridId
Register a new grid. Returns its fresh, unique GridId.
Sourcepub fn remove_grid(&mut self, id: GridId) -> Option<Grid>
pub fn remove_grid(&mut self, id: GridId) -> Option<Grid>
Remove a grid by id. Returns the removed Grid (so the
caller can reclaim its chunks) or None if the id wasn’t
registered. Removed ids are not reissued.
Sourcepub fn grids(&self) -> impl Iterator<Item = (GridId, &Grid)>
pub fn grids(&self) -> impl Iterator<Item = (GridId, &Grid)>
Iterator over all (id, grid) pairs in registration order
is not guaranteed — the underlying map is a HashMap.
Callers that need a stable order must sort by GridId.
Sourcepub fn grids_mut(&mut self) -> impl Iterator<Item = (GridId, &mut Grid)>
pub fn grids_mut(&mut self) -> impl Iterator<Item = (GridId, &mut Grid)>
Mutable iterator over all (id, grid) pairs. Yield order
is not guaranteed (HashMap-backed).
Sourcepub fn set_streaming_threads(&mut self, n: usize)
pub fn set_streaming_threads(&mut self, n: usize)
Configure the number of worker threads in the dedicated streaming pool (S7.3).
Lazily applied — the pool itself is constructed on the first
Self::pump_streaming call. If the pool was already built
(i.e. a previous pump_streaming already dispatched at
least one task), it gets dropped and rebuilt. Dropping the
old pool blocks until all of its in-flight tasks finish
(rayon’s contract); any results those tasks sent are still
drained by the next pump_streaming because the channel
survives the rebuild.
The streaming pool is separate from rayon’s global pool (which R12 multicore rendering uses), so chunk generation doesn’t compete with render threads. Sensible values are 1 to ~4 — generation work is CPU-bound but should leave most of the box for everything else.
On wasm32 this is a no-op (no rayon pool available);
pump_streaming runs synchronously there.
§Panics
Panics on native if n == 0 (zero-thread pools are not
supported; the scene crate’s S7.1 helper already disallows
the equivalent for StreamRadius::r_active < 0).
Sourcepub fn pump_streaming(&mut self, camera_world_pos: DVec3)
pub fn pump_streaming(&mut self, camera_world_pos: DVec3)
Asynchronous streaming pump (S7.3).
On native, dispatches missing-chunk generations onto a
dedicated rayon pool, drains any results that arrived since
the last pump, runs the eviction pass, and tracks in-flight
tasks in each grid’s Grid::pending_gen set. The drain
uses the per-chunk version counter from S7.2 to discard
results whose chunk was edited mid-generation.
On wasm32 this short-circuits to Self::pump_streaming_sync
— no thread pool is available there, but the same per-grid
stream-in / evict semantics apply.
Call once per frame from the render thread. Cheap when nothing changed (early-exit on disabled grids, try_recv loops empty fast).
Sourcepub fn pump_streaming_sync(&mut self, camera_world_pos: DVec3)
pub fn pump_streaming_sync(&mut self, camera_world_pos: DVec3)
Synchronous streaming pump (S7.1).
For each grid with a non-StreamRadius::DISABLED policy:
- Project the world-space camera into grid-local coords (inverse rotation + origin subtract).
- Stream in any chunk whose AABB-to-camera distance is
<= r_active, callingGrid::ensure_chunk_generated. No-ops gracefully if the grid has no generator attached (so callers can use the eviction half of streaming on a purely-edited grid). - Evict any chunk whose AABB-to-camera distance exceeds
r_evictfrom the grid’s chunk map. Eviction also clears the cachedBillboardCache(the bounding sphere may shrink, invalidating impostor projections; the next Far-tier render rebuilds lazily).
Both passes use the f64 grid-local position so rotation
- non-axis-aligned grids stream and evict correctly. The
generate path is blocking — S7.3 will move it to a
background rayon pool with
pump_streaming(non-blocking). Callers that want the async variant in S7.0/S7.1 stages should keepr_activesmall.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scene
impl !RefUnwindSafe for Scene
impl Send for Scene
impl Sync for Scene
impl Unpin for Scene
impl UnsafeUnpin for Scene
impl !UnwindSafe for Scene
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
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 more