-added EntityManager.removeEntity(EntityID) -EntitiesBlock now has ID usefull for updating first_free_block in EntityInfo
185 lines
No EOL
3.5 KiB
D
185 lines
No EOL
3.5 KiB
D
module tests.tests;
|
|
|
|
import ecs.manager;
|
|
import ecs.events;
|
|
import ecs.system;
|
|
import ecs.entity;
|
|
|
|
import core.time;
|
|
import std.stdio;
|
|
|
|
int main()
|
|
{
|
|
alias SerializeVector = ubyte[];
|
|
|
|
struct TestComp
|
|
{
|
|
__gshared static int component_id;
|
|
int a;
|
|
ulong b;
|
|
|
|
static void serializeComponent(ref TestComp comp, SerializeVector output)
|
|
{
|
|
|
|
}
|
|
|
|
static void deserializeComponent(ref TestComp comp, ubyte[] data)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
struct TestComp2
|
|
{
|
|
__gshared static int component_id;
|
|
short b;
|
|
ubyte a;
|
|
|
|
static void serializeComponent(ref TestComp comp, SerializeVector output)
|
|
{
|
|
|
|
}
|
|
|
|
static void deserializeComponent(ref TestComp comp, ubyte[] data)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
struct TestSystem
|
|
{
|
|
|
|
void initialize(ref TestComp comp)
|
|
{
|
|
|
|
}
|
|
|
|
void update(ref TestComp test, ref TestComp2 test2)//ref TestComp comp)
|
|
{
|
|
assert( cast(ptrdiff_t)&test % TestComp.alignof == 0 );
|
|
assert( cast(ptrdiff_t)&test2 % TestComp2.alignof == 0 );
|
|
import std.stdio;
|
|
//writeln("Jakis tekst! ",test.b);
|
|
test.a+=1000;
|
|
test.b+=2000;
|
|
//writeln("Jakis tekst! ",test.b);
|
|
test2.b += 2;
|
|
test2.a = 1;
|
|
//writeln("Jakis tekst! ",test2.b);
|
|
}
|
|
|
|
void handleEvent(Event event, ref TestComp comp)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
struct TestSystem2
|
|
{
|
|
|
|
void onEnable()
|
|
{
|
|
import std.stdio;
|
|
writeln("TestSystem2 enabled");
|
|
}
|
|
|
|
void onDisable()
|
|
{
|
|
import std.stdio;
|
|
writeln("TestSystem2 disabled");
|
|
}
|
|
|
|
void initialize(ref TestComp comp)
|
|
{
|
|
|
|
}
|
|
|
|
void update(ref TestComp2 test2)//ref TestComp comp)
|
|
{
|
|
test2.b += 1000;
|
|
}
|
|
|
|
void handleEvent(Event event, ref TestComp comp)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
EntityManager.initialize();
|
|
assert(gEM !is null);
|
|
|
|
MonoTime time = MonoTime.currTime;
|
|
|
|
gEM.registerComponent!TestComp2;
|
|
gEM.registerComponent!TestComp;
|
|
|
|
ulong dur = (MonoTime.currTime - time).total!"usecs";
|
|
writeln("Components register: ",dur," usecs");
|
|
|
|
time = MonoTime.currTime;
|
|
|
|
gEM.registerSystem!TestSystem(0);
|
|
//gEM.registerSystem!TestSystem2(0);
|
|
|
|
dur = (MonoTime.currTime - time).total!"usecs";
|
|
writeln("Systems register: ",dur," usecs");
|
|
|
|
time = MonoTime.currTime;
|
|
|
|
ushort[2] ids = [0,1];
|
|
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
|
*cast(EntityID*)tmpl.entity_data.ptr = EntityID(1,1);
|
|
|
|
dur = (MonoTime.currTime - time).total!"usecs";
|
|
writeln("Template allocating: ",dur," usecs");
|
|
|
|
time = MonoTime.currTime;
|
|
|
|
//foreach(i; 0..1_000_000)gEM.addEntity(tmpl);
|
|
|
|
//foreach(i; 0..1_000_000)gEM.removeEntity(gEM.addEntity(tmpl).id);
|
|
|
|
EntityID[1000] idss;
|
|
|
|
foreach(i; 0..1_000)
|
|
{
|
|
foreach(j; 0..1_000)idss[j] = gEM.addEntity(tmpl).id;
|
|
foreach(j; 0..1_000)gEM.removeEntity(idss[j]);
|
|
}
|
|
|
|
uint blocks = 0;
|
|
foreach(info; &gEM.entities_infos.byValue)
|
|
{
|
|
EntityManager.EntitiesBlock* block = info.first_block;
|
|
while(block !is null)
|
|
{
|
|
block = block.next_block;
|
|
blocks++;
|
|
}
|
|
}
|
|
writeln("Entities blocks: ",blocks);
|
|
|
|
/*Entity entity = gEM.addEntity(tmpl);
|
|
gEM.removeEntity(entity.id);
|
|
gEM.addEntity(tmpl);*/
|
|
|
|
dur = (MonoTime.currTime - time).total!"usecs";
|
|
writeln("Entities adding: ",dur," usecs");
|
|
|
|
gEM.registerSystem!TestSystem2(0);
|
|
|
|
//assert(*(cast(EntityID*)(cast(void*)tmpl.info.first_block+24)) == EntityID(1,1));
|
|
//assert(*(cast(EntityID*)(cast(void*)tmpl.info.first_block+48)) == EntityID(1,1));
|
|
|
|
time = MonoTime.currTime;
|
|
|
|
gEM.update();
|
|
|
|
dur = (MonoTime.currTime - time).total!"usecs";
|
|
writeln("Update: ",dur," usecs");
|
|
|
|
//import std.stdio;
|
|
//writeln((cast(uint*)tmpl.info.first_block)[0..48]);
|
|
gEM.freeTemplate(tmpl);
|
|
return 0;
|
|
} |