Behavior

Trait Behavior 

Source
pub trait Behavior<H: Host>:
    Debug
    + Any
    + Send
    + Sync
    + VisitHandles
    + 'static {
    // Required methods
    fn step(&self, context: &Context<'_, '_, H>) -> (UniverseTransaction, Then);
    fn persistence(&self) -> Option<Persistence>;
}
Expand description

Dynamic add-ons to game objects; we might also have called them “components”. Each behavior is owned by a “host” of type H which determines when the behavior is invoked.

Required Methods§

Source

fn step(&self, context: &Context<'_, '_, H>) -> (UniverseTransaction, Then)

Computes a transaction to apply the effects of this behavior for one timestep, and specifies when next to step the behavior again (if ever).

TODO: Define what happens if the transaction fails.

Source

fn persistence(&self) -> Option<Persistence>

If None, then the behavior should not be persisted/saved to disk, because it will be reconstructed as needed (e.g. collision, occupancy, user interaction, particles).

If Some, then the representation that should be serialized, which must specify not just the state of the behavior but which behavior to recreate.

TODO: Return type isn’t a clean public API, nor extensible.

Implementors§