Crate entity_rust

Source
Expand description

§Goal

We want to define components, store them in an efficient manner and make them accessible to systems.

We want to define events along with their types and make them available to systems.

We want to define systems that operate on lists of components, are triggered by other systems through events.

§Implementation

For each component type there will be a list that is a tuple of an entity ID and the component values. There will also be a map from entity IDs to component list indexes.

A system will consist of state, iterators over components its subscribed to and any number of functions that are triggered by events.

§Syntax

component! { Physics, body: physics.RigidBody, physics_id: physics.ID }

// event! { GameStarted } // This one is implicitly defined
event! { PhysicsTick, dt: u64 }
event! { Bump, e1: EntityID, e2: EntityID }

system! { PhysicsSystem,

  state! { world: physics.World }

  on! { GameStarted, {
     state.world = physics.World::new(event.name);
     state.world.on_collision = |e1, e2| {
       unwrap_entity = |e| { e.user_data.downcast_ref<EntityID>() }
       trigger! { Bump, unwrap_entity(e1), unwrap_entity(e2) }
     };
  }}

  on! { PhysicsTick, {
    state.world.step(event.dt);
  }}

  component_added! { Physics, {
    let id = state.world.add_body(component.body);
    component.physics_id = id;
  }}

  component_removed! { Physics, {
    state.world.remove_body(component.physics_id);
  }}

}

system! { BumpSystem, {
  on! { Bump, {
    println!("Entity {:?} bumped into entity {:?}!", e1, e2);
  }}
}}

Modules§

components
entities
events
helpers
systems
tick

Macros§

append_path_component
component
event
on
on_sync
state
static_any_vec_map
sync_event
system
Systems are a set of event handlers and optionally some associated state.
system_contents
system_register

Structs§

Duration
A Duration type to represent a span of time, typically used for system timeouts.
Instant
A measurement of a monotonically nondecreasing clock. Opaque and useful only with Duration.

Functions§

run
ticker