Add unregisterSystem functionality
This commit is contained in:
parent
881d6d113b
commit
5f4ba90b3e
2 changed files with 37 additions and 0 deletions
|
|
@ -172,6 +172,8 @@ export struct EntityManager
|
|||
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
continue;
|
||||
if (system.m_empty)
|
||||
{
|
||||
if (system.m_update)
|
||||
|
|
@ -236,6 +238,8 @@ export struct EntityManager
|
|||
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
continue;
|
||||
foreach (caller; system.m_event_callers)
|
||||
{
|
||||
event_callers[caller.id]++;
|
||||
|
|
@ -252,6 +256,8 @@ export struct EntityManager
|
|||
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
continue;
|
||||
foreach (caller; system.m_event_callers)
|
||||
{
|
||||
events[caller.id].callers[event_callers[caller.id]].callback = caller.callback;
|
||||
|
|
@ -328,6 +334,21 @@ export struct EntityManager
|
|||
allocator.freeMemory();
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************************************************
|
||||
Unregister given system form EntityManager.
|
||||
*/
|
||||
void unregisterSystem(Sys)()
|
||||
{
|
||||
assert(register_state, "unregisterSystem must be called between beginRegister() and endRegister().");
|
||||
ushort system_id = becsID!Sys;
|
||||
System* system = getSystem(system_id);
|
||||
assert(system, "System was not registered");
|
||||
assert(system.isAlive, "System already unregistered");
|
||||
system.destroy();
|
||||
*system = System.init;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
Same as "void registerSystem(Sys)(int priority, int pass = 0)" but use pass name instead of id.
|
||||
*/
|
||||
|
|
@ -1887,6 +1908,8 @@ export struct EntityManager
|
|||
|
||||
foreach (i, ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
continue;
|
||||
if (system.m_empty)
|
||||
continue;
|
||||
if (system.m_update is null)
|
||||
|
|
@ -3095,6 +3118,8 @@ export struct EntityManager
|
|||
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
continue;
|
||||
if (system.enabled && system.m_begin)
|
||||
system.m_execute = (cast(bool function(void*)) system.m_begin)(
|
||||
system.m_system_pointer);
|
||||
|
|
@ -3109,6 +3134,10 @@ export struct EntityManager
|
|||
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.isAlive() == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (system.enabled && system.m_end)
|
||||
(cast(void function(void*)) system.m_end)(system.m_system_pointer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,14 @@ struct System
|
|||
return cast(const(char)[]) m_name;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
Return false if system was unregistered, true otherwise.
|
||||
*/
|
||||
export bool isAlive() nothrow @nogc
|
||||
{
|
||||
return m_system_pointer != null;
|
||||
}
|
||||
|
||||
package:
|
||||
|
||||
void destroy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue