-onBegin() return type was changed from void to bool

-disabling system execution in onBegin() funciton
This commit is contained in:
Mergul 2018-10-26 17:43:51 +02:00
parent d3f7593afc
commit f666dfd1d5
3 changed files with 43 additions and 30 deletions

View file

@ -441,29 +441,35 @@ class EntityManager
system.m_update = &callUpdate; 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) ~ "(void* system_pointer)
{ {
Sys* s = cast(Sys*) system_pointer; Sys* s = cast(Sys*) system_pointer;
s." ~ func ~ "(); "~ret_str~"s." ~ func ~ "();
} }
system." system."
~ member ~ " = &call" ~ func ~ "; ~ member ~ " = &call" ~ func ~ ";
}"; }";
return ret; return ret;
//dfmt on
} }
mixin(catchFunc("m_enable", "onEnable")); mixin(catchFunc("m_enable", "onEnable"));
mixin(catchFunc("m_disable", "onDisable")); mixin(catchFunc("m_disable", "onDisable"));
mixin(catchFunc("m_create", "onCreate")); mixin(catchFunc("m_create", "onCreate"));
mixin(catchFunc("m_destroy", "onDestroy")); mixin(catchFunc("m_destroy", "onDestroy"));
mixin(catchFunc("m_begin", "onBegin")); mixin(catchFunc!(bool)("m_begin", "onBegin"));
mixin(catchFunc("m_end", "onEnd")); mixin(catchFunc("m_end", "onEnd"));
system.m_system_pointer = cast(void*) Mallocator.instance.make!Sys; system.m_system_pointer = cast(void*) Mallocator.instance.make!Sys;
@ -654,7 +660,7 @@ class EntityManager
foreach (caller; passes[pass].system_callers) foreach (caller; passes[pass].system_callers)
{ {
System* sys = &systems[caller.system_id]; System* sys = &systems[caller.system_id];
if (sys.enabled) if (sys.enabled && sys.execute)
{ {
//if (sys.m_begin) //if (sys.m_begin)
// sys.m_begin(sys.m_system_pointer); // sys.m_begin(sys.m_system_pointer);
@ -704,7 +710,7 @@ class EntityManager
foreach (caller; passes[pass].system_callers) foreach (caller; passes[pass].system_callers)
{ {
System* sys = &systems[caller.system_id]; System* sys = &systems[caller.system_id];
if (sys.enabled) if (sys.enabled && sys.execute)
{ {
uint entities_count = 0; uint entities_count = 0;
foreach (info; caller.infos) foreach (info; caller.infos)
@ -1668,10 +1674,10 @@ class EntityManager
commit(); commit();
m_call_data_allocator.clear(); m_call_data_allocator.clear();
foreach (ref system; instance.systems) foreach (ref system; systems)
{ {
if (system.m_begin) if (system.enabled && system.m_begin)
(cast(void function(void*)) system.m_begin)(system.m_system_pointer); system.execute = (cast(bool function(void*)) system.m_begin)(system.m_system_pointer);
} }
} }
@ -1681,9 +1687,9 @@ class EntityManager
export void end() 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); (cast(void function(void*)) system.m_end)(system.m_system_pointer);
} }
@ -1715,8 +1721,8 @@ class EntityManager
} }
uint index = 0; uint index = 0;
SystemCaller*[] exclusion; SystemCaller*[] exclusion;
exclusion = (cast(SystemCaller**) alloca((SystemCaller*).sizeof * pass.system_callers.length))[0 exclusion = (cast(SystemCaller**) alloca((SystemCaller*)
.. pass.system_callers.length]; .sizeof * pass.system_callers.length))[0 .. pass.system_callers.length];
foreach (caller; pass.system_callers) foreach (caller; pass.system_callers)
{ {
index = 0; index = 0;
@ -1787,8 +1793,8 @@ class EntityManager
return 1; return 1;
} }
qsort(pass.system_callers.array.ptr, pass.system_callers.length, (SystemCaller*) qsort(pass.system_callers.array.ptr, pass.system_callers.length,
.sizeof, &compareSystems); (SystemCaller*).sizeof, &compareSystems);
/*static struct CallerData /*static struct CallerData
{ {
@ -1830,7 +1836,8 @@ class EntityManager
if (index > 0) if (index > 0)
{ {
caller.dependencies = Mallocator.instance.makeArray(exclusion[0 .. index]); 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) foreach (j, dep; caller.dependencies)
{ {
@ -2015,8 +2022,10 @@ class EntityManager
~this() ~this()
{ {
assert(name); assert(name);
if(name)Mallocator.instance.dispose(name); if (name)
Mallocator.instance.dispose(name);
} }
char[] name; char[] name;
Vector!(SystemCaller*) system_callers; Vector!(SystemCaller*) system_callers;
} }

View file

@ -47,6 +47,9 @@ struct System
package: package:
///should system be executed in current update?
bool execute = true;
///should system update and catch events? ///should system update and catch events?
bool m_enabled = false; bool m_enabled = false;
///system priority ///system priority

View file

@ -111,9 +111,10 @@ int main()
writeln("On Test System destroy."); writeln("On Test System destroy.");
} }
void onBegin() bool onBegin()
{ {
//writeln("On Test System begin."); //writeln("On Test System begin.");
return true;
} }
void onEnd() void onEnd()