-removed system components sorting due to fact that it's make an issue

-workaround for DMD phobos issues
This commit is contained in:
Mergul 2018-10-02 15:36:00 +02:00
parent 2004909642
commit fddfc78ec1
4 changed files with 44 additions and 42 deletions

View file

@ -2,5 +2,5 @@ module ecs.attributes;
///Used to mark optional components for system. ///Used to mark optional components for system.
enum optional = "optional"; enum optional = "optional";
///Used to mark absen components for system. Enum 'AbsenComponents' should be used instead of it. ///Used to mark absent components for system. Enum 'AbsentComponents' should be used instead of it.
enum absen = "absen"; enum absent = "absent";

View file

@ -99,11 +99,11 @@ class EntityManager
static assert(0, "EntitiesData members should be arrays of elements!"); static assert(0, "EntitiesData members should be arrays of elements!");
} }
string ret;// = "ushort comp;uint req;uint opt;uint absen;"; string ret;// = "ushort comp;uint req;uint opt;uint absent;";
uint req; uint req;
uint opt; uint opt;
uint absen; uint absent;
foreach (member; __traits(allMembers, Sys.EntitiesData)) foreach (member; __traits(allMembers, Sys.EntitiesData))
{ {
if (member == "length" || is(typeof(__traits(getMember, Sys.EntitiesData, if (member == "length" || is(typeof(__traits(getMember, Sys.EntitiesData,
@ -126,9 +126,9 @@ class EntityManager
has_att = true; has_att = true;
break; break;
} }
else if (att == "absen") else if (att == "absent")
{ {
absen++; absent++;
//ret ~= "absen++;"; //ret ~= "absen++;";
has_att = true; has_att = true;
break; break;
@ -140,39 +140,39 @@ class EntityManager
} }
} }
static if(__traits(hasMember, Sys, "AbsenComponents")) static if(__traits(hasMember, Sys, "AbsentComponents"))
{ {
static if(is(Sys.AbsenComponents == enum)) static if(is(Sys.AbsentComponents == enum))
{ {
absen += (Fields!(Sys.AbsenComponents)).length;//static assert(0,"Enum AbsenComponents are not implemented yet."); absent += (Fields!(Sys.AbsentComponents)).length;//static assert(0,"Enum AbsentComponents are not implemented yet.");
} }
else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsenComponents))) && allSameType!(string,typeof(Sys.AbsenComponents)) && else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsentComponents))) && allSameType!(string,typeof(Sys.AbsentComponents)) &&
isExpressions!(Sys.AbsenComponents)) isExpressions!(Sys.AbsentComponents))
{ {
absen += Sys.AbsenComponents.length; absent += Sys.AbsentComponents.length;
} }
} }
if(req > 0)ret ~= "system.m_components = Mallocator.instance.makeArray!ushort("~req.to!string~");"; if(req > 0)ret ~= "system.m_components = Mallocator.instance.makeArray!ushort("~req.to!string~");";
if(opt > 0)ret ~= "system.m_optional_components = Mallocator.instance.makeArray!ushort("~opt.to!string~");"; if(opt > 0)ret ~= "system.m_optional_components = Mallocator.instance.makeArray!ushort("~opt.to!string~");";
if(absen > 0)ret ~= "system.m_absen_components = Mallocator.instance.makeArray!ushort("~absen.to!string~");"; if(absent > 0)ret ~= "system.m_absent_components = Mallocator.instance.makeArray!ushort("~absent.to!string~");";
ret ~= "ushort comp;";//uint opt = 0;uint req = 0;uint absen = 0;"; ret ~= "ushort comp;";//uint opt = 0;uint req = 0;uint absent = 0;";
opt = 0; opt = 0;
req = 0; req = 0;
absen = 0; absent = 0;
static if(__traits(hasMember, Sys, "AbsenComponents")) static if(__traits(hasMember, Sys, "AbsentComponents"))
{ {
static if(is(Sys.AbsenComponents == enum)) static if(is(Sys.AbsentComponents == enum))
{ {
//static assert(0,"Enum AbsenComponents are not implemented yet."); //static assert(0,"Enum AbsentComponents are not implemented yet.");
foreach(str;Fields!(Sys.AbsenComponents))ret ~= "system.m_absen_components["~(absen++).to!string~"] = components_map.get(\""~str.stringof~"\", ushort.max);"; foreach(str;Fields!(Sys.AbsentComponents))ret ~= "system.m_absent_components["~(absent++).to!string~"] = components_map.get(\""~str.stringof~"\", ushort.max);";
} }
else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsenComponents))) && allSameType!(string,typeof(Sys.AbsenComponents)) && else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsentComponents))) && allSameType!(string,typeof(Sys.AbsentComponents)) &&
isExpressions!(Sys.AbsenComponents)) isExpressions!(Sys.AbsentComponents))
{ {
foreach(str;Sys.AbsenComponents)ret ~= "system.m_absen_components["~(absen++).to!string~"] = components_map.get(\""~str~"\", ushort.max);"; foreach(str;Sys.AbsentComponents)ret ~= "system.m_absent_components["~(absent++).to!string~"] = components_map.get(\""~str~"\", ushort.max);";
} }
} }
@ -208,9 +208,9 @@ class EntityManager
has_att = true; has_att = true;
break; break;
} }
else if (att == "absen") else if (att == "absent")
{ {
ret ~= "system.m_absen_components["~(absen++).to!string~"] = comp;}"; ret ~= "system.m_absent_components["~(absent++).to!string~"] = comp;}";
has_att = true; has_att = true;
break; break;
} }
@ -246,7 +246,7 @@ class EntityManager
ushort comp; ushort comp;
uint req = 0; uint req = 0;
uint opt = 0; uint opt = 0;
uint absen = 0; uint absent = 0;
foreach (member; __traits(allMembers, Sys.EntitiesData)) foreach (member; __traits(allMembers, Sys.EntitiesData))
{ {
if (is(typeof(__traits(getMember, Sys.EntitiesData, if (is(typeof(__traits(getMember, Sys.EntitiesData,
@ -282,9 +282,9 @@ class EntityManager
has_att = true; has_att = true;
break; break;
} }
else if (att == "absen") else if (att == "absent")
{ {
absen++; absent++;
has_att = true; has_att = true;
break; break;
} }
@ -354,9 +354,9 @@ class EntityManager
mixin(genCompList()); mixin(genCompList());
if(system.m_components)qsort(system.m_components.ptr, system.m_components.length, ushort.sizeof, &compareUShorts); /*if(system.m_components)qsort(system.m_components.ptr, system.m_components.length, ushort.sizeof, &compareUShorts);
if(system.m_optional_components)qsort(system.m_optional_components.ptr, system.m_optional_components.length, ushort.sizeof, &compareUShorts); if(system.m_optional_components)qsort(system.m_optional_components.ptr, system.m_optional_components.length, ushort.sizeof, &compareUShorts);
if(system.m_absen_components)qsort(system.m_absen_components.ptr, system.m_absen_components.length, ushort.sizeof, &compareUShorts); if(system.m_absent_components)qsort(system.m_absent_components.ptr, system.m_absent_components.length, ushort.sizeof, &compareUShorts);*/
ushort sys_id = systems_map.get(Sys.stringof, ushort.max); ushort sys_id = systems_map.get(Sys.stringof, ushort.max);
if (sys_id < systems.length) if (sys_id < systems.length)
@ -653,9 +653,9 @@ class EntityManager
System* system = &systems[system_id]; System* system = &systems[system_id];
CallData call_data = CallData(system_id, system, &entity); CallData call_data = CallData(system_id, system, &entity);
if(system.m_absen_components) if(system.m_absent_components)
{ {
foreach (id; system.m_absen_components) foreach (id; system.m_absent_components)
{ {
foreach (id2; entity.components) foreach (id2; entity.components)
{ {

View file

@ -58,13 +58,13 @@ package:
///required components ///required components
ushort[] m_components; ushort[] m_components;
///absen components ///absent components
ushort[] m_absen_components; ushort[] m_absent_components;
///optional components ///optional components
ushort[] m_optional_components; ushort[] m_optional_components;
void function(ref EntityManager.CallData data) m_update; //void function(ref EntityManager.CallData data) m_update;
//void* m_update; ///workaroud for DMD bug with upper line void* m_update; ///workaroud for DMD bug with upper line
void function(void* system_pointer) m_enable; void function(void* system_pointer) m_enable;
void function(void* system_pointer) m_disable; void function(void* system_pointer) m_disable;
@ -75,6 +75,8 @@ package:
void function(void* system_pointer) m_begin; void function(void* system_pointer) m_begin;
void function(void* system_pointer) m_end; void function(void* system_pointer) m_end;
void function(ref EntityManager.CallData data) m_initialize; //void function(ref EntityManager.CallData data) m_initialize;
void function(ref EntityManager.CallData data) m_deinitilize; //void function(ref EntityManager.CallData data) m_deinitilize;
void* m_initialize;
void* m_deinitilize;
} }

View file

@ -131,7 +131,7 @@ int main()
TestComp[] test; TestComp[] test;
TestComp2[] test2; TestComp2[] test2;
@optional TestComp3[] test3; @optional TestComp3[] test3;
//@absen TestComp4[] test4; //@absent TestComp4[] test4;
} }
void update(ref Entity entity, ref TestComp test, ref TestComp2 test2)//, TestComp3* test3) //ref TestComp comp) void update(ref Entity entity, ref TestComp test, ref TestComp2 test2)//, TestComp3* test3) //ref TestComp comp)
@ -194,22 +194,22 @@ import std.meta;
{ {
__gshared ushort system_id; __gshared ushort system_id;
enum AbsenComponents0 enum AbsentComponents0
{ {
TestComp, TestComp,
TestComp4 TestComp4
} }
alias AbsenComponents = AliasSeq!("TestComp", "TestComp4"); alias AbsentComponents = AliasSeq!("TestComp", "TestComp4");
string AbsenComponents2; string AbsentComponents2;
static struct EntitiesData static struct EntitiesData
{ {
short length; short length;
Entity[] entity; Entity[] entity;
TestComp3[] test; TestComp3[] test;
//@absen TestComp[] testt; //@absent TestComp[] testt;
} }
void onEnable() void onEnable()