EntityManager

Undocumented in source.

Members

Functions

clear
void clear()
Undocumented in source. Be warned that the author may not have intended to support it.
create
Entity create()

Create an entity

detach
void detach(Entity e)

Detach

exists
bool exists(size_t eid)

Exists

get
Entity get(size_t eid)

Get an entity

getAllWith
Entity[] getAllWith()

Get every entity in the scope which contains a component

getAllWith
Entity[] getAllWith()

Get every entity in the scope which contains a group of components

getDeletedIds
size_t[] getDeletedIds()

Get all the deleted ids

getFirstWith
Entity getFirstWith()

Get the first entity in the scope with a component

getFirstWith
Entity getFirstWith()

Get the first entity in the scope which contains a group of components

Examples

EntityManager manager = new EntityManager();

Entity e1 = manager.create();
Entity e2 = manager.create();

assertTrue(manager.exists(0));

assertEquals(0, e1.id); // Entity id begins in 0
assertEquals(1, e2.id);

e1.detach(); // Entity id is removed from the world's scope

assertEquals(0, manager.getDeletedIds.front);

Entity e3 = manager.create(); // Entity gets an id which was removed previously

assertEquals(0, e3.id);
assertEquals(0, manager.getDeletedIds.length); // Entity id is no longer deleted

assertThrown!EntityManagerHandlingException(manager.detach(e1)); // This entity is no longer in the world's scope
final class Foo : IComponent
{
}

final class Bar : IComponent
{
}

final class Foobar : IComponent
{
}

EntityManager manager = new EntityManager();

Entity e1 = manager.create();
Entity e2 = manager.create();
Entity e3 = manager.create();

e1.add(new Foo());
e1.add(new Bar());

e2.add(new Foo());
e2.add(new Bar());

e3.add(new Foo());

auto arr = manager.getAllWith!(Foo, Bar);
auto e = manager.getFirstWith!Foo;

import std.algorithm.comparison : equal;

assertTrue(equal!((a, b) => a is b)([e1, e2], arr));
assertTrue(e is e1);

assertTrue(manager.getFirstWith!Foobar is null); // There are no entities with this Component
EntityManager manager = new EntityManager();

Entity e = manager.create();

assertTrue(e is manager.get(e.id));
EntityManager manager = new EntityManager();
Entity e = manager.create();
manager.clear();

assertEquals(0, manager.mEntities.length);

Meta