Struct all_is_cubes::space::Space [−][src]
pub struct Space { /* fields omitted */ }
Expand description
Container for Block
s arranged in three-dimensional space. The main “game world”
data structure.
Implementations
Methods on Space that specifically implement the lighting algorithm.
Clear and recompute light data and update queue, in a way which gets fast approximate results suitable for flat landscapes mostly lit from above (the +Y axis).
TODO: Revisit whether this is a good public API.
Returns a SpaceBuilder
configured for a block,
which may be used to construct a new Space
.
This means that its bounds are as per Grid::for_block()
, and its
physics
is SpacePhysics::DEFAULT_FOR_BLOCK
.
Returns a SpaceBuilder
with the given grid and all default values,
which may be used to construct a new Space
.
Constructs a Space
that is entirely empty and whose coordinate system
is in the +X+Y+Z octant. This is a shorthand intended mainly for tests.
Registers a listener for mutations of this space.
Returns the Grid
describing the bounds of this space; no blocks may exist
outside it.
Returns the internal unstable numeric ID for the block at the given position,
which may be mapped to a Block
by Space::block_data
.
If you are looking for simple access, use space[position]
(the
std::ops::Index
trait) instead.
These IDs may be used to perform efficient processing of many blocks, but they may be renumbered after any mutation.
pub fn extract<V>(
&self,
subgrid: Grid,
extractor: impl FnMut(Option<BlockIndex>, &SpaceBlockData, PackedLight) -> V
) -> GridArray<V>
pub fn extract<V>(
&self,
subgrid: Grid,
extractor: impl FnMut(Option<BlockIndex>, &SpaceBlockData, PackedLight) -> V
) -> GridArray<V>
Copy data out of a portion of the space in a caller-chosen format.
If the provided Grid
contains portions outside of this space’s grid,
those positions in the output will be treated as if they are filled with AIR
and lit by SpacePhysics::sky_color
.
Gets the EvaluatedBlock
of the block in this space at the given position.
Returns the light occupying the given cube.
This value may be considered as representing the average of the light reflecting off of all surfaces within, or immediately adjacent to and facing toward, this cube. If there are no such surfaces, or if the given position is out of bounds, the result is arbitrary. If the position is within an opaque block, the result is black.
Lighting is updated asynchronously after modifications, so all above claims about the meaning of this value are actually “will eventually be, if no more changes are made”.
Replace the block in this space at the given position.
If the position is out of bounds, there is no effect.
use all_is_cubes::block::*;
use all_is_cubes::math::Rgba;
use all_is_cubes::space::Space;
let mut space = Space::empty_positive(1, 1, 1);
let a_block = Block::builder().color(Rgba::new(1.0, 0.0, 0.0, 1.0)).build();
space.set((0, 0, 0), &a_block);
assert_eq!(space[(0, 0, 0)], a_block);
Replace blocks in region
with a block computed by the function.
The function may return a reference to a block or a block. If it returns None
,
the existing block is left unchanged.
The operation will stop on the first error, potentially leaving some blocks
replaced. (Exception: If the grid
extends outside of
self.grid()
, that will always be rejected before any changes are
made.)
use all_is_cubes::block::{AIR, Block};
use all_is_cubes::math::Rgba;
use all_is_cubes::space::{Grid, Space};
let mut space = Space::empty_positive(10, 10, 10);
let a_block: Block = Rgba::new(1.0, 0.0, 0.0, 1.0).into();
space.fill(Grid::new((0, 0, 0), (2, 1, 1)), |_point| Some(&a_block)).unwrap();
assert_eq!(space[(0, 0, 0)], a_block);
assert_eq!(space[(1, 0, 0)], a_block);
assert_eq!(space[(0, 1, 0)], AIR);
TODO: Support providing the previous block as a parameter (take cues from extract
).
See also Space::fill_uniform
for filling a region with one block.
pub fn fill_uniform<'b>(
&mut self,
region: Grid,
block: impl Into<Cow<'b, Block>>
) -> Result<(), SetCubeError>
pub fn fill_uniform<'b>(
&mut self,
region: Grid,
block: impl Into<Cow<'b, Block>>
) -> Result<(), SetCubeError>
Replace blocks in region
with the given block.
TODO: Document error behavior
use all_is_cubes::block::{AIR, Block};
use all_is_cubes::math::Rgba;
use all_is_cubes::space::{Grid, Space};
let mut space = Space::empty_positive(10, 10, 10);
let a_block: Block = Rgba::new(1.0, 0.0, 0.0, 1.0).into();
space.fill_uniform(Grid::new((0, 0, 0), (2, 1, 1)), &a_block).unwrap();
assert_eq!(&space[(0, 0, 0)], &a_block);
assert_eq!(&space[(1, 0, 0)], &a_block);
assert_eq!(&space[(0, 1, 0)], &AIR);
See also Space::fill
for non-uniform fill and bulk copies.
Provides an DrawTarget
adapter for 2.5D drawing.
For more information on how to use this, see
all_is_cubes::drawing
.
Returns all distinct block types found in the space.
TODO: This was invented for testing the indexing of blocks and should be replaced with something else if it only gets used for testing.
Returns data about all the blocks assigned internal IDs (indices) in the space, as well as placeholder data for any deallocated indices.
The indices of this slice correspond to the results of Space::get_block_index
.
pub fn step(
&mut self,
self_ref: Option<&URef<Space>>,
tick: Tick
) -> (SpaceStepInfo, UniverseTransaction)
pub fn step(
&mut self,
self_ref: Option<&URef<Space>>,
tick: Tick
) -> (SpaceStepInfo, UniverseTransaction)
Advance time in the space.
pub fn evaluate_light(
&mut self,
epsilon: u8,
progress_callback: impl FnMut(LightUpdatesInfo)
) -> usize
pub fn evaluate_light(
&mut self,
epsilon: u8,
progress_callback: impl FnMut(LightUpdatesInfo)
) -> usize
Perform lighting updates until there are none left to do. Returns the number of updates performed.
This may take a while. It is appropriate for when the goal is to render a fully lit scene non-interactively.
epsilon
specifies a threshold at which to stop doing updates.
Zero means to run to full completion; one is the smallest unit of light level
difference; and so on.
Returns the current SpacePhysics
data, which determines global characteristics
such as the behavior of light and gravity.
Sets the physics parameters, as per physics
.
This may cause recomputation of lighting.
Trait Implementations
Gets a reference to the block in this space at the given position.
If the position is out of bounds, returns AIR
.
Note that Space
does not implement IndexMut
;
use Space::set
or Space::fill
to modify blocks.
type CommitCheck = <BehaviorSetTransaction<Space> as Transaction<BehaviorSet<Space>>>::CommitCheck
type CommitCheck = <BehaviorSetTransaction<Space> as Transaction<BehaviorSet<Space>>>::CommitCheck
Type of a value passed from Transaction::check
to Transaction::commit
.
This may be used to pass precalculated values to speed up the commit phase,
or even lock guards or similar, but also makes it slightly harder to accidentally
call commit
without check
. Read more
The result of a Transaction::commit()
or Transaction::execute()
. Read more
Perform the mutations specified by this transaction. The check
value should have
been created by a prior call to Transaction::commit
. Read more
Convenience method to execute a transaction in one step. Implementations should not need to override this. Equivalent to: Read more
fn bind(self, target: URef<T>) -> UniverseTransaction where
Self: Sized,
T: UTransactional<Transaction = Self>,
fn bind(self, target: URef<T>) -> UniverseTransaction where
Self: Sized,
T: UTransactional<Transaction = Self>,
type Transaction = SpaceTransaction
Inserts a new object with a specific name. Read more
fn iter_by_type(&self) -> UniverseIter<'_, Space>ⓘNotable traits for UniverseIter<'u, T>impl<'u, T> Iterator for UniverseIter<'u, T> type Item = (Name, URef<T>);
fn iter_by_type(&self) -> UniverseIter<'_, Space>ⓘNotable traits for UniverseIter<'u, T>impl<'u, T> Iterator for UniverseIter<'u, T> type Item = (Name, URef<T>);
impl<'u, T> Iterator for UniverseIter<'u, T> type Item = (Name, URef<T>);
Iterate over all of the objects of type T
.
Note that this includes anonymous objects. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Space
impl !UnwindSafe for Space
Blanket Implementations
Mutably borrows from an owned value. Read more
Casts the value.
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
Casts the value.
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
Casts the value.
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
Casts the value.
pub fn vzip(self) -> V
Casts the value.