Class World

java.lang.Object
tripleplay.entity.World
All Implemented Interfaces:
Iterable<Entity>

public class World extends Object implements Iterable<Entity>
A collection of entities and systems. A world is completely self-contained, so it would be possible to have multiple separate worlds running simultaneously, though this would be uncommon.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final react.Signal<Entity>
    A signal emitted when an entity is added to this world.
    final react.Signal<Entity>
    A signal emitted when an entity in this world has changed (usually this means components have been added to or removed from the entity).
    final react.Signal<Entity>
    A signal emitted when an entity in this world which was enabled becomes disabled.
    final react.Signal<Entity>
    A signal emitted when an entity in this world which was disabled becomes enabled.
    final react.Signal<Entity>
    A signal emitted when an entity is removed from the world.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    react.Closeable
    connect(react.Signal<Clock> update, react.Signal<Clock> paint)
    Connects this world to the supplied update and paint signals.
    create(boolean enabled)
    Creates and returns an entity.
    Returns an iterator over all entities in the world.
    entity(int id)
    Returns the entity with the specified id.
     
    void
    paint(Clock clock)
    Paints all of the Systems in this world.
    restore(int id, BitVec components)
    Creates an entity with the specified id and component bitvec.
    void
    update(Clock clock)
    Updates all of the Systems in this world.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • entityAdded

      public final react.Signal<Entity> entityAdded
      A signal emitted when an entity is added to this world.
    • entityChanged

      public final react.Signal<Entity> entityChanged
      A signal emitted when an entity in this world has changed (usually this means components have been added to or removed from the entity).
    • entityEnabled

      public final react.Signal<Entity> entityEnabled
      A signal emitted when an entity in this world which was disabled becomes enabled.
    • entityDisabled

      public final react.Signal<Entity> entityDisabled
      A signal emitted when an entity in this world which was enabled becomes disabled.
    • entityRemoved

      public final react.Signal<Entity> entityRemoved
      A signal emitted when an entity is removed from the world. This happens when an entity is disabled, as well as when it is destroyed.
  • Constructor Details

    • World

      public World()
  • Method Details

    • connect

      public react.Closeable connect(react.Signal<Clock> update, react.Signal<Clock> paint)
      Connects this world to the supplied update and paint signals.
      Returns:
      an object that can be used to disconnect both connections.
    • create

      public Entity create(boolean enabled)
      Creates and returns an entity. The entity may actually be obtained from a pool of free entities to avoid unnecessary garbage generation.
      Parameters:
      enabled - whether the entity should be enabled by default. If it is enabled, it will automatically be queued for addition to the world. If it is not enabled, it will remain dormant until Entity.setEnabled(boolean) is used to enable it.
    • restore

      public Entity restore(int id, BitVec components)
      Creates an entity with the specified id and component bitvec. This is only used when restoring entities from persistent storage. Use create(boolean) to create new entities.
    • entity

      public Entity entity(int id)
      Returns the entity with the specified id. Note: this method is optimized for speed, which means that passing an invalid/unused entity id to this method may return a destroyed entity or it may throw an exception.
    • entities

      public Iterator<Entity> entities()
      Returns an iterator over all entities in the world. Iterator.remove() is not implemented for this iterator.
    • update

      public void update(Clock clock)
      Updates all of the Systems in this world. The systems will likely in turn update the components of registered Entitys.
    • paint

      public void paint(Clock clock)
      Paints all of the Systems in this world.
    • iterator

      public Iterator<Entity> iterator()
      Specified by:
      iterator in interface Iterable<Entity>