-fillInputData created as local function in register process

-call onAdd (WIP)
This commit is contained in:
Mergul 2019-03-23 20:18:26 +00:00
parent 6bbc8b5152
commit 3aad89fc56
2 changed files with 79 additions and 54 deletions

View file

@ -566,78 +566,85 @@ class EntityManager
return ret;
}
static if (hasMember!(Sys, "update") && (mixin(genParamsChecking())))
static string genFillInputData()()
{
static string genFillInputData()()
string ret;
ushort comp;
uint req = 0;
uint opt = 0;
uint excluded = 0;
foreach (member; __traits(allMembers, Sys.EntitiesData))
{
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
{
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)))
{
bool has_att = false;
foreach (att; __traits(getAttributes,
__traits(getMember, Sys.EntitiesData, member)))
if (att == "optional")
{
if (att == "optional")
{
ret ~= "if(data.system.m_optional_components[" ~ opt.to!string
~ "] < info.deltas.length && info.deltas[ data.system.m_optional_components["
~ opt.to!string ~ "]] != 0)input_data." ~ member
~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member
~ "))*)(cast(void*) block + info.deltas[ data.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;
}
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;
}
if (!has_att)
else if (att == "excluded")
{
ret ~= "input_data." ~ member ~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member
~ "))*)(cast(void*) block + info.deltas[ data.system.m_components["
~ req.to!string ~ "]]))[offset .. entities_count];";
req++;
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;
}
return ret;
}
//pragma(msg,genFillInputData);
//pragma(msg,genFillInputData);
static void fillInputData(ref Sys.EntitiesData input_data, EntityInfo* info, EntitiesBlock* block,
uint offset, uint entities_count, System* system)
{
mixin(genFillInputData());
}
static if (hasMember!(Sys, "update") && (mixin(genParamsChecking())))
{
static void callUpdate(ref CallData data)
{
Sys* s = cast(Sys*) data.system.m_system_pointer;
Sys.EntitiesData input_data;
EntityInfo* info = data.info; //block.type_info;
System* system = data.system;
EntitiesBlock* block;
if (data.first_block)
@ -667,7 +674,8 @@ class EntityManager
assert(entities_count <= block.entities_count && offset <= block.entities_count);
mixin(genFillInputData());
fillInputData(input_data, info, block, offset, entities_count, system);
//mixin(genFillInputData());
s.update(input_data);
@ -1825,12 +1833,29 @@ class EntityManager
}
}
private void callAddEntityListeners(EntityInfo* info, EntitiesBlock* block, int entity_index)
{
foreach(listener;info.add_listeners)
{
System* system = &systems[listener];
(cast(void function (System*)) system.m_entity_added)(system);
}
}
private void updateBlocks()
{
foreach (ref thread; threads)
{
foreach (block; thread.blocks_to_update)
{
EntityInfo* info = block.type_info;
if(info.add_listeners)
{
foreach(i;block.entities_count..block.entities_count+block.added_count)
{
callAddEntityListeners(info,block,i);
}
}
block.entities_count += block.added_count;
if (block.entities_count > block.type_info.max_entities)
{