-removed mixin genFillInputData
This commit is contained in:
parent
a93529dad1
commit
a5eade669e
1 changed files with 68 additions and 92 deletions
|
|
@ -312,14 +312,19 @@ class EntityManager
|
|||
}
|
||||
}
|
||||
|
||||
static struct CompInfo
|
||||
{
|
||||
string name;
|
||||
string type;
|
||||
}
|
||||
|
||||
static struct ComponentsIndices
|
||||
{
|
||||
string[] readonly;
|
||||
string[] excluded;
|
||||
string[] optional;
|
||||
string[] mutable;
|
||||
string[] req;
|
||||
|
||||
CompInfo[] readonly;
|
||||
CompInfo[] excluded;
|
||||
CompInfo[] optional;
|
||||
CompInfo[] mutable;
|
||||
CompInfo[] req;
|
||||
}
|
||||
|
||||
static void allocateSystemComponents(ComponentsIndices components_info)(ref System system)
|
||||
|
|
@ -392,27 +397,27 @@ class EntityManager
|
|||
}
|
||||
if (is_read_only)
|
||||
{
|
||||
components_info.readonly ~= name;
|
||||
components_info.readonly ~= CompInfo(member,name);
|
||||
}
|
||||
else
|
||||
{
|
||||
components_info.mutable ~= name;
|
||||
components_info.mutable ~= CompInfo(member,name);
|
||||
}
|
||||
if (is_excluded)
|
||||
{
|
||||
components_info.excluded ~= name;
|
||||
components_info.excluded ~= CompInfo(member,name);
|
||||
}
|
||||
if (is_optional)
|
||||
{
|
||||
components_info.optional ~= name;
|
||||
components_info.optional ~= CompInfo(member,name);
|
||||
}
|
||||
if (is_read_only)
|
||||
{
|
||||
components_info.readonly ~= name;
|
||||
components_info.readonly ~= CompInfo(member,name);
|
||||
}
|
||||
if (is_excluded == false && is_optional == false)
|
||||
{ //is Req
|
||||
components_info.req ~= name;
|
||||
components_info.req ~= CompInfo(member,name);
|
||||
}
|
||||
|
||||
assert(!(is_optional && is_excluded),
|
||||
|
|
@ -467,107 +472,78 @@ class EntityManager
|
|||
enum ComponentsIndices components_info = getComponentsInfo();
|
||||
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);
|
||||
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\".");
|
||||
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 \""~comp_info.type~"\".");
|
||||
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);
|
||||
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\".");
|
||||
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 \""~comp_info.type~"\".");
|
||||
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);
|
||||
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\".");
|
||||
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 \""~comp_info.type~"\".");
|
||||
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);
|
||||
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\".");
|
||||
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 \""~comp_info.type~"\".");
|
||||
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);
|
||||
assert(comp != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing component \""~name~"\".");
|
||||
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 \""~comp_info.type~"\".");
|
||||
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,
|
||||
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()()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue