-removed mixin genFillInputData

This commit is contained in:
Mergul 2019-04-06 18:41:48 +00:00
parent a93529dad1
commit a5eade669e

View file

@ -312,14 +312,19 @@ class EntityManager
} }
} }
static struct CompInfo
{
string name;
string type;
}
static struct ComponentsIndices static struct ComponentsIndices
{ {
string[] readonly; CompInfo[] readonly;
string[] excluded; CompInfo[] excluded;
string[] optional; CompInfo[] optional;
string[] mutable; CompInfo[] mutable;
string[] req; CompInfo[] req;
} }
static void allocateSystemComponents(ComponentsIndices components_info)(ref System system) static void allocateSystemComponents(ComponentsIndices components_info)(ref System system)
@ -392,27 +397,27 @@ class EntityManager
} }
if (is_read_only) if (is_read_only)
{ {
components_info.readonly ~= name; components_info.readonly ~= CompInfo(member,name);
} }
else else
{ {
components_info.mutable ~= name; components_info.mutable ~= CompInfo(member,name);
} }
if (is_excluded) if (is_excluded)
{ {
components_info.excluded ~= name; components_info.excluded ~= CompInfo(member,name);
} }
if (is_optional) if (is_optional)
{ {
components_info.optional ~= name; components_info.optional ~= CompInfo(member,name);
} }
if (is_read_only) if (is_read_only)
{ {
components_info.readonly ~= name; components_info.readonly ~= CompInfo(member,name);
} }
if (is_excluded == false && is_optional == false) if (is_excluded == false && is_optional == false)
{ //is Req { //is Req
components_info.req ~= name; components_info.req ~= CompInfo(member,name);
} }
assert(!(is_optional && is_excluded), assert(!(is_optional && is_excluded),
@ -467,107 +472,78 @@ class EntityManager
enum ComponentsIndices components_info = getComponentsInfo(); enum ComponentsIndices components_info = getComponentsInfo();
allocateSystemComponents!(components_info)(system); allocateSystemComponents!(components_info)(system);
foreach (iii, name; components_info.req) foreach (iii, comp_info; components_info.req)
{ {
ushort comp = components_map.get(cast(char[]) name, ushort.max); ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\"."); assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
system.m_components[iii] = comp; system.m_components[iii] = comp;
} }
foreach (iii, name; components_info.excluded) foreach (iii, comp_info; components_info.excluded)
{ {
ushort comp = components_map.get(cast(char[]) name, ushort.max); ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\"."); assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
system.m_excluded_components[iii] = comp; system.m_excluded_components[iii] = comp;
} }
foreach (iii, name; components_info.optional) foreach (iii, comp_info; components_info.optional)
{ {
ushort comp = components_map.get(cast(char[]) name, ushort.max); ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\"."); assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
system.m_optional_components[iii] = comp; system.m_optional_components[iii] = comp;
} }
foreach (iii, name; components_info.readonly) foreach (iii, comp_info; components_info.readonly)
{ {
ushort comp = components_map.get(cast(char[]) name, ushort.max); ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\"."); assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
system.m_read_only_components[iii] = comp; system.m_read_only_components[iii] = comp;
} }
foreach (iii, name; components_info.mutable) foreach (iii, comp_info; components_info.mutable)
{ {
ushort comp = components_map.get(cast(char[]) name, ushort.max); ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\"."); assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~comp_info.type~"\".");
system.m_modified_components[iii] = comp; system.m_modified_components[iii] = comp;
} }
} }
static string genFillInputData()()
{
string ret;
ushort comp;
uint req = 0;
uint opt = 0;
uint excluded = 0;
foreach (member; __traits(allMembers, Sys.EntitiesData))
{
if (is(typeof(__traits(getMember, Sys.EntitiesData,
member)) == Entity[]) || is(typeof(__traits(getMember,
Sys.EntitiesData, member)) == const(Entity)[]))
{
ret ~= "input_data." ~ member
~ " = (cast(Entity*) block.dataBegin())[offset .. entities_count];";
}
else if (member == "length")
{
ret ~= "input_data." ~ member
~ " = cast(typeof(input_data.length))(entities_count - offset);";
}
else
{
{
bool has_att = false;
foreach (att; __traits(getAttributes,
__traits(getMember, Sys.EntitiesData, member)))
{
if (att == "optional")
{
ret ~= "if(system.m_optional_components[" ~ opt.to!string
~ "] < info.deltas.length && info.deltas[ system.m_optional_components["
~ opt.to!string ~ "]] != 0)input_data." ~ member
~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member
~ "))*)(cast(void*) block + info.deltas[ system.m_optional_components["
~ opt.to!string ~ "]]))[offset .. entities_count];
else input_data."
~ member ~ " = null;";
opt++;
has_att = true;
break;
}
else if (att == "excluded")
{
excluded++;
has_att = true;
break;
}
}
if (!has_att)
{
ret ~= "input_data." ~ member ~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member
~ "))*)(cast(void*) block + info.deltas[ system.m_components["
~ req.to!string ~ "]]))[offset .. entities_count];";
req++;
}
}
}
}
return ret;
}
//pragma(msg,genFillInputData);
static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info, static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info,
EntitiesBlock* block, uint offset, uint entities_count, System* system) EntitiesBlock* block, uint offset, uint entities_count, System* system)
{ {
mixin(genFillInputData()); enum ComponentsIndices components_info = getComponentsInfo();
static foreach (member; __traits(allMembers, Sys.EntitiesData))
{
static if (is(typeof(__traits(getMember, Sys.EntitiesData,
member)) == Entity[]) || is(typeof(__traits(getMember,
Sys.EntitiesData, member)) == const(Entity)[]))
{
__traits(getMember, input_data, member) = (cast(Entity*) block.dataBegin())[offset .. entities_count];
}
else static if (member == "length")
{
__traits(getMember, input_data, member) = cast(typeof(input_data.length))(entities_count - offset);
}
else
{
}
}
static foreach (iii, comp_info; components_info.req)
{
__traits(getMember, input_data, comp_info.name) =
(cast(ForeachType!(typeof(__traits(getMember,
Sys.EntitiesData, comp_info.name)))*)(cast(void*) block + info.deltas[ system.m_components[iii]]))[offset .. entities_count];
}
static foreach (iii, comp_info; components_info.optional)
{
if(system.m_optional_components[iii] < info.deltas.length && info.deltas[system.m_optional_components[iii]] != 0)
{
__traits(getMember, input_data, comp_info.name) =
(cast(ForeachType!(typeof(__traits(getMember,
Sys.EntitiesData, comp_info.name)))*)(cast(void*) block + info.deltas[ system.m_optional_components[iii]]))[offset .. entities_count];
}
}
} }
bool checkOnUpdateParams()() bool checkOnUpdateParams()()