pub enum PalettedContainer<V: Hash + Eq + Copy + Default, const DIM: usize> {
Homogeneous(V),
Heterogeneous(HeterogeneousPalette<V, DIM>),
Building(Box<[[[V; DIM]; DIM]; DIM]>),
}Expand description
A paletted container.
Building is a transient mode used during worldgen: it’s a raw cube without
palette tracking, so writes are O(1) stores. Must be finalized via
Self::finalize_building (or implicitly when the parent section recalculates
its counters) before any serialization or paletted access. Mirrors
FastNoise’s FastChunkSection write-only fill mode.
Variants§
Homogeneous(V)
A homogeneous container, where all values are the same.
Heterogeneous(HeterogeneousPalette<V, DIM>)
A heterogeneous container, where values can be different.
Building(Box<[[[V; DIM]; DIM]; DIM]>)
Write-only build mode: raw cube without palette tracking.
set is a single store; get is a direct read.
Convert back via Self::finalize_building.
Implementations§
Source§impl<V: Hash + Eq + Copy + Default + Debug, const DIM: usize> PalettedContainer<V, DIM>
impl<V: Hash + Eq + Copy + Default + Debug, const DIM: usize> PalettedContainer<V, DIM>
Sourcepub fn from_cube(cube: Box<[[[V; DIM]; DIM]; DIM]>) -> Self
pub fn from_cube(cube: Box<[[[V; DIM]; DIM]; DIM]>) -> Self
Creates a PalettedContainer from a pre-built cube.
Will automatically determine if the result should be homogeneous or heterogeneous.
Walks the cube as a flat slice (it’s [[[V; DIM]; DIM]; DIM] so memory
is contiguous) and counts identical cells in runs. The inner “find run
end” loop is a vectorizable equality scan, so long stone columns collapse
to a single palette increment.
Sourcepub fn get_at_index(&self, index: usize) -> V
pub fn get_at_index(&self, index: usize) -> V
Gets the value at a y,z,x linear index.
The index layout is x + z * DIM + y * DIM * DIM, matching the flat
order used when serializing palette data and by ScalableLux light propagation.
Sourcepub(crate) fn copy_column_into(&self, x: usize, z: usize, out: &mut [V])
pub(crate) fn copy_column_into(&self, x: usize, z: usize, out: &mut [V])
Copies the full vertical column at (x, z) into out.
Sourcepub fn maybe_has(&self, predicate: impl FnMut(V) -> bool) -> bool
pub fn maybe_has(&self, predicate: impl FnMut(V) -> bool) -> bool
Returns whether this container’s palette may contain a matching value.
This checks palette entries instead of every cell, matching vanilla and
ScalableLux’s fast pre-scan before doing a full section pass.
Sourcepub fn collect_values(&self) -> Vec<V>
pub fn collect_values(&self) -> Vec<V>
Collects all values in the container in y, z, x order.
Sourcepub fn enter_building_mode(&mut self)
pub fn enter_building_mode(&mut self)
Switches the container into write-only build mode for fast bulk writes.
Idempotent: a no-op if already in Self::Building.
Allocates a Cube if currently Homogeneous. For Heterogeneous it
reuses the existing cube allocation.
Sourcepub fn as_building_slice_mut(&mut self) -> Option<&mut [V]>
pub fn as_building_slice_mut(&mut self) -> Option<&mut [V]>
Returns the raw cube backing this container as a flat mutable slice if
it’s currently in Self::Building mode. Indexing is [y * DIM*DIM + z * DIM + x].
Used by the chunk fill path to bypass the 3-arm set dispatch and the
unused old-value load — write-only worldgen never reads back what it
just wrote, so the read in set is wasted memory traffic.
Sourcepub fn finalize_building(&mut self)
pub fn finalize_building(&mut self)
Finalizes a Self::Building container back to Homogeneous or
Heterogeneous by scanning the cube once and constructing the palette.
No-op if not in build mode.
Sourcepub fn set(&mut self, x: usize, y: usize, z: usize, value: V) -> V
pub fn set(&mut self, x: usize, y: usize, z: usize, value: V) -> V
Sets the value at the given coordinates.
fn calculate_strategy(count: usize) -> (u8, PaletteMode)
Source§impl PalettedContainer<BlockStateId, 16>
impl PalettedContainer<BlockStateId, 16>
Sourcepub fn non_empty_block_count(&self) -> u16
pub fn non_empty_block_count(&self) -> u16
Gets the number of non-empty blocks in the container.
Sourcepub fn has_only_air(&self) -> bool
pub fn has_only_air(&self) -> bool
Returns true if this palette contains only air blocks.
Trait Implementations§
Source§impl<V: Clone + Hash + Eq + Copy + Default, const DIM: usize> Clone for PalettedContainer<V, DIM>
impl<V: Clone + Hash + Eq + Copy + Default, const DIM: usize> Clone for PalettedContainer<V, DIM>
Source§fn clone(&self) -> PalettedContainer<V, DIM>
fn clone(&self) -> PalettedContainer<V, DIM>
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<V, const DIM: usize> Freeze for PalettedContainer<V, DIM>where
V: Freeze,
impl<V, const DIM: usize> RefUnwindSafe for PalettedContainer<V, DIM>where
V: RefUnwindSafe,
impl<V, const DIM: usize> Send for PalettedContainer<V, DIM>where
V: Send,
impl<V, const DIM: usize> Sync for PalettedContainer<V, DIM>where
V: Sync,
impl<V, const DIM: usize> Unpin for PalettedContainer<V, DIM>where
V: Unpin,
impl<V, const DIM: usize> UnsafeUnpin for PalettedContainer<V, DIM>where
V: UnsafeUnpin,
impl<V, const DIM: usize> UnwindSafe for PalettedContainer<V, DIM>where
V: UnwindSafe,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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 moreArc<SyncMutex<>>