More tests:
-fixed bug in EntityManger.addComponents -added many new tests
This commit is contained in:
parent
84e04191c8
commit
d0b7138f9f
2 changed files with 288 additions and 3 deletions
289
tests/basic.d
289
tests/basic.d
|
|
@ -101,7 +101,7 @@ struct EmptySystem
|
|||
|
||||
void beforeEveryTest()
|
||||
{
|
||||
gEM.initialize(1);
|
||||
gEM.initialize(0);
|
||||
|
||||
gEM.beginRegister();
|
||||
|
||||
|
|
@ -493,11 +493,10 @@ unittest
|
|||
gEM.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@("SystemEntityCallbacks")
|
||||
unittest
|
||||
{
|
||||
//TODO: this test is WIP by now
|
||||
struct TestSystem
|
||||
{
|
||||
mixin ECS.System!16;
|
||||
|
|
@ -569,4 +568,288 @@ unittest
|
|||
assert(system.add == 2);
|
||||
|
||||
gEM.commit();
|
||||
}
|
||||
|
||||
@("TemplateCoverage")
|
||||
unittest
|
||||
{
|
||||
struct TestSystem
|
||||
{
|
||||
mixin ECS.System;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
int length;
|
||||
Entity[] entity;
|
||||
@readonly CLong[] long_;
|
||||
@optional CInt[] int_;
|
||||
@readonly CFloat[] float_;
|
||||
}
|
||||
|
||||
mixin ECS.ExcludedComponents!(CUnregistered);
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
gEM.beginRegister();
|
||||
|
||||
gEM.registerComponent!CUnregistered;
|
||||
|
||||
gEM.registerSystem!TestSystem(0);
|
||||
|
||||
gEM.endRegister();
|
||||
}
|
||||
|
||||
@("UnregisteredSystem")
|
||||
unittest
|
||||
{
|
||||
struct TestSystem
|
||||
{
|
||||
mixin ECS.System;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
int length;
|
||||
Entity[] entity;
|
||||
@readonly CLong[] long_;
|
||||
@optional CInt[] int_;
|
||||
@readonly CFloat[] float_;
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
assert(gEM.getSystem!TestSystem is null);
|
||||
assert(gEM.getSystem(TestSystem.system_id) is null);
|
||||
}
|
||||
|
||||
@("MultithreadedUpdate")
|
||||
unittest
|
||||
{
|
||||
struct TestSystem
|
||||
{
|
||||
mixin ECS.System;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
int length;
|
||||
Entity[] entity;
|
||||
@readonly CLong[] long_;
|
||||
@optional CInt[] int_;
|
||||
@readonly CFloat[] float_;
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
update++;
|
||||
entities += data.length;
|
||||
}
|
||||
|
||||
int update = 0;
|
||||
int entities = 0;
|
||||
}
|
||||
|
||||
struct TestEmptySystem
|
||||
{
|
||||
mixin ECS.System;
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
int length;
|
||||
}
|
||||
|
||||
void onUpdate(EntitiesData data)
|
||||
{
|
||||
update++;
|
||||
}
|
||||
|
||||
int update = 0;
|
||||
}
|
||||
|
||||
void dispatch(EntityManager.JobGroup grp)
|
||||
{
|
||||
foreach(job; grp.jobs)
|
||||
{
|
||||
job.execute();
|
||||
}
|
||||
}
|
||||
|
||||
uint getID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gEM.setMultithreadingCallbacks(&dispatch, &getID);
|
||||
|
||||
gEM.beginRegister();
|
||||
|
||||
gEM.registerPass("custom");
|
||||
gEM.registerSystem!TestSystem(-1,"custom");
|
||||
gEM.registerSystem!TestEmptySystem(1,"custom");
|
||||
|
||||
gEM.endRegister();
|
||||
|
||||
TestSystem* system = gEM.getSystem!TestSystem;
|
||||
TestEmptySystem* empty_system = gEM.getSystem!TestEmptySystem;
|
||||
|
||||
gEM.begin();
|
||||
|
||||
gEM.updateMT("custom");
|
||||
|
||||
gEM.end();
|
||||
|
||||
assert(system.update == 0);
|
||||
assert(system.entities == 0);
|
||||
assert(empty_system.update == 1);
|
||||
|
||||
ushort[2] ids = [CLong.component_id,CFloat.component_id];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
gEM.addEntity(tmpl);
|
||||
|
||||
gEM.begin();
|
||||
|
||||
gEM.updateMT("custom");
|
||||
|
||||
gEM.end();
|
||||
|
||||
assert(system.update == 1);
|
||||
assert(system.entities == 1);
|
||||
assert(empty_system.update == 2);
|
||||
system.entities = 0;
|
||||
|
||||
foreach(i;0..2000)gEM.addEntity(tmpl);
|
||||
|
||||
gEM.begin();
|
||||
|
||||
gEM.updateMT("custom");
|
||||
|
||||
gEM.end();
|
||||
|
||||
assert(system.update > 2);
|
||||
assert(system.entities == 2001);
|
||||
assert(empty_system.update == 3);
|
||||
system.entities = 0;
|
||||
|
||||
foreach(i;0..10000)gEM.addEntity(tmpl);
|
||||
|
||||
gEM.begin();
|
||||
|
||||
gEM.updateMT("custom");
|
||||
|
||||
gEM.end();
|
||||
|
||||
assert(system.entities == 12001);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(gEM.pageSize == 32768);
|
||||
assert(gEM.pagesInBlock == 128);
|
||||
}
|
||||
|
||||
@("AddRemoveEntities")
|
||||
unittest
|
||||
{
|
||||
ushort[3] ids = [CLong.component_id,CFloat.component_id,CShort.component_id];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
|
||||
EntityID[5000] entities;
|
||||
|
||||
foreach(i;0..4)
|
||||
{
|
||||
foreach(j;0..5000)
|
||||
{
|
||||
entities[j] = gEM.addEntity(tmpl).id;
|
||||
}
|
||||
gEM.commit();
|
||||
foreach(j;0..5000)
|
||||
{
|
||||
gEM.removeEntity(entities[j]);
|
||||
}
|
||||
gEM.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@("ChangeEntityComponents")
|
||||
unittest
|
||||
{
|
||||
gEM.beginRegister();
|
||||
|
||||
gEM.registerComponent!CUnregistered;
|
||||
|
||||
gEM.endRegister();
|
||||
|
||||
ushort[1] ids = [CLong.component_id];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
|
||||
EntityID id = gEM.addEntity(tmpl).id;
|
||||
gEM.commit();
|
||||
Entity* entity = gEM.getEntity(id);
|
||||
assert(entity.id == id);
|
||||
assert(entity.getComponent!CLong !is null);
|
||||
assert(entity.getComponent!CFloat is null);
|
||||
assert(entity.getComponent!CUnregistered is null);
|
||||
assert(entity.getComponent!CShort is null);
|
||||
assert(entity.getComponent!CInt is null);
|
||||
assert(*entity.getComponent!CLong == 10);
|
||||
|
||||
gEM.addComponents(id, CShort(15), CFloat(13));
|
||||
gEM.commit();
|
||||
|
||||
entity = gEM.getEntity(id);
|
||||
assert(entity.id == id);
|
||||
assert(entity.getComponent!CLong !is null);
|
||||
assert(entity.getComponent!CFloat !is null);
|
||||
assert(entity.getComponent!CUnregistered is null);
|
||||
assert(entity.getComponent!CShort !is null);
|
||||
assert(entity.getComponent!CInt is null);
|
||||
assert(*entity.getComponent!CLong == 10);
|
||||
assert(*entity.getComponent!CShort == 15);
|
||||
assert(*entity.getComponent!CFloat == 13);
|
||||
|
||||
ushort[3] ids2 = [CFloat.component_id, CLong.component_id, CUnregistered.component_id];
|
||||
gEM.removeComponents(id, ids2);
|
||||
gEM.commit();
|
||||
|
||||
entity = gEM.getEntity(id);
|
||||
assert(entity.id == id);
|
||||
assert(entity.getComponent!CLong is null);
|
||||
assert(entity.getComponent!CFloat is null);
|
||||
assert(entity.getComponent!CUnregistered is null);
|
||||
assert(entity.getComponent!CShort !is null);
|
||||
assert(entity.getComponent!CInt is null);
|
||||
assert(*entity.getComponent!CShort == 15);
|
||||
|
||||
gEM.removeComponents(id, ids2);
|
||||
gEM.addComponents(id, CShort(11), CLong(2)); //wrong order of components
|
||||
gEM.commit();
|
||||
|
||||
entity = gEM.getEntity(id);
|
||||
assert(entity.id == id);
|
||||
assert(entity.getComponent!CLong !is null);
|
||||
assert(entity.getComponent!CFloat is null);
|
||||
assert(entity.getComponent!CUnregistered is null);
|
||||
assert(entity.getComponent!CShort !is null);
|
||||
assert(entity.getComponent!CInt is null);
|
||||
assert(*entity.getComponent!CLong == 2);
|
||||
assert(*entity.getComponent!CShort == 15);
|
||||
|
||||
gEM.removeEntity(id);
|
||||
|
||||
entity = gEM.getEntity(id);
|
||||
assert(entity !is null);
|
||||
assert(entity.id == id);
|
||||
|
||||
gEM.commit();
|
||||
entity = gEM.getEntity(id);
|
||||
assert(entity is null);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue