Create an entity
Detach
Exists
Get an entity
Get every entity in the scope which contains a component
Get every entity in the scope which contains a group of components
Get all the deleted ids
Get the first entity in the scope with a component
Get the first entity in the scope which contains a group of components
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);