bubel-ecs/tests/tests.d

122 lines
No EOL
2.1 KiB
D

module tests.tests;
import ecs.manager;
import ecs.events;
import ecs.system;
import ecs.entity;
int main()
{
return 0;
}
unittest
{
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 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);
gEM.registerComponent!TestComp2;
gEM.registerComponent!TestComp;
gEM.registerSystem!TestSystem(0);
gEM.registerSystem!TestSystem2(0);
ushort[2] ids = [0,1];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
*cast(EntityID*)tmpl.entity_data.ptr = EntityID(1,1);
foreach(i; 0..1_000_000)gEM.addEntity(tmpl);
//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));
gEM.update();
gEM.update();
import std.stdio;
writeln((cast(uint*)tmpl.info.first_block)[0..48]);
gEM.freeTemplate(tmpl);
}