Mutation

Struct Mutation 

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

Source

pub fn bounds(&self) -> GridAab

Same as Space::bounds().

Source

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.

Source

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);
Source

pub fn fill<F, B>( &mut self, region: GridAab, function: F, ) -> Result<(), SetCubeError>
where F: FnMut(Cube) -> Option<B>, B: Borrow<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 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.

Source

pub fn fill_all<F, B>(&mut self, function: F) -> Result<(), SetCubeError>
where F: FnMut(Cube) -> Option<B>, B: Borrow<Block>,

As Mutation::fill(), but fills the entire space instead of a specified region.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn spawn(&self) -> &Spawn

Returns the current default Spawn, which determines where new Characters are placed in the space if no alternative applies.

Source

pub fn set_spawn(&mut self, spawn: Spawn)

Sets the default Spawn, which determines where new Characters are placed in the space if no alternative applies.

Trait Implementations§

Source§

impl<T: Into<Cube>> Index<T> for Mutation<'_, '_>

Source§

type Output = Block

The returned type after indexing.
Source§

fn index(&self, position: T) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,