component.entitysystem - ICE 0.1 API documentation

ICE 0.1 API documentation

# component.entitysystem

Component based entity system.

struct EntityID;

  Uniquely identifies an entity in an entity system.

  const pure nothrow bool opEquals(EntityID rhs);

    Equality comparison with another ID.

  const pure nothrow long opCmp(EntityID rhs);

    Comparison for sorting.

  const string toString();

    Get string representation for debugging.

struct Entity;

  Game entity.

  Entity is specifies what components it has, in an on/off fashion, as well as indices to its components stored in the EntitySystem.
  The most effective way to access the components of a particular entity is by iterating the entity and component arrays in lockstep in EntitySystem.

  const pure nothrow @property bool valid();

    Is the entity valid (alive)?

  const pure nothrow @property EntityID id();

    Get the ID of the entity.

  void kill();

    Kill the entity.

    This will make the entity invalid on next EntitySystem update. The entity stays valid during the current update.

  const pure nothrow @property bool killed();

    Has this entity been killed during current update?

  const pure nothrow @property bool spawned();

    Has this entity been spawned at the beginning of the current update?

  static auto ctfeComponentGetters();

    Getters to access components of this entity.

  pure nothrow uint componentIdx(C)();

    Get a reference to the index of specified component. Used during entity construction.

class EntitySystem: monitor.monitorable.Monitorable;

  Stores game entities and their components and provides access to them.

  An Entity is a collection of components with zero or one component of each type.
  A Component is a simple struct with public data members and no functionality at all (setters might be used, though).
  To add a new Component type, you must import it in this file and add it to the componentTypes tuple on top of the file.
  Every component type must be copiable without invalidating its state - it is copied between EntityPrototype and EntitySystem.
  The only way to access entities is to iterate using foreach over Entity and one or more component types. This iterates only over entities that have all of the specified components.

  Examples:

       EntitySystem system; //set elsewhere

       foreach(ref Entity entity,
               ref PhysicsComponent physics,
               ref VisualComponent visual;
               system)
       {
           //Do stuff with physics and visual.
       }

  This works similarly to a select in a relational database that only selects rows where specified columns are nonnull.
  Note that Entities and their Components might be moved around in memory between updates, so keeping pointers to them is not safe. It is safe for duration of one update, so that pointers can be stored for various in-update operations.
  void destroy();

    Destroy all entities and components, returning to initial state.

  final EntityID newEntity(ref EntityPrototype prototype);

    Construct an entity with components from specified prototype.

  final Entity* entityWithID(ref const EntityID id);

    Get a pointer to the entity with specified ID.

    This is the safe way to keep "pointers" to entities between game updates.
    If the entity with specified ID doesn't exist (e.g. was destroyed), this returns null.

  final void update();

    Update the EntitySystem.

    This should be called once per game logic update. This is where entities created or killed in previous frame are actually added/removed.

  int opApply(Types...)(int delegate(ref Entity, ref Types) dg);

    Iterate over entities with specified components.

    This will only iterate over entities that have all of specified component types.

  MonitorDataInterface monitorData();

    Provide an interface for the Monitor subsystem to monitor the EntitySystem.

  void constructEntityAddComponent(C)(Entity* entity, const bool recycling, ref C component);

    Add a component to currently constructed entity.

    Parameters:

    entity | Entity we're constructing at the moment.
    recycling | Are we recycling an already existing(dead) entity?
    component | Component to add to the entity.

  inout pure inout(SegmentedVector!(T,4096)) componentArray(T)();

    Get the component array of specified type.

Copyright © Ferdinand Majerech 2011. | Page generated by AutoDDoc and Ddoc.