Merge branch 'master' of https://gitlab.com/Mergul/bubel-ecs.git into remove_structure_top_mixin

# Conflicts:
#	tests/basic.d
This commit is contained in:
Mergul 2021-02-27 17:30:31 +01:00
commit 8b2793fc57
13 changed files with 200 additions and 97 deletions

View file

@ -1110,6 +1110,32 @@ export struct EntityManager
}
}
static void catchEntityFilterFunction(string func_name, RetType = void)(void** member)
{
static if (hasMember!(Sys, func_name))
{
foreach (func; __traits(getOverloads, Sys, func_name))
{
static if ((Parameters!(func)).length == 1
&& is(Parameters!(func)[0] == EntityInfo*)
&& is(ReturnType!(func) == RetType))
{
static RetType callFunc(void* system_pointer, EntityInfo* info)
{
Sys* s = cast(Sys*) system_pointer;
static if (is(RetTyp == void))
mixin("s." ~ func_name ~ "(info)");
else
return mixin("s." ~ func_name ~ "(info)");
}
*member = cast(void*)&callFunc;
break;
}
}
}
}
catchFunction!("onEnable")(&system.m_enable);
catchFunction!("onDisable")(&system.m_disable);
catchFunction!("onCreate")(&system.m_create);
@ -1121,6 +1147,8 @@ export struct EntityManager
catchEntityFunction!("onRemoveEntity")(&system.m_remove_entity);
catchEntityFunction!("onChangeEntity")(&system.m_change_entity);
catchEntityFilterFunction!("filterEntity", bool)(&system.m_filter_entity);
system.m_system_pointer = cast(void*) Mallocator.make!Sys;
system.m_priority = priority;
//(cast(Sys*) system.m_system_pointer).__ecsInitialize();
@ -2035,6 +2063,9 @@ export struct EntityManager
is_:
}
///call Custom Entity Filter test if function exists
if(system.m_filter_entity && !(cast(bool function(void* system_pointer, EntityInfo* info) @nogc nothrow)system.m_filter_entity)(system, &entity))return;
entity.systems[system_id] = true;
}
@ -2077,30 +2108,8 @@ export struct EntityManager
{
System* system = &systems[system_id];
if (system.m_excluded_components)
{
foreach (id; system.m_excluded_components)
{
foreach (id2; info.components)
{
if (id == id2)
return;
}
}
}
foreach (id; system.m_components)
{
foreach (i2, id2; info.components)
{
if (id2 == id)
goto is_;
}
return;
is_:
}
info.systems[system_id] = true;
connectListenerToEntityInfo(info, system_id);
if(!info.systems[system_id])return;
uint index = 0;
for (; index < passes[system.m_pass].system_callers.length; index++)
@ -3483,6 +3492,12 @@ export struct EntityManager
return new_info;
}
export bool hasComponent(ushort component_id)
{
if(component_id >= deltas.length || !deltas[component_id])return false;
return true;
}
export ~this() @nogc nothrow
{
if (components)