-add ecsID template function (get Component/System/Event ID, passes tests)

-removed some ECS mixins code
This commit is contained in:
Mergul 2020-09-29 18:41:31 +02:00
parent 13c82acad4
commit a926b79223
9 changed files with 138 additions and 123 deletions

View file

@ -115,7 +115,7 @@ struct EmptySystem
void beforeEveryTest()
{
CUnregistered.component_id = ushort.max;
ecsID!CUnregistered = ushort.max;
gEM.initialize(0);
gEM.beginRegister();
@ -138,17 +138,17 @@ void afterEveryTest()
@("EntityMeta")
unittest
{
EntityTemplate* tmpl_ = gEM.allocateTemplate([CInt.component_id, CFloat.component_id, CFlag.component_id].staticArray);
EntityTemplate* tmpl_ = gEM.allocateTemplate([ecsID!CInt, ecsID!CFloat, ecsID!CFlag].staticArray);
Entity* entity = gEM.addEntity(tmpl_);
EntityMeta meta = entity.getMeta();
assert(meta.hasComponent(CInt.component_id));
assert(meta.hasComponent(ecsID!CInt));
assert(meta.getComponent!CInt);
assert(meta.hasComponent(CFloat.component_id));
assert(meta.hasComponent(ecsID!CFloat));
assert(meta.getComponent!CFloat);
assert(!meta.getComponent!CLong);
assert(!meta.hasComponent(CLong.component_id));
assert(!meta.hasComponent(ecsID!CLong));
assert(!meta.getComponent!CUnregistered);
assert(!meta.hasComponent(CUnregistered.component_id));
assert(!meta.hasComponent(ecsID!CUnregistered));
assert(*meta.getComponent!CInt == 1);
assert(*meta.getComponent!CFloat == 2.0);
}
@ -156,7 +156,7 @@ unittest
@("AddEntity")
unittest
{
EntityTemplate* tmpl_ = gEM.allocateTemplate([CInt.component_id, CFloat.component_id, CFlag.component_id].staticArray);
EntityTemplate* tmpl_ = gEM.allocateTemplate([ecsID!CInt, ecsID!CFloat, ecsID!CFlag].staticArray);
assert(tmpl_.info.components.length == 3);
assert(tmpl_.info.size == (CInt.sizeof + CFloat.sizeof + EntityID.sizeof));
assert(tmpl_.getComponent!CInt);
@ -185,8 +185,8 @@ unittest
//Entity* entity3 = gEM.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray);
Entity* entity3 = gEM.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray);
EntityID id = entity3.id;
assert(entity3.hasComponent(CInt.component_id));
assert(entity3.hasComponent(CFloat.component_id));
assert(entity3.hasComponent(ecsID!CInt));
assert(entity3.hasComponent(ecsID!CFloat));
assert(*entity3.getComponent!CInt == 10);
assert(*entity3.getComponent!CFloat == 2.0);
@ -201,7 +201,7 @@ unittest
assert(*entity3.getComponent!CFloat == 2.0);
assert(*entity3.getComponent!CShort == 2);
gEM.removeComponents(entity3.id, [CFlag().component_id,CShort(2).component_id].staticArray);
gEM.removeComponents(entity3.id, [ecsID!CFlag,ecsID!CShort].staticArray);
gEM.commit();
entity3 = gEM.getEntity(id);
assert(entity3.getComponent!CInt);
@ -212,7 +212,7 @@ unittest
assert(*entity3.getComponent!CFloat == 2.0);
gEM.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray);
gEM.removeComponents(entity3.id, [CUnregistered.component_id].staticArray);
gEM.removeComponents(entity3.id, [ecsID!CUnregistered].staticArray);
gEM.commit();
entity3 = gEM.getEntity(id);
assert(entity3.getComponent!CInt);
@ -235,7 +235,7 @@ unittest
assert(entity3.getComponent!CUnregistered);
assert(*entity3.getComponent!CUnregistered == 4);
gEM.removeComponents(entity3.id, [CUnregistered.component_id].staticArray);
gEM.removeComponents(entity3.id, [ecsID!CUnregistered].staticArray);
gEM.commit();
entity3 = gEM.getEntity(id);
assert(!entity3.getComponent!CUnregistered);
@ -247,9 +247,9 @@ unittest
unittest
{
//basic template allocation
ushort[2] ids = [CInt.component_id, CFloat.component_id];
ushort[2] ids = [ecsID!CInt, ecsID!CFloat];
EntityTemplate* tmpl_ = gEM.allocateTemplate(ids);
EntityTemplate* tmpl_d = gEM.allocateTemplate([CFloat.component_id, CInt.component_id, CFloat.component_id].staticArray);
EntityTemplate* tmpl_d = gEM.allocateTemplate([ecsID!CFloat, ecsID!CInt, ecsID!CFloat].staticArray);
EntityTemplate* tmpl_cp = gEM.allocateTemplate(tmpl_);
assert(tmpl_d.info == tmpl_.info);
assert(tmpl_cp.info == tmpl_cp.info);
@ -268,7 +268,7 @@ unittest
*tmpl_.getComponent!CFloat = 5.0;
//allocate template from template with additional components
ushort[2] ids2 = [CDouble.component_id,CFlag.component_id];
ushort[2] ids2 = [ecsID!CDouble,ecsID!CFlag];
EntityTemplate* tmpl_2 = gEM.allocateTemplate(tmpl_, ids2);
assert(tmpl_2.info.components.length == 4);
assert(tmpl_2.getComponent!CInt);
@ -313,7 +313,7 @@ unittest
assert(*tmpl_4.getComponent!CDouble == 3.0);
//allocate template from template with three additional component
ushort[3] ids3 = [CDouble.component_id, CLong.component_id, CShort.component_id];
ushort[3] ids3 = [ecsID!CDouble, ecsID!CLong, ecsID!CShort];
EntityTemplate* tmpl_5 = gEM.allocateTemplate(tmpl_2, ids3);
assert(tmpl_5.info.components.length == 6);
assert(tmpl_5.getComponent!CInt);
@ -328,7 +328,7 @@ unittest
assert(*tmpl_5.getComponent!CShort == 12);
//allocate template from template without one component
ushort[1] rem_ids = [CFloat.component_id];
ushort[1] rem_ids = [ecsID!CFloat];
EntityTemplate* tmpl_6 = gEM.allocateTemplate(tmpl_, null, rem_ids);
assert(tmpl_6.info.components.length == 1);
assert(tmpl_6.getComponent!CInt);
@ -358,8 +358,8 @@ unittest
unittest
{
//basic template allocation
ushort[2] ids = [CFloat.component_id, CInt.component_id];
ushort[2] ids2 = [CInt.component_id, CFloat.component_id];
ushort[2] ids = [ecsID!CFloat, ecsID!CInt];
ushort[2] ids2 = [ecsID!CInt, ecsID!CFloat];
EntityTemplate* tmpl_ = gEM.allocateTemplate(ids);
EntityTemplate* tmpl_2 = gEM.allocateTemplate(ids2);
assert(tmpl_.info.components.length == 2);
@ -398,9 +398,9 @@ unittest
assert(system !is null);
assert(system.count == 0);
System* ecs_system = gEM.getSystem(EmptySystem.system_id);
System* ecs_system = gEM.getSystem(ecsID!EmptySystem);
assert(ecs_system !is null);
assert(ecs_system.id == EmptySystem.system_id);
assert(ecs_system.id == ecsID!EmptySystem);
assert(ecs_system.name == "tests.basic.EmptySystem");
gEM.begin();
@ -502,7 +502,7 @@ unittest
//FIXME: currently destroy is only called with Manager.destory which is bug, but there is no workaround for this by now
//assert(destroy == 1);
System* ecs_system = gEM.getSystem(system.system_id);
System* ecs_system = gEM.getSystem(system.ecsID);
ecs_system.enable();
assert(system.enable == 1);
@ -513,7 +513,7 @@ unittest
assert(system.disable == 1);
ushort[2] ids = [CLong.component_id,CFloat.component_id];
ushort[2] ids = [ecsID!CLong,ecsID!CFloat];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
gEM.addEntity(tmpl);
@ -527,7 +527,7 @@ unittest
gEM.end();
assert(system.end == 1);
ushort[2] ids2 = [CLong.component_id, CInt.component_id];
ushort[2] ids2 = [ecsID!CLong, ecsID!CInt];
EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2);
scope (exit) gEM.freeTemplate(tmpl2);
gEM.addEntity(tmpl2);
@ -542,7 +542,7 @@ unittest
gEM.end();
assert(system.end == 2);
ushort[2] ids3 = [CLong.component_id, CShort.component_id];
ushort[2] ids3 = [ecsID!CLong, ecsID!CShort];
EntityTemplate* tmpl3 = gEM.allocateTemplate(ids3);
scope (exit) gEM.freeTemplate(tmpl3);
gEM.addEntity(tmpl3);
@ -601,13 +601,13 @@ unittest
assert(system !is null);
assert(system.updates_count == 0);
System* ecs_system = gEM.getSystem(LongAddSystem.system_id);
System* ecs_system = gEM.getSystem(ecsID!LongAddSystem);
assert(ecs_system !is null);
assert(ecs_system.id == LongAddSystem.system_id);
assert(ecs_system.id == ecsID!LongAddSystem);
assert(ecs_system.priority == -1);
assert(ecs_system.name == "tests.basic.LongAddSystem");
ushort[1] ids = [CLong.component_id];
ushort[1] ids = [ecsID!CLong];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
gEM.addEntity(tmpl);
@ -757,19 +757,19 @@ unittest
assert(system.remove == 0);
assert(system.change == 0);
EntityTemplate* tmpl = gEM.allocateTemplate([CLong.component_id,CFloat.component_id].staticArray);
EntityTemplate* tmpl = gEM.allocateTemplate([ecsID!CLong,ecsID!CFloat].staticArray);
scope (exit) gEM.freeTemplate(tmpl);
EntityID id0 = gEM.addEntity(tmpl).id;
gEM.commit();
assert(system.add == 1);
EntityTemplate* tmpl2 = gEM.allocateTemplate([CLong.component_id, CInt.component_id].staticArray);
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CLong, ecsID!CInt].staticArray);
scope (exit) gEM.freeTemplate(tmpl2);
EntityID id1 = gEM.addEntity(tmpl2).id;
gEM.commit();
assert(system.add == 2);
EntityTemplate* tmpl3 = gEM.allocateTemplate([CLong.component_id, CShort.component_id].staticArray);
EntityTemplate* tmpl3 = gEM.allocateTemplate([ecsID!CLong, ecsID!CShort].staticArray);
scope (exit) gEM.freeTemplate(tmpl3);
EntityID id2 = gEM.addEntity(tmpl3).id;
gEM.commit();
@ -778,19 +778,19 @@ unittest
gEM.beginRegister();
gEM.endRegister();
gEM.removeComponents(id0, [CFloat.component_id].staticArray);
gEM.removeComponents(id0, [ecsID!CFloat].staticArray);
gEM.commit();
assert(system.add == 2);
assert(system.remove == 0);
assert(system.change == 0);
gEM.removeComponents(id1, [CInt.component_id].staticArray);
gEM.removeComponents(id1, [ecsID!CInt].staticArray);
gEM.commit();
assert(system.add == 2);
assert(system.remove == 0);
assert(system.change == 1);
gEM.removeComponents(id2, [CShort.component_id].staticArray);
gEM.removeComponents(id2, [ecsID!CShort].staticArray);
gEM.commit();
assert(system.add == 3);
assert(system.remove == 0);
@ -889,7 +889,7 @@ unittest
}
assert(gEM.getSystem!TestSystem is null);
assert(gEM.getSystem(TestSystem.system_id) is null);
assert(gEM.getSystem(ecsID!TestSystem) is null);
}
@("MultithreadedUpdate")
@ -961,10 +961,10 @@ unittest
TestSystem* system = gEM.getSystem!TestSystem;
TestEmptySystem* empty_system = gEM.getSystem!TestEmptySystem;
ushort[2] ids = [CLong.component_id,CFloat.component_id];
ushort[2] ids = [ecsID!CLong,ecsID!CFloat];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
EntityTemplate* tmpl2 = gEM.allocateTemplate([CLong.component_id,CInt.component_id,CShort.component_id,CFloat.component_id].staticArray);
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CLong,ecsID!CInt,ecsID!CShort,ecsID!CFloat].staticArray);
scope (exit) gEM.freeTemplate(tmpl2);
gEM.begin();
@ -1059,7 +1059,7 @@ unittest
@("AddRemoveEntities")
unittest
{
ushort[3] ids = [CLong.component_id,CFloat.component_id,CShort.component_id];
ushort[3] ids = [ecsID!CLong,ecsID!CFloat,ecsID!CShort];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
@ -1089,7 +1089,7 @@ unittest
gEM.endRegister();
ushort[1] ids = [CLong.component_id];
ushort[1] ids = [ecsID!CLong];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
@ -1118,7 +1118,7 @@ unittest
assert(*entity.getComponent!CShort == 15);
assert(*entity.getComponent!CFloat == 13);
ushort[3] ids2 = [CFloat.component_id, CLong.component_id, CUnregistered.component_id];
ushort[3] ids2 = [ecsID!CFloat, ecsID!CLong, ecsID!CUnregistered];
gEM.removeComponents(id, ids2);
gEM.commit();
@ -1161,12 +1161,12 @@ unittest
{
struct ETest
{
mixin ECS.Event;
// mixin ECS.Event;
}
struct ETest2
{
mixin ECS.Event;
// mixin ECS.Event;
void onDestroy()
{
@ -1253,10 +1253,10 @@ unittest
gEM.endRegister();
ushort[1] ids = [CLong.component_id];
ushort[1] ids = [ecsID!CLong];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
scope (exit) gEM.freeTemplate(tmpl);
ushort[1] ids2 = [CShort.component_id];
ushort[1] ids2 = [ecsID!CShort];
EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2);
scope (exit) gEM.freeTemplate(tmpl2);
@ -1348,11 +1348,11 @@ unittest
gEM.endRegister();
EntityTemplate* tmpl = gEM.allocateTemplate([CInt.component_id].staticArray);
EntityTemplate* tmpl = gEM.allocateTemplate([ecsID!CInt].staticArray);
scope (exit) gEM.freeTemplate(tmpl);
EntityID id1 = gEM.addEntity(tmpl).id;
EntityTemplate* tmpl2 = gEM.allocateTemplate([CInt.component_id, CLong.component_id].staticArray);
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CInt, ecsID!CLong].staticArray);
scope (exit) gEM.freeTemplate(tmpl2);
EntityID id2 = gEM.addEntity(tmpl2).id;
@ -1471,22 +1471,22 @@ unittest
const (EntityManager.UpdatePass)* pass = gEM.getPass("update");
assert(pass != null);
assert(pass.system_callers.length == 5);
assert(pass.system_callers[0].system_id == TestSystem.system_id);
assert(pass.system_callers[1].system_id == TestSystem2.system_id);
assert(pass.system_callers[2].system_id == TestSystem3.system_id);
assert(pass.system_callers[3].system_id == TestSystem4.system_id);
assert(pass.system_callers[4].system_id == TestSystem5.system_id);
assert(pass.system_callers[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[1].system_id == ecsID!TestSystem2);
assert(pass.system_callers[2].system_id == ecsID!TestSystem3);
assert(pass.system_callers[3].system_id == ecsID!TestSystem4);
assert(pass.system_callers[4].system_id == ecsID!TestSystem5);
assert(pass.system_callers[0].dependencies.length == 0);
assert(pass.system_callers[1].dependencies.length == 1);
assert(pass.system_callers[2].dependencies.length == 1);
assert(pass.system_callers[3].dependencies.length == 3);
assert(pass.system_callers[4].dependencies.length == 1);
assert(pass.system_callers[1].dependencies[0].system_id == TestSystem.system_id);
assert(pass.system_callers[2].dependencies[0].system_id == TestSystem2.system_id);
assert(pass.system_callers[3].dependencies[0].system_id == TestSystem.system_id);
assert(pass.system_callers[3].dependencies[1].system_id == TestSystem2.system_id);
assert(pass.system_callers[3].dependencies[2].system_id == TestSystem3.system_id);
assert(pass.system_callers[4].dependencies[0].system_id == TestSystem4.system_id);
assert(pass.system_callers[1].dependencies[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[2].dependencies[0].system_id == ecsID!TestSystem2);
assert(pass.system_callers[3].dependencies[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[3].dependencies[1].system_id == ecsID!TestSystem2);
assert(pass.system_callers[3].dependencies[2].system_id == ecsID!TestSystem3);
assert(pass.system_callers[4].dependencies[0].system_id == ecsID!TestSystem4);
}
@("ExternalSystemDependencies")
@ -1598,21 +1598,21 @@ unittest
const (EntityManager.UpdatePass)* pass = gEM.getPass("update");
assert(pass != null);
assert(pass.system_callers.length == 5);
assert(pass.system_callers[0].system_id == TestSystem.system_id);
assert(pass.system_callers[1].system_id == TestSystem2.system_id);
assert(pass.system_callers[2].system_id == TestSystem3.system_id);
assert(pass.system_callers[3].system_id == TestSystem4.system_id);
assert(pass.system_callers[4].system_id == TestSystem5.system_id);
assert(pass.system_callers[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[1].system_id == ecsID!TestSystem2);
assert(pass.system_callers[2].system_id == ecsID!TestSystem3);
assert(pass.system_callers[3].system_id == ecsID!TestSystem4);
assert(pass.system_callers[4].system_id == ecsID!TestSystem5);
assert(pass.system_callers[0].dependencies.length == 0);
assert(pass.system_callers[1].dependencies.length == 1);
assert(pass.system_callers[2].dependencies.length == 1);
assert(pass.system_callers[3].dependencies.length == 3);
assert(pass.system_callers[4].dependencies.length == 2);
assert(pass.system_callers[1].dependencies[0].system_id == TestSystem.system_id);
assert(pass.system_callers[2].dependencies[0].system_id == TestSystem2.system_id);
assert(pass.system_callers[3].dependencies[0].system_id == TestSystem.system_id);
assert(pass.system_callers[3].dependencies[1].system_id == TestSystem2.system_id);
assert(pass.system_callers[3].dependencies[2].system_id == TestSystem3.system_id);
assert(pass.system_callers[4].dependencies[0].system_id == TestSystem2.system_id);
assert(pass.system_callers[4].dependencies[1].system_id == TestSystem4.system_id);
assert(pass.system_callers[1].dependencies[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[2].dependencies[0].system_id == ecsID!TestSystem2);
assert(pass.system_callers[3].dependencies[0].system_id == ecsID!TestSystem);
assert(pass.system_callers[3].dependencies[1].system_id == ecsID!TestSystem2);
assert(pass.system_callers[3].dependencies[2].system_id == ecsID!TestSystem3);
assert(pass.system_callers[4].dependencies[0].system_id == ecsID!TestSystem2);
assert(pass.system_callers[4].dependencies[1].system_id == ecsID!TestSystem4);
}