142 lines
No EOL
3 KiB
D
142 lines
No EOL
3 KiB
D
module tests.bugs;
|
|
|
|
import tests.basic;
|
|
|
|
import bubel.ecs.core;
|
|
import bubel.ecs.manager;
|
|
import bubel.ecs.system;
|
|
import bubel.ecs.attributes;
|
|
|
|
version(GNU)
|
|
{
|
|
pragma(inline, true) T[n] staticArray(T, size_t n)(auto ref T[n] a)
|
|
{
|
|
return a;
|
|
}
|
|
}
|
|
else import std.array : staticArray;
|
|
|
|
@("Bug0001")
|
|
unittest
|
|
{
|
|
struct Event1
|
|
{
|
|
// mixin ECS.Event;
|
|
|
|
EntityID id;
|
|
}
|
|
|
|
struct Event2
|
|
{
|
|
// mixin ECS.Event;
|
|
}
|
|
|
|
struct System1
|
|
{
|
|
mixin ECS.System;
|
|
|
|
struct EntitiesData
|
|
{
|
|
CInt[] int_;
|
|
}
|
|
|
|
EntityTemplate* tmpl;
|
|
EntityID id;
|
|
|
|
void onCreate()
|
|
{
|
|
tmpl = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray);
|
|
}
|
|
|
|
void onDestroy()
|
|
{
|
|
gEntityManager.freeTemplate(tmpl);
|
|
}
|
|
|
|
void handleEvent(Entity* entity, Event1 event)
|
|
{
|
|
gEntityManager.removeEntity(event.id);
|
|
gEntityManager.sendEvent(entity.id,Event2());
|
|
}
|
|
|
|
void handleEvent(Entity* entity, Event2 event)
|
|
{
|
|
id = gEntityManager.addEntity(tmpl).id;
|
|
}
|
|
}
|
|
|
|
struct System2
|
|
{
|
|
mixin ECS.System;
|
|
|
|
struct EntitiesData
|
|
{
|
|
Entity[] entity;
|
|
}
|
|
|
|
///check if every entity was removed correctly
|
|
void onUpdate(EntitiesData data)
|
|
{
|
|
assert(0);
|
|
}
|
|
}
|
|
|
|
struct System3
|
|
{
|
|
mixin ECS.System;
|
|
|
|
struct EntitiesData
|
|
{
|
|
uint length;
|
|
Entity[] entity;
|
|
}
|
|
|
|
///remove every entity
|
|
void onUpdate(EntitiesData data)
|
|
{
|
|
foreach(i;0..data.length)gEntityManager.removeEntity(data.entity[i].id);
|
|
}
|
|
}
|
|
|
|
gEntityManager.initialize(0);
|
|
|
|
gEntityManager.beginRegister();
|
|
|
|
gEntityManager.registerComponent!CInt;
|
|
gEntityManager.registerComponent!CFloat;
|
|
gEntityManager.registerComponent!CDouble;
|
|
gEntityManager.registerComponent!CLong;
|
|
gEntityManager.registerComponent!CShort;
|
|
gEntityManager.registerComponent!CFlag;
|
|
|
|
gEntityManager.registerEvent!Event1;
|
|
gEntityManager.registerEvent!Event2;
|
|
|
|
gEntityManager.registerSystem!System1(0);
|
|
gEntityManager.registerSystem!System2(-200);
|
|
gEntityManager.registerSystem!System3(-200);
|
|
|
|
gEntityManager.endRegister();
|
|
|
|
EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!CInt, becsID!CLong].staticArray);
|
|
EntityID id = gEntityManager.addEntity(tmpl,[CLong(10).ref_, CInt(6).ref_].staticArray).id;
|
|
EntityID id2 = gEntityManager.addEntity(tmpl,[CInt(4).ref_].staticArray).id;
|
|
gEntityManager.freeTemplate(tmpl);
|
|
gEntityManager.commit();
|
|
|
|
gEntityManager.sendEvent(id2, Event1(id));
|
|
|
|
gEntityManager.getSystem(becsID!System2).disable();
|
|
|
|
gEntityManager.begin();
|
|
gEntityManager.update();
|
|
gEntityManager.end();
|
|
|
|
gEntityManager.getSystem(becsID!System2).enable();
|
|
|
|
gEntityManager.begin();
|
|
gEntityManager.update();
|
|
gEntityManager.end();
|
|
|
|
gEntityManager.destroy();
|
|
} |