-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.
enum optional = "optional";
///Used to mark absen components for system. Enum 'AbsenComponents' should be used instead of it.
enum absen = "absen";
///Used to mark absent components for system. Enum 'AbsentComponents' should be used instead of it.
enum absent = "absent";

View file

@ -99,11 +99,11 @@ class EntityManager
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 opt;
uint absen;
uint absent;
foreach (member; __traits(allMembers, Sys.EntitiesData))
{
if (member == "length" || is(typeof(__traits(getMember, Sys.EntitiesData,
@ -126,9 +126,9 @@ class EntityManager
has_att = true;
break;
}
else if (att == "absen")
else if (att == "absent")
{
absen++;
absent++;
//ret ~= "absen++;";
has_att = true;
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)) &&
isExpressions!(Sys.AbsenComponents))
else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsentComponents))) && allSameType!(string,typeof(Sys.AbsentComponents)) &&
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(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~");";
ret ~= "ushort comp;";//uint opt = 0;uint req = 0;uint absen = 0;";
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 absent = 0;";
opt = 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.");
foreach(str;Fields!(Sys.AbsenComponents))ret ~= "system.m_absen_components["~(absen++).to!string~"] = components_map.get(\""~str.stringof~"\", ushort.max);";
//static assert(0,"Enum AbsentComponents are not implemented yet.");
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)) &&
isExpressions!(Sys.AbsenComponents))
else static if(__traits(compiles,allSameType!(string,typeof(Sys.AbsentComponents))) && allSameType!(string,typeof(Sys.AbsentComponents)) &&
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;
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;
break;
}
@ -246,7 +246,7 @@ class EntityManager
ushort comp;
uint req = 0;
uint opt = 0;
uint absen = 0;
uint absent = 0;
foreach (member; __traits(allMembers, Sys.EntitiesData))
{
if (is(typeof(__traits(getMember, Sys.EntitiesData,
@ -282,9 +282,9 @@ class EntityManager
has_att = true;
break;
}
else if (att == "absen")
else if (att == "absent")
{
absen++;
absent++;
has_att = true;
break;
}
@ -354,9 +354,9 @@ class EntityManager
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_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);
if (sys_id < systems.length)
@ -653,9 +653,9 @@ class EntityManager
System* system = &systems[system_id];
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)
{

View file

@ -58,13 +58,13 @@ package:
///required components
ushort[] m_components;
///absen components
ushort[] m_absen_components;
///absent components
ushort[] m_absent_components;
///optional components
ushort[] m_optional_components;
void function(ref EntityManager.CallData data) m_update;
//void* m_update; ///workaroud for DMD bug with upper line
//void function(ref EntityManager.CallData data) m_update;
void* m_update; ///workaroud for DMD bug with upper line
void function(void* system_pointer) m_enable;
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_end;
void function(ref EntityManager.CallData data) m_initialize;
void function(ref EntityManager.CallData data) m_deinitilize;
//void function(ref EntityManager.CallData data) m_initialize;
//void function(ref EntityManager.CallData data) m_deinitilize;
void* m_initialize;
void* m_deinitilize;
}