-onAdd/onRemove called when components are changed
This commit is contained in:
parent
e4be23ee96
commit
4ac80d7025
2 changed files with 131 additions and 14 deletions
|
|
@ -1284,9 +1284,12 @@ class EntityManager
|
|||
}
|
||||
|
||||
if (index < passes[system.m_pass].system_callers.length)
|
||||
{
|
||||
passes[system.m_pass].system_callers[index].infos.add(&entity);
|
||||
|
||||
entity.systems[system_id] = true;
|
||||
entity.systems[system_id] = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
|
|
@ -1365,6 +1368,18 @@ class EntityManager
|
|||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) >> 3);
|
||||
else
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) / EntityID.sizeof());
|
||||
|
||||
if(info.remove_listeners)
|
||||
{
|
||||
foreach(listener;info.remove_listeners)
|
||||
{
|
||||
if(!new_info.systems[listener])
|
||||
{
|
||||
callRemoveEntityListener(&systems[listener],info,block,ind,ind+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (comp; new_info.components)
|
||||
{
|
||||
uint comp_size = components[comp].size;
|
||||
|
|
@ -1372,6 +1387,17 @@ class EntityManager
|
|||
cast(void*) block + info.deltas[comp] + ind * comp_size, comp_size);
|
||||
}
|
||||
|
||||
if(new_info.add_listeners)
|
||||
{
|
||||
foreach(listener;new_info.add_listeners)
|
||||
{
|
||||
if(!info.systems[listener])
|
||||
{
|
||||
callAddEntityListener(&systems[listener],new_info,new_block,new_block.entities_count,new_block.entities_count+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_block.entities_count++;
|
||||
|
||||
removeEntityNoID(entity, block);
|
||||
|
|
@ -1495,6 +1521,18 @@ class EntityManager
|
|||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) >> 3);
|
||||
else
|
||||
uint ind = cast(uint)((cast(void*) entity - block.dataBegin()) / EntityID.sizeof());
|
||||
|
||||
if(info.remove_listeners)
|
||||
{
|
||||
foreach(listener;info.remove_listeners)
|
||||
{
|
||||
if(!new_info.systems[listener])
|
||||
{
|
||||
callRemoveEntityListener(&systems[listener],info,block,ind,ind+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ref id; ids[0 .. len])
|
||||
{
|
||||
void* dst = cast(void*) new_block + new_info.deltas[id] + (
|
||||
|
|
@ -1522,6 +1560,17 @@ class EntityManager
|
|||
}
|
||||
}
|
||||
|
||||
if(new_info.add_listeners)
|
||||
{
|
||||
foreach(listener;new_info.add_listeners)
|
||||
{
|
||||
if(!info.systems[listener])
|
||||
{
|
||||
callAddEntityListener(&systems[listener],new_info,new_block,new_block.entities_count,new_block.entities_count+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_block.entities_count++;
|
||||
removeEntityNoID(entity, block);
|
||||
}
|
||||
|
|
@ -1852,29 +1901,39 @@ class EntityManager
|
|||
foreach(listener;info.add_listeners)
|
||||
{
|
||||
System* system = &systems[listener];
|
||||
ListenerCallData data;
|
||||
data.system = system;
|
||||
data.block = block;
|
||||
data.begin = begin;
|
||||
data.end = end;
|
||||
(cast(void function (ref ListenerCallData) nothrow @nogc) system.m_entity_added)(data);
|
||||
callAddEntityListener(system,info,block,begin,end);
|
||||
}
|
||||
}
|
||||
|
||||
private void callAddEntityListener(System* system, EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||
{
|
||||
ListenerCallData data;
|
||||
data.system = system;
|
||||
data.block = block;
|
||||
data.begin = begin;
|
||||
data.end = end;
|
||||
(cast(void function (ref ListenerCallData) nothrow @nogc) system.m_entity_added)(data);
|
||||
}
|
||||
|
||||
private void callRemoveEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||
{
|
||||
foreach(listener;info.add_listeners)
|
||||
{
|
||||
System* system = &systems[listener];
|
||||
ListenerCallData data;
|
||||
data.system = system;
|
||||
data.block = block;
|
||||
data.begin = begin;
|
||||
data.end = end;
|
||||
(cast(void function (ref ListenerCallData) nothrow @nogc) system.m_entity_removed)(data);
|
||||
callRemoveEntityListener(system,info,block,begin,end);
|
||||
}
|
||||
}
|
||||
|
||||
private void callRemoveEntityListener(System* system, EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||
{
|
||||
ListenerCallData data;
|
||||
data.system = system;
|
||||
data.block = block;
|
||||
data.begin = begin;
|
||||
data.end = end;
|
||||
(cast(void function (ref ListenerCallData) nothrow @nogc) system.m_entity_removed)(data);
|
||||
}
|
||||
|
||||
private void updateBlocks()
|
||||
{
|
||||
foreach (ref thread; threads)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue