pub struct Mutation<'m, 'space> { /* private fields */ }Expand description
Access to a Space’s contents to perform several modifications.
Obtain this using Space::mutate().
Implementations§
Source§impl<'space> Mutation<'_, 'space>
impl<'space> Mutation<'_, 'space>
Sourcepub fn bounds(&self) -> GridAab
pub fn bounds(&self) -> GridAab
Same as Space::bounds().
Sourcepub fn get_evaluated(&self, position: impl Into<Cube>) -> &EvaluatedBlock
pub fn get_evaluated(&self, position: impl Into<Cube>) -> &EvaluatedBlock
Returns the EvaluatedBlock of the block in this space at the given position.
If out of bounds, returns the evaluation of AIR.
Sourcepub fn set<'block>(
&mut self,
position: impl Into<Cube>,
block: impl Into<Cow<'block, Block>>,
) -> Result<bool, SetCubeError>
pub fn set<'block>( &mut self, position: impl Into<Cube>, block: impl Into<Cow<'block, Block>>, ) -> Result<bool, SetCubeError>
Replace the block in this space at the given position.
If the position is out of bounds, there is no effect.
§Returns
Returns Ok(true) if the change was made, Ok(false) if the same block was
already present, and Err(_) if the replacement could not be made; see
SetCubeError for possible errors.
use all_is_cubes::block;
use all_is_cubes::math::Rgba;
use all_is_cubes::space::Space;
use all_is_cubes::universe::ReadTicket;
let mut space = Space::empty_positive(1, 1, 1);
let a_block = block::from_color!(1.0, 0.0, 0.0, 1.0);
space.mutate(ReadTicket::stub(), |m| {
m.set([0, 0, 0], &a_block)
}).unwrap();
assert_eq!(space[[0, 0, 0]], a_block);Sourcepub fn fill<F, B>(
&mut self,
region: GridAab,
function: F,
) -> Result<(), SetCubeError>
pub fn fill<F, B>( &mut self, region: GridAab, function: F, ) -> Result<(), SetCubeError>
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 region extends outside of
self.bounds(), that will always be rejected before any changes
are made.)
use all_is_cubes::block;
use all_is_cubes::math::{GridAab, Rgba};
use all_is_cubes::space::Space;
use all_is_cubes::universe::ReadTicket;
let mut space = Space::empty_positive(10, 10, 10);
let a_block: block::Block = block::from_color!(1.0, 0.0, 0.0, 1.0);
space.mutate(ReadTicket::stub(), |m| {
m.fill(GridAab::from_lower_size([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]], block::AIR);TODO: Support providing the previous block as a parameter (take cues from extract).
See also Mutation::fill_uniform() for filling a region with one block.
Sourcepub fn fill_all<F, B>(&mut self, function: F) -> Result<(), SetCubeError>
pub fn fill_all<F, B>(&mut self, function: F) -> Result<(), SetCubeError>
As Mutation::fill(), but fills the entire space instead of a specified region.
Sourcepub fn fill_uniform(
&mut self,
region: GridAab,
block: &Block,
) -> Result<(), SetCubeError>
pub fn fill_uniform( &mut self, region: GridAab, block: &Block, ) -> Result<(), SetCubeError>
Replace blocks in region with the given block.
TODO: Document error behavior
use all_is_cubes::block;
use all_is_cubes::math::{GridAab, Rgba};
use all_is_cubes::space::Space;
use all_is_cubes::universe::ReadTicket;
let mut space = Space::empty_positive(10, 10, 10);
let a_block: block::Block = block::from_color!(1.0, 0.0, 0.0, 1.0);
space.mutate(ReadTicket::stub(), |m| {
m.fill_uniform(GridAab::from_lower_size([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]], &block::AIR);See also Mutation::fill() for non-uniform fill and bulk copies.
Sourcepub fn fill_all_uniform(&mut self, block: &Block) -> Result<(), SetCubeError>
pub fn fill_all_uniform(&mut self, block: &Block) -> Result<(), SetCubeError>
As Mutation::fill_uniform(), but fills the entire space instead of a specified region.
Sourcepub fn draw_target<C>(
&mut self,
transform: Gridgid,
) -> DrawingPlane<'_, Self, C>
pub fn draw_target<C>( &mut self, transform: Gridgid, ) -> DrawingPlane<'_, Self, C>
Provides an DrawTarget
adapter for 2.5D drawing.
For more information on how to use this, see
all_is_cubes::drawing.
Sourcepub 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.
Sourcepub fn fast_evaluate_light(&mut self)
pub fn fast_evaluate_light(&mut self)
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).
This function is useful immeduately after filling a Space with its initial contents.
TODO: Revisit whether this is a good public API.
Trait Implementations§
Auto Trait Implementations§
impl<'m, 'space> Freeze for Mutation<'m, 'space>
impl<'m, 'space> !RefUnwindSafe for Mutation<'m, 'space>
impl<'m, 'space> Send for Mutation<'m, 'space>
impl<'m, 'space> Sync for Mutation<'m, 'space>
impl<'m, 'space> Unpin for Mutation<'m, 'space>
impl<'m, 'space> !UnwindSafe for Mutation<'m, 'space>
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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