-Systems, Components and Events now must have proper mixin. Mixins are located in ecs.core module. (i.e. mixin ECS.Component)
-Multithreading support: *multithreaded update - updateMT(), function generates jobs to execute *added dispatch callback function to dispatch generated jobs (setJobDispachFunc) *added getID callback for get thread ID by EntityManager -added Job structure. Job has one function "execute()". -calling partial info update (required to multithreading) -multithreaded removeEntity, addCompoenents, removeComponents. Every thread has own data and remove/change lists. -multithreaded addEntity (WIP) -fixed issue with duplicating components -simpler and faster "findBlockWithFreeSpace" function -CallDataAllocator, allocator for CallDatas (used for Jobs) -fixed some bugs/issues
This commit is contained in:
parent
3a767babc0
commit
5dd24b6462
6 changed files with 519 additions and 135 deletions
|
|
@ -5,6 +5,7 @@ import ecs.events;
|
|||
import ecs.manager;
|
||||
import ecs.system;
|
||||
import ecs.attributes;
|
||||
import ecs.core;
|
||||
|
||||
import core.time;
|
||||
import std.stdio;
|
||||
|
|
@ -14,19 +15,19 @@ int main()
|
|||
|
||||
struct TestEvent
|
||||
{
|
||||
__gshared ushort event_id;
|
||||
mixin ECS.Event;//__gshared ushort event_id;
|
||||
int a;
|
||||
}
|
||||
|
||||
struct TestEvent2
|
||||
{
|
||||
__gshared ushort event_id;
|
||||
mixin ECS.Event;//__gshared ushort event_id;
|
||||
float a;
|
||||
}
|
||||
|
||||
static struct TestComp
|
||||
{
|
||||
__gshared ushort component_id;
|
||||
mixin ECS.Component;//__gshared ushort component_id;
|
||||
int a = 1;
|
||||
ulong b = 2;
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ int main()
|
|||
|
||||
static struct TestComp2
|
||||
{
|
||||
__gshared ushort component_id;
|
||||
mixin ECS.Component;//__gshared ushort component_id;
|
||||
int b = 3;
|
||||
int a = 4;
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ int main()
|
|||
|
||||
static struct TestComp3
|
||||
{
|
||||
__gshared ushort component_id;
|
||||
mixin ECS.Component;//__gshared ushort component_id;
|
||||
uint gg = 5; //good game
|
||||
uint bg = 6; //bad game
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ int main()
|
|||
|
||||
static struct TestComp4
|
||||
{
|
||||
__gshared ushort component_id;
|
||||
mixin ECS.Component;//__gshared ushort component_id;
|
||||
uint gg = 7; //good game
|
||||
uint bg = 8; //bad game
|
||||
ulong a = 9;
|
||||
|
|
@ -98,7 +99,7 @@ int main()
|
|||
|
||||
struct TestSystem
|
||||
{
|
||||
__gshared ushort system_id;
|
||||
mixin ECS.System!16;//__gshared ushort system_id;
|
||||
|
||||
void onCreate()
|
||||
{
|
||||
|
|
@ -146,7 +147,7 @@ int main()
|
|||
test2.a = 8;
|
||||
}
|
||||
|
||||
void update(ref EntitiesData data)
|
||||
void update(EntitiesData data)
|
||||
{
|
||||
foreach(i;0..data.length)
|
||||
{
|
||||
|
|
@ -165,7 +166,7 @@ int main()
|
|||
|
||||
struct TestSystemWithHighPriority
|
||||
{
|
||||
__gshared ushort system_id;
|
||||
mixin ECS.System!16;//__gshared ushort system_id;
|
||||
|
||||
static struct EntitiesData
|
||||
{
|
||||
|
|
@ -177,7 +178,7 @@ int main()
|
|||
|
||||
}
|
||||
|
||||
void update(ref EntitiesData data)
|
||||
void update(EntitiesData data)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -192,7 +193,7 @@ import std.meta;
|
|||
|
||||
struct TestSystem2
|
||||
{
|
||||
__gshared ushort system_id;
|
||||
mixin ECS.System!16;//__gshared ushort system_id;
|
||||
|
||||
enum AbsentComponents0
|
||||
{
|
||||
|
|
@ -255,6 +256,15 @@ import std.meta;
|
|||
}*/
|
||||
}
|
||||
|
||||
void dispatch(EntityManager.Job[] jobs)
|
||||
{
|
||||
foreach(job;jobs)
|
||||
{
|
||||
//writeln(job);
|
||||
job.execute();
|
||||
}
|
||||
}
|
||||
|
||||
void writeEntityComponents(Entity* entity)
|
||||
{
|
||||
write(entity.id);
|
||||
|
|
@ -270,7 +280,8 @@ import std.meta;
|
|||
//writeln((cast(uint*) pp)[0 .. 14], " ", pp);
|
||||
}
|
||||
|
||||
EntityManager.initialize();
|
||||
EntityManager.initialize(1);
|
||||
gEM.setJobDispachFunc(&dispatch);
|
||||
assert(gEM !is null);
|
||||
|
||||
MonoTime time = MonoTime.currTime;
|
||||
|
|
@ -358,40 +369,49 @@ import std.meta;
|
|||
//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));
|
||||
|
||||
Entity entity2;
|
||||
|
||||
foreach (i; 0 .. 500_000)
|
||||
{
|
||||
gEM.addEntity(tmpl);
|
||||
entity2 = gEM.addEntity(tmpl);
|
||||
gEM.addEntity(tmpl2);
|
||||
}
|
||||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
gEM.begin();
|
||||
//gEM.updateMT();
|
||||
gEM.update();
|
||||
gEM.end();
|
||||
|
||||
dur = (MonoTime.currTime - time).total!"usecs";
|
||||
writeln("Update: ", dur, " usecs");
|
||||
|
||||
writeEntityComponents(gEM.getEntity(entity2.id));
|
||||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
gEM.begin();
|
||||
gEM.update();
|
||||
gEM.updateMT();
|
||||
//gEM.update();
|
||||
gEM.end();
|
||||
|
||||
dur = (MonoTime.currTime - time).total!"usecs";
|
||||
writeln("Update: ", dur, " usecs");
|
||||
|
||||
writeEntityComponents(gEM.getEntity(entity2.id));
|
||||
|
||||
time = MonoTime.currTime;
|
||||
|
||||
gEM.begin();
|
||||
gEM.update();
|
||||
gEM.updateMT();
|
||||
//gEM.update();
|
||||
gEM.end();
|
||||
|
||||
dur = (MonoTime.currTime - time).total!"usecs";
|
||||
writeln("Update: ", dur, " usecs");
|
||||
|
||||
writeEntityComponents(gEM.getEntity(entity.id));
|
||||
writeEntityComponents(gEM.getEntity(entity2.id));
|
||||
|
||||
entity = gEM.addEntity(tmpl);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue