-onBegin() return type was changed from void to bool
-disabling system execution in onBegin() funciton
This commit is contained in:
parent
d3f7593afc
commit
f666dfd1d5
3 changed files with 43 additions and 30 deletions
|
|
@ -441,29 +441,35 @@ class EntityManager
|
|||
system.m_update = &callUpdate;
|
||||
}
|
||||
|
||||
static string catchFunc()(string member, string func)
|
||||
static string catchFunc(RetType = void)(string member, string func)
|
||||
{
|
||||
string ret = "static if (hasMember!(Sys, \"" ~ func ~ "\"))
|
||||
//dfmt off
|
||||
static if(is(RetType == void))string ret_str = "";
|
||||
else string ret_str = "return ";
|
||||
string ret = "static if (hasMember!(Sys, \"" ~ func ~ "\") &&
|
||||
Parameters!(Sys."~func~").length == 0 &&
|
||||
is(ReturnType!(Sys."~func~") == "~RetType.stringof~"))
|
||||
{
|
||||
static void call" ~ func
|
||||
static "~RetType.stringof~" call" ~ func
|
||||
~ "(void* system_pointer)
|
||||
{
|
||||
|
||||
Sys* s = cast(Sys*) system_pointer;
|
||||
s." ~ func ~ "();
|
||||
"~ret_str~"s." ~ func ~ "();
|
||||
}
|
||||
|
||||
system."
|
||||
~ member ~ " = &call" ~ func ~ ";
|
||||
}";
|
||||
return ret;
|
||||
//dfmt on
|
||||
}
|
||||
|
||||
mixin(catchFunc("m_enable", "onEnable"));
|
||||
mixin(catchFunc("m_disable", "onDisable"));
|
||||
mixin(catchFunc("m_create", "onCreate"));
|
||||
mixin(catchFunc("m_destroy", "onDestroy"));
|
||||
mixin(catchFunc("m_begin", "onBegin"));
|
||||
mixin(catchFunc!(bool)("m_begin", "onBegin"));
|
||||
mixin(catchFunc("m_end", "onEnd"));
|
||||
|
||||
system.m_system_pointer = cast(void*) Mallocator.instance.make!Sys;
|
||||
|
|
@ -654,7 +660,7 @@ class EntityManager
|
|||
foreach (caller; passes[pass].system_callers)
|
||||
{
|
||||
System* sys = &systems[caller.system_id];
|
||||
if (sys.enabled)
|
||||
if (sys.enabled && sys.execute)
|
||||
{
|
||||
//if (sys.m_begin)
|
||||
// sys.m_begin(sys.m_system_pointer);
|
||||
|
|
@ -704,7 +710,7 @@ class EntityManager
|
|||
foreach (caller; passes[pass].system_callers)
|
||||
{
|
||||
System* sys = &systems[caller.system_id];
|
||||
if (sys.enabled)
|
||||
if (sys.enabled && sys.execute)
|
||||
{
|
||||
uint entities_count = 0;
|
||||
foreach (info; caller.infos)
|
||||
|
|
@ -1668,10 +1674,10 @@ class EntityManager
|
|||
commit();
|
||||
m_call_data_allocator.clear();
|
||||
|
||||
foreach (ref system; instance.systems)
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.m_begin)
|
||||
(cast(void function(void*)) system.m_begin)(system.m_system_pointer);
|
||||
if (system.enabled && system.m_begin)
|
||||
system.execute = (cast(bool function(void*)) system.m_begin)(system.m_system_pointer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1681,9 +1687,9 @@ class EntityManager
|
|||
export void end()
|
||||
{
|
||||
|
||||
foreach (ref system; instance.systems)
|
||||
foreach (ref system; systems)
|
||||
{
|
||||
if (system.m_end)
|
||||
if (system.enabled && system.m_end)
|
||||
(cast(void function(void*)) system.m_end)(system.m_system_pointer);
|
||||
}
|
||||
|
||||
|
|
@ -1715,8 +1721,8 @@ class EntityManager
|
|||
}
|
||||
uint index = 0;
|
||||
SystemCaller*[] exclusion;
|
||||
exclusion = (cast(SystemCaller**) alloca((SystemCaller*).sizeof * pass.system_callers.length))[0
|
||||
.. pass.system_callers.length];
|
||||
exclusion = (cast(SystemCaller**) alloca((SystemCaller*)
|
||||
.sizeof * pass.system_callers.length))[0 .. pass.system_callers.length];
|
||||
foreach (caller; pass.system_callers)
|
||||
{
|
||||
index = 0;
|
||||
|
|
@ -1787,8 +1793,8 @@ class EntityManager
|
|||
return 1;
|
||||
}
|
||||
|
||||
qsort(pass.system_callers.array.ptr, pass.system_callers.length, (SystemCaller*)
|
||||
.sizeof, &compareSystems);
|
||||
qsort(pass.system_callers.array.ptr, pass.system_callers.length,
|
||||
(SystemCaller*).sizeof, &compareSystems);
|
||||
|
||||
/*static struct CallerData
|
||||
{
|
||||
|
|
@ -1830,7 +1836,8 @@ class EntityManager
|
|||
if (index > 0)
|
||||
{
|
||||
caller.dependencies = Mallocator.instance.makeArray(exclusion[0 .. index]);
|
||||
caller.job_group.dependencies = Mallocator.instance.makeArray!(JobGroup*)(index);
|
||||
caller.job_group.dependencies = Mallocator.instance.makeArray!(
|
||||
JobGroup*)(index);
|
||||
|
||||
foreach (j, dep; caller.dependencies)
|
||||
{
|
||||
|
|
@ -2015,8 +2022,10 @@ class EntityManager
|
|||
~this()
|
||||
{
|
||||
assert(name);
|
||||
if(name)Mallocator.instance.dispose(name);
|
||||
if (name)
|
||||
Mallocator.instance.dispose(name);
|
||||
}
|
||||
|
||||
char[] name;
|
||||
Vector!(SystemCaller*) system_callers;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ struct System
|
|||
|
||||
package:
|
||||
|
||||
///should system be executed in current update?
|
||||
bool execute = true;
|
||||
|
||||
///should system update and catch events?
|
||||
bool m_enabled = false;
|
||||
///system priority
|
||||
|
|
|
|||
|
|
@ -111,9 +111,10 @@ int main()
|
|||
writeln("On Test System destroy.");
|
||||
}
|
||||
|
||||
void onBegin()
|
||||
bool onBegin()
|
||||
{
|
||||
//writeln("On Test System begin.");
|
||||
return true;
|
||||
}
|
||||
|
||||
void onEnd()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue