-working onAdd listener when new Entity is added to EntityManager
This commit is contained in:
parent
3aad89fc56
commit
1841c9c244
2 changed files with 25 additions and 18 deletions
|
|
@ -723,11 +723,12 @@ class EntityManager
|
||||||
is(ReturnType!(Sys."~func~") == "~RetType.stringof~"))
|
is(ReturnType!(Sys."~func~") == "~RetType.stringof~"))
|
||||||
{
|
{
|
||||||
static "~RetType.stringof~" call" ~ func
|
static "~RetType.stringof~" call" ~ func
|
||||||
~ "(void* system_pointer)
|
~ "(ref ListenerCallData data)
|
||||||
{
|
{
|
||||||
Sys* s = cast(Sys*) system_pointer;
|
Sys* s = cast(Sys*) data.system.m_system_pointer;
|
||||||
Sys.EntitiesData data;
|
Sys.EntitiesData input_data;
|
||||||
"~ret_str~"s." ~ func ~ "(data);
|
fillInputData(input_data, data.block.type_info, data.block, data.begin, data.end, data.system);
|
||||||
|
"~ret_str~"s." ~ func ~ "(input_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
system."
|
system."
|
||||||
|
|
@ -1833,12 +1834,17 @@ class EntityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callAddEntityListeners(EntityInfo* info, EntitiesBlock* block, int entity_index)
|
private void callAddEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin, int end)
|
||||||
{
|
{
|
||||||
foreach(listener;info.add_listeners)
|
foreach(listener;info.add_listeners)
|
||||||
{
|
{
|
||||||
System* system = &systems[listener];
|
System* system = &systems[listener];
|
||||||
(cast(void function (System*)) system.m_entity_added)(system);
|
ListenerCallData data;
|
||||||
|
data.system = system;
|
||||||
|
data.block = block;
|
||||||
|
data.begin = begin;
|
||||||
|
data.end = end;
|
||||||
|
(cast(void function (ref ListenerCallData)) system.m_entity_added)(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1851,10 +1857,7 @@ class EntityManager
|
||||||
EntityInfo* info = block.type_info;
|
EntityInfo* info = block.type_info;
|
||||||
if(info.add_listeners)
|
if(info.add_listeners)
|
||||||
{
|
{
|
||||||
foreach(i;block.entities_count..block.entities_count+block.added_count)
|
callAddEntityListeners(info,block,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)
|
||||||
|
|
@ -2275,6 +2278,14 @@ class EntityManager
|
||||||
ushort end;
|
ushort end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ListenerCallData
|
||||||
|
{
|
||||||
|
System* system;
|
||||||
|
EntitiesBlock* block;
|
||||||
|
uint begin;
|
||||||
|
uint end;
|
||||||
|
}
|
||||||
|
|
||||||
struct Job
|
struct Job
|
||||||
{
|
{
|
||||||
CallData[] callers;
|
CallData[] callers;
|
||||||
|
|
|
||||||
|
|
@ -110,18 +110,14 @@ struct TestSystem
|
||||||
|
|
||||||
void onAdd(EntitiesData data)
|
void onAdd(EntitiesData data)
|
||||||
{
|
{
|
||||||
//writeln("Entity added ID: ");//,data.entites[0].id);
|
//foreach(i;0..data.length)
|
||||||
|
//writeln("Entity added ID: ",data.entites[i].id.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void onAdd()
|
/*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()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue