-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~"))
|
||||
{
|
||||
static "~RetType.stringof~" call" ~ func
|
||||
~ "(void* system_pointer)
|
||||
~ "(ref ListenerCallData data)
|
||||
{
|
||||
Sys* s = cast(Sys*) system_pointer;
|
||||
Sys.EntitiesData data;
|
||||
"~ret_str~"s." ~ func ~ "(data);
|
||||
Sys* s = cast(Sys*) data.system.m_system_pointer;
|
||||
Sys.EntitiesData input_data;
|
||||
fillInputData(input_data, data.block.type_info, data.block, data.begin, data.end, data.system);
|
||||
"~ret_str~"s." ~ func ~ "(input_data);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
if(info.add_listeners)
|
||||
{
|
||||
foreach(i;block.entities_count..block.entities_count+block.added_count)
|
||||
{
|
||||
callAddEntityListeners(info,block,i);
|
||||
}
|
||||
callAddEntityListeners(info,block,block.entities_count,block.entities_count+block.added_count);
|
||||
}
|
||||
block.entities_count += block.added_count;
|
||||
if (block.entities_count > block.type_info.max_entities)
|
||||
|
|
@ -2275,6 +2278,14 @@ class EntityManager
|
|||
ushort end;
|
||||
}
|
||||
|
||||
struct ListenerCallData
|
||||
{
|
||||
System* system;
|
||||
EntitiesBlock* block;
|
||||
uint begin;
|
||||
uint end;
|
||||
}
|
||||
|
||||
struct Job
|
||||
{
|
||||
CallData[] callers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue