EntityManager class
class EntityManager extends Manager { Bag<Entity> _entities; Bag<Entity> _deletedEntities; Bag<bool> _disabled; int _active = 0; int _added = 0; int _created = 0; int _deleted = 0; _IdentifierPool _identifierPool; EntityManager() : _entities = new Bag<Entity>(), _deletedEntities = new Bag<Entity>(), _disabled = new Bag<bool>(), _identifierPool = new _IdentifierPool(); void initialize() {} Entity _createEntityInstance() { Entity e = _deletedEntities.removeLast(); if (null == e) { e = new Entity._(_world, _identifierPool.checkOut()); } _created++; return e; } void added(Entity e) { _active++; _added++; _entities[e.id] = e; } void enabled(Entity e) { _disabled[e.id] = false; } void disabled(Entity e) { _disabled[e.id] = true; } void deleted(Entity e) { _entities[e.id] = null; _disabled[e.id] = false; _deletedEntities.add(e); _active--; _deleted++; } /** * Check if this entity is active. * Active means the entity is being actively processed. */ bool isActive(int entityId) => _entities[entityId] != null; /** * Check if the specified entityId is enabled. */ bool isEnabled(int entityId) => !_disabled[entityId]; /** * Get a entity with this id. */ Entity _getEntity(int entityId) => _entities[entityId]; /** * Get how many entities are active in this world. */ int get activeEntityCount => _active; /** * Get how many entities have been created in the world since start. * Note: A created entity may not have been added to the world, thus * created count is always equal or larger than added count. */ int get totalCreated => _created; /** * Get how many entities have been added to the world since start. */ int get totalAdded => _added; /** * Get how many entities have been deleted from the world since start. */ int get totalDeleted => _deleted; }
Extends
Manager > EntityManager
Constructors
new EntityManager() #
EntityManager() : _entities = new Bag<Entity>(), _deletedEntities = new Bag<Entity>(), _disabled = new Bag<bool>(), _identifierPool = new _IdentifierPool();
Properties
final int activeEntityCount #
Get how many entities are active in this world.
int get activeEntityCount => _active;
final int totalAdded #
Get how many entities have been added to the world since start.
int get totalAdded => _added;
Methods
void deleted(Entity e) #
void deleted(Entity e) { _entities[e.id] = null; _disabled[e.id] = false; _deletedEntities.add(e); _active--; _deleted++; }
void initialize() #
void initialize() {}