pub struct BillboardCache {
pub resolution: u32,
pub snapshots: Vec<BillboardSnapshot>,
}Expand description
Per-grid lazy cache of 26 BillboardSnapshots indexed by the
26 canonical_viewpoints directions.
Construction modes:
Self::new_empty: allocate an empty cache, populate later viaSelf::build.Self::build: render all 26 snapshots in one call. Use this from the render-time lazy path: when a grid first lands onLod::Far, the S6.3 dispatch checksGrid::billboards; ifNone, callsbuildand stores.
Fields§
§resolution: u32Snapshot resolution in pixels (square). Pinned at build
time; rebuilds construct a fresh BillboardCache rather
than resizing in place.
snapshots: Vec<BillboardSnapshot>26 snapshots, indexed in the same order as
canonical_viewpoints. Empty (Vec::new) iff this cache
is uninitialised.
Implementations§
Source§impl BillboardCache
impl BillboardCache
Sourcepub fn new_empty(resolution: u32) -> Self
pub fn new_empty(resolution: u32) -> Self
Allocate an empty cache. snapshots is empty; future
Self::build populates it. Cheap — no allocations beyond
the empty Vec header.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of snapshots populated. 0 for an empty cache,
26 after Self::build.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true iff this cache has not yet been populated (no
snapshots stored).
Sourcepub fn build(grid: &Grid, resolution: u32) -> Self
pub fn build(grid: &Grid, resolution: u32) -> Self
Render all 26 viewpoint snapshots of grid into a fresh
cache.
Cost: O(26 × resolution² × grid_render_cost). For
resolution = 128 and a small ship grid this is roughly
equivalent to a single full-frame render. Intended to be
called once per grid-edit cycle (caches are invalidated on
edits via Grid::set_voxel et al.).
An empty grid (no populated chunks) yields 26 all-sky
snapshots. The cache is still populated so the S6.3 blit
path doesn’t keep retrying — a Far-tier empty grid’s blit
is then a no-op (every pixel skipped via SKY_SENTINEL).
Sky-pixel detection: the pool’s skycast colour is set
to SKY_SENTINEL before each snapshot render so opticast
writes the sentinel (not a real sky colour) into pixels
rays missed. Post-render, every sentinel pixel’s depth is
reset to f32::INFINITY (opticast writes a finite “sky
distance” for these pixels, which would otherwise leak
through the blit’s depth check).
Sourcepub fn pick_nearest(&self, query: DVec3) -> Option<&BillboardSnapshot>
pub fn pick_nearest(&self, query: DVec3) -> Option<&BillboardSnapshot>
Pick the snapshot whose view_dir is closest to query
(largest dot product). Returns None iff the cache is
empty.
query is the unit vector from the grid centre to the
current camera position in grid-local space — the same
frame the snapshot view_dirs live in. Caller is
responsible for normalisation.
Tie-breaking is “first in viewpoint order”; with the 26 canonical viewpoints, ties only happen for query directions exactly equidistant between two viewpoints, which is a measure-zero set under f64.
Trait Implementations§
Source§impl Clone for BillboardCache
impl Clone for BillboardCache
Source§fn clone(&self) -> BillboardCache
fn clone(&self) -> BillboardCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BillboardCache
impl RefUnwindSafe for BillboardCache
impl Send for BillboardCache
impl Sync for BillboardCache
impl Unpin for BillboardCache
impl UnsafeUnpin for BillboardCache
impl UnwindSafe for BillboardCache
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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