-onRemove() called when entity is removed from EntityManager
This commit is contained in:
parent
1841c9c244
commit
e4be23ee96
2 changed files with 31 additions and 4 deletions
|
|
@ -1718,6 +1718,19 @@ class EntityManager
|
|||
if (entity is null)
|
||||
return; //return if entity doesn't exist
|
||||
EntitiesBlock* block = getMetaData(entity);
|
||||
|
||||
EntityInfo* info = block.type_info;
|
||||
if(info.remove_listeners)
|
||||
{
|
||||
void* data_begin = block.dataBegin();
|
||||
static if (EntityID.sizeof == 8)
|
||||
uint pos = cast(uint)((cast(void*) entity - data_begin) >> 3);
|
||||
else
|
||||
uint pos = cast(uint)((cast(void*) entity - data_begin) / EntityID.sizeof());
|
||||
|
||||
callRemoveEntityListeners(info,block,pos,pos+1);
|
||||
}
|
||||
|
||||
id_manager.releaseID(id); //release id from manager
|
||||
|
||||
removeEntityNoID(entity, block, true);
|
||||
|
|
@ -1834,7 +1847,7 @@ class EntityManager
|
|||
}
|
||||
}
|
||||
|
||||
private void callAddEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin, int end)
|
||||
private void callAddEntityListeners(EntityInfo* info, EntitiesBlock* block, int begin, int end) @nogc nothrow
|
||||
{
|
||||
foreach(listener;info.add_listeners)
|
||||
{
|
||||
|
|
@ -1844,7 +1857,21 @@ class EntityManager
|
|||
data.block = block;
|
||||
data.begin = begin;
|
||||
data.end = end;
|
||||
(cast(void function (ref ListenerCallData)) system.m_entity_added)(data);
|
||||
(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ struct TestSystem
|
|||
//writeln("Entity added ID: ",data.entites[i].id.id);
|
||||
}
|
||||
|
||||
/*void onRemove(EntitiesData data)
|
||||
void onRemove(EntitiesData data)
|
||||
{
|
||||
//writeln("Entity destroyed ID: ",data.entites[0].id);
|
||||
}*/
|
||||
}
|
||||
|
||||
bool onBegin()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue