Struct all_is_cubes::space::Space

source ·
pub struct Space { /* private fields */ }
Expand description

Container for Blocks 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 GridAab::for_block(), and its physics is SpacePhysics::DEFAULT_FOR_BLOCK.

Returns a SpaceBuilder with the given bounds and all default values, which may be used to construct a new Space.

Constructs a Space that is entirely filled with AIR.

Equivalent to Space::builder(bounds).build()

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 GridAab 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.

Copy data out of a portion of the space in a caller-chosen format.

If the provided GridAab contains portions outside of this space’s bounds, 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 region extends outside of self.bounds(), that will always be rejected before any changes are made.)

use all_is_cubes::block::{AIR, Block};
use all_is_cubes::math::{GridAab, Rgba};
use all_is_cubes::space::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(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)], 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.

Replace blocks in region with the given block.

TODO: Document error behavior

use all_is_cubes::block::{AIR, Block};
use all_is_cubes::math::{GridAab, Rgba};
use all_is_cubes::space::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(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)], &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.

Advance time in the space.

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§

Generate an arbitrary value of Self from the given unstructured data. Read more
Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Returns false if the Behavior should be dropped because conditions under which it is useful no longer apply.
Whether the behavior should never be persisted/saved to disk, because it will be reconstructed as needed (e.g. collision, occupancy, user interaction, particles). Read more
Computes a transaction to apply the effects of this behavior for one timestep. Read more
Additional data about “where” the behavior is attached to the host.
Formats the value using the given formatter. Read more

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.

The returned type after indexing.
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.
Checks whether the target’s current state meets the preconditions and returns Err if it does not. (TODO: Informative error return type.) 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
Specify the target of this transaction as a URef, and erase its type, so that it can be combined with other transactions in the same universe. Read more
Specify the target of the transaction as a URef, and erase its type, so that it can be combined with other transactions in the same universe. Read more
Translates a name for an object of type T into a URef for it, which allows borrowing the actual object. Read more
Inserts a new object with a specific name. Read more
Iterate over all of the objects of type T. Note that this includes anonymous objects. Read more
For each URef contained within self that is reachable without traversing another URef, call visitor with a reference to it.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Casts the value.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Casts the value.
Casts the value.
Casts the value.
Converts self into T using Into<T>. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted.
Causes self to use its LowerExp implementation when Debug-formatted.
Causes self to use its LowerHex implementation when Debug-formatted.
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted.
Causes self to use its UpperExp implementation when Debug-formatted.
Causes self to use its UpperHex implementation when Debug-formatted.
Formats each item in a sequence. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Casts the value.
Casts the value.
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
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Casts the value.
Casts the value.
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
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.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Casts the value.
Casts the value.
Casts the value.
Casts the value.