Skip to main content

Scene

Struct Scene 

Source
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

Source

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

Source

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

Source

pub fn new() -> Self

New empty scene — no grids.

Source

pub fn grid_count(&self) -> usize

Number of grids currently registered.

Source

pub fn add_grid(&mut self, transform: GridTransform) -> GridId

Register a new grid. Returns its fresh, unique GridId.

Source

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.

Source

pub fn grid(&self, id: GridId) -> Option<&Grid>

Borrow a registered grid.

Source

pub fn grid_mut(&mut self, id: GridId) -> Option<&mut Grid>

Mutably borrow a registered grid.

Source

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.

Source

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

Source

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

Source

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

Source

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:

  1. Project the world-space camera into grid-local coords (inverse rotation + origin subtract).
  2. Stream in any chunk whose AABB-to-camera distance is <= r_active, calling Grid::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).
  3. Evict any chunk whose AABB-to-camera distance exceeds r_evict from the grid’s chunk map. Eviction also clears the cached BillboardCache (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 keep r_active small.

Trait Implementations§

Source§

impl Debug for Scene

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Scene

Source§

fn default() -> Scene

Returns the “default value” for a type. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.