-suport system callback: onCreate, onDestroy, onBegin, onEnd

-support for optional Components for System
-Components IDs in Systems are now stored as ushorts
This commit is contained in:
Mergul 2018-09-16 22:40:55 +02:00
parent 8fdb56e840
commit b3dce6560a
4 changed files with 180 additions and 60 deletions

View file

@ -81,12 +81,32 @@ int main()
struct TestSystem
{
void onCreate()
{
writeln("On Test System create.");
}
void onDestroy()
{
writeln("On Test System destroy.");
}
void onBegin()
{
writeln("On Test System begin.");
}
void onEnd()
{
writeln("On Test System end.");
}
void initialize(ref Entity entity, ref TestComp comp)
{
}
void update(ref Entity entity, ref TestComp test, ref TestComp2 test2) //ref TestComp comp)
void update(ref Entity entity, ref TestComp test, ref TestComp2 test2, TestComp3* test3) //ref TestComp comp)
{
assert(cast(size_t)&test % TestComp.alignof == 0);
assert(cast(size_t)&test2 % TestComp2.alignof == 0);
@ -100,6 +120,7 @@ int main()
test2.a = 8;
//writeln("Jakis tekst! ",test2.b);
//writeln("Low priority tekst! ");
if(test3)test3.gg = 200;
}
void handleEvent(Event event, ref TestComp comp)
@ -247,7 +268,9 @@ int main()
Entity entity = gEM.addEntity(tmpl);
gEM.begin();
gEM.update();
gEM.end();
Entity* pp = gEM.getEntity(entity.id);
writeln((cast(uint*) pp)[0 .. 14], " ", pp);
@ -257,19 +280,25 @@ int main()
gEM.addComponents(entity.id, TestComp3());
pp = gEM.getEntity(entity.id);
gEM.begin();
gEM.update();
gEM.end();
writeln((cast(uint*) pp)[0 .. 14], " ", pp);
gEM.removeComponents!(TestComp)(entity.id);
pp = gEM.getEntity(entity.id);
gEM.begin();
gEM.update();
gEM.end();
writeln((cast(uint*) pp)[0 .. 14], " ", pp);
//import std.stdio;
//writeln((cast(uint*)tmpl.info.first_block)[0..48]);
gEM.freeTemplate(tmpl);
EntityManager.destroy();
return 0;
}