-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
|
|
@ -61,7 +61,7 @@ class EntityManager
|
||||||
|
|
||||||
id_manager.initialize();
|
id_manager.initialize();
|
||||||
|
|
||||||
allocator = BlockAllocator(page_size,pages_in_block);
|
allocator = BlockAllocator(page_size, pages_in_block);
|
||||||
|
|
||||||
//add_mutex = Mallocator.instance.make!Mutex;
|
//add_mutex = Mallocator.instance.make!Mutex;
|
||||||
entity_block_alloc_mutex = Mallocator.instance.make!Mutex;
|
entity_block_alloc_mutex = Mallocator.instance.make!Mutex;
|
||||||
|
|
@ -72,13 +72,13 @@ class EntityManager
|
||||||
pass.name = Mallocator.instance.makeArray("update");
|
pass.name = Mallocator.instance.makeArray("update");
|
||||||
passes.add(pass);
|
passes.add(pass);
|
||||||
|
|
||||||
passes_map.add(cast(string)pass.name, cast(ushort)(passes.length - 1));
|
passes_map.add(cast(string) pass.name, cast(ushort)(passes.length - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
*Same as "void registerSystem(Sys)(int priority, int pass = 0)" but use pass name instead of id.
|
*Same as "void registerSystem(Sys)(int priority, int pass = 0)" but use pass name instead of id.
|
||||||
*/
|
*/
|
||||||
void registerSystem(Sys)(int priority, const (char)[] pass_name)
|
void registerSystem(Sys)(int priority, const(char)[] pass_name)
|
||||||
{
|
{
|
||||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||||
assert(pass != ushort.max);
|
assert(pass != ushort.max);
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -544,12 +550,12 @@ class EntityManager
|
||||||
return cast(Sys*) systems[Sys.system_id].m_system_pointer;
|
return cast(Sys*) systems[Sys.system_id].m_system_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort registerPass(const (char)[] name)
|
ushort registerPass(const(char)[] name)
|
||||||
{
|
{
|
||||||
UpdatePass* pass = Mallocator.instance.make!UpdatePass;
|
UpdatePass* pass = Mallocator.instance.make!UpdatePass;
|
||||||
pass.name = Mallocator.instance.makeArray(name);
|
pass.name = Mallocator.instance.makeArray(name);
|
||||||
passes.add(pass);
|
passes.add(pass);
|
||||||
passes_map.add(name,cast(ushort)(passes.length - 1));
|
passes_map.add(name, cast(ushort)(passes.length - 1));
|
||||||
return cast(ushort)(passes.length - 1);
|
return cast(ushort)(passes.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -592,7 +598,7 @@ class EntityManager
|
||||||
{
|
{
|
||||||
components.add(info);
|
components.add(info);
|
||||||
Comp.component_id = cast(ushort)(components.length - 1);
|
Comp.component_id = cast(ushort)(components.length - 1);
|
||||||
const (char)[] name = Mallocator.instance.makeArray(Comp.stringof);
|
const(char)[] name = Mallocator.instance.makeArray(Comp.stringof);
|
||||||
components_map.add(name, cast(ushort)(components.length - 1));
|
components_map.add(name, cast(ushort)(components.length - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -636,7 +642,7 @@ class EntityManager
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
*Same as "void update(int pass = 0)" but use pass name instead of id.
|
*Same as "void update(int pass = 0)" but use pass name instead of id.
|
||||||
*/
|
*/
|
||||||
void update(const (char)[] pass_name)
|
void update(const(char)[] pass_name)
|
||||||
{
|
{
|
||||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||||
assert(pass != ushort.max);
|
assert(pass != ushort.max);
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -686,7 +692,7 @@ class EntityManager
|
||||||
/************************************************************************************************************************
|
/************************************************************************************************************************
|
||||||
*Same as "void updateMT(int pass = 0)" but use pass name instead of id.
|
*Same as "void updateMT(int pass = 0)" but use pass name instead of id.
|
||||||
*/
|
*/
|
||||||
void updateMT(const (char)[] pass_name)
|
void updateMT(const(char)[] pass_name)
|
||||||
{
|
{
|
||||||
ushort pass = passes_map.get(pass_name, ushort.max);
|
ushort pass = passes_map.get(pass_name, ushort.max);
|
||||||
assert(pass != ushort.max);
|
assert(pass != ushort.max);
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1680,10 +1686,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1703,7 +1709,7 @@ class EntityManager
|
||||||
/*private */
|
/*private */
|
||||||
void generateDependencies()
|
void generateDependencies()
|
||||||
{
|
{
|
||||||
foreach(pass_id,pass;passes)
|
foreach (pass_id, pass; passes)
|
||||||
{
|
{
|
||||||
foreach (caller; pass.system_callers)
|
foreach (caller; pass.system_callers)
|
||||||
{
|
{
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
@ -2041,7 +2050,7 @@ class EntityManager
|
||||||
enum pages_in_block = 128;
|
enum pages_in_block = 128;
|
||||||
|
|
||||||
IDManager id_manager;
|
IDManager id_manager;
|
||||||
BlockAllocator/*!(page_size, pages_in_block)*/ allocator;
|
BlockAllocator /*!(page_size, pages_in_block)*/ allocator;
|
||||||
|
|
||||||
//EventManager event_manager;
|
//EventManager event_manager;
|
||||||
mixin EventManagerCode;
|
mixin EventManagerCode;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue