-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; 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; if (is(typeof(__traits(getMember, Sys.EntitiesData,
ushort comp; member)) == Entity[]) || is(typeof(__traits(getMember,
uint req = 0; Sys.EntitiesData, member)) == const(Entity)[]))
uint opt = 0; {
uint excluded = 0; ret ~= "input_data." ~ member
foreach (member; __traits(allMembers, Sys.EntitiesData)) ~ " = (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; if (att == "optional")
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["
ret ~= "if(data.system.m_optional_components[" ~ opt.to!string ~ opt.to!string ~ "]] != 0)input_data." ~ member
~ "] < info.deltas.length && info.deltas[ data.system.m_optional_components[" ~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member
~ opt.to!string ~ "]] != 0)input_data." ~ member ~ "))*)(cast(void*) block + info.deltas[ system.m_optional_components["
~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member ~ opt.to!string ~ "]]))[offset .. entities_count];
~ "))*)(cast(void*) block + info.deltas[ data.system.m_optional_components[" else input_data."
~ opt.to!string ~ "]]))[offset .. entities_count]; ~ member ~ " = null;";
else input_data." opt++;
~ member ~ " = null;"; has_att = true;
opt++; break;
has_att = true;
break;
}
else if (att == "excluded")
{
excluded++;
has_att = true;
break;
}
} }
if (!has_att) else if (att == "excluded")
{ {
ret ~= "input_data." ~ member ~ " = (cast(ForeachType!(typeof(Sys.EntitiesData." ~ member excluded++;
~ "))*)(cast(void*) block + info.deltas[ data.system.m_components[" has_att = true;
~ req.to!string ~ "]]))[offset .. entities_count];"; break;
req++;
} }
} }
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) static void callUpdate(ref CallData data)
{ {
Sys* s = cast(Sys*) data.system.m_system_pointer; Sys* s = cast(Sys*) data.system.m_system_pointer;
Sys.EntitiesData input_data; Sys.EntitiesData input_data;
EntityInfo* info = data.info; //block.type_info; EntityInfo* info = data.info; //block.type_info;
System* system = data.system;
EntitiesBlock* block; EntitiesBlock* block;
if (data.first_block) if (data.first_block)
@ -667,7 +674,8 @@ class EntityManager
assert(entities_count <= block.entities_count && offset <= block.entities_count); 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); 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() private void updateBlocks()
{ {
foreach (ref thread; threads) foreach (ref thread; threads)
{ {
foreach (block; thread.blocks_to_update) 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; block.entities_count += block.added_count;
if (block.entities_count > block.type_info.max_entities) if (block.entities_count > block.type_info.max_entities)
{ {

View file

@ -110,7 +110,7 @@ struct TestSystem
void onAdd(EntitiesData data) void onAdd(EntitiesData data)
{ {
writeln("Entity added ID: ",data.entites[0].id); //writeln("Entity added ID: ");//,data.entites[0].id);
} }
/*void onAdd() /*void onAdd()
@ -120,7 +120,7 @@ struct TestSystem
void onRemove(EntitiesData data) void onRemove(EntitiesData data)
{ {
writeln("Entity destroyed ID: ",data.entites[0].id); //writeln("Entity destroyed ID: ",data.entites[0].id);
} }
bool onBegin() bool onBegin()