-add ecsID template function (get Component/System/Event ID, passes tests)

-removed some ECS mixins code
This commit is contained in:
Mergul 2020-09-29 18:41:31 +02:00
parent 13c82acad4
commit a926b79223
9 changed files with 138 additions and 123 deletions

View file

@ -367,10 +367,10 @@ export struct EntityManager
System system;
system.m_pass = pass;
static if (!(hasMember!(Sys, "system_id")) || !is(typeof(Sys.system_id) == ushort))
{
static assert(0, "Add \"mixin ECS.System;\" in top of system structure;");
}
// static if (!(hasMember!(Sys, "system_id")) || !is(typeof(Sys.system_id) == ushort))
// {
// static assert(0, "Add \"mixin ECS.System;\" in top of system structure;");
// }
static if (!(hasMember!(Sys, "EntitiesData")))
{
@ -408,7 +408,7 @@ export struct EntityManager
~ "\" due to non existing event \"" ~ EventName ~ "\".");
callers[i].callback = cast(void*)&callEventHandler!(EventParamType);
callers[i].id = EventParamType.event_id;
callers[i].id = ecsID!EventParamType;
i++;
}
}
@ -1125,8 +1125,8 @@ export struct EntityManager
system.m_priority = priority;
//(cast(Sys*) system.m_system_pointer).__ecsInitialize();
//system.jobs = (cast(Sys*) system.m_system_pointer)._ecs_jobs;
system.jobs = Mallocator.makeArray!(Job)((cast(Sys*) system.m_system_pointer)
.__ecs_jobs_count);
static if(__traits(hasMember, Sys ,"__ecs_jobs_count"))system.jobs = Mallocator.makeArray!(Job)(Sys.__ecs_jobs_count);
else system.jobs = Mallocator.makeArray!(Job)(32);
static if (OnUpdateOverloadNum != -1)
{
@ -1194,7 +1194,7 @@ export struct EntityManager
systems[$ - 1].enable();
}
Sys.system_id = system.id;
ecsID!Sys = system.id;
}
/************************************************************************************************************************
@ -1212,9 +1212,9 @@ export struct EntityManager
*/
Sys* getSystem(Sys)() nothrow @nogc
{
if (Sys.system_id >= systems.length)
if (ecsID!Sys >= systems.length)
return null;
return cast(Sys*) systems[Sys.system_id].m_system_pointer;
return cast(Sys*) systems[ecsID!Sys].m_system_pointer;
}
export ushort registerPass(const(char)[] name)
@ -1244,10 +1244,10 @@ export struct EntityManager
enum ComponentName = fullName!Comp;
// enum ComponentName = Comp.stringof;
static if (!(hasMember!(Comp, "component_id")) || !is(typeof(Comp.component_id) == ushort))
{
static assert(0, "Add \"mixin ECS.Component;\" in top of component structure;");
}
// static if (!(hasMember!(Comp, "component_id")) || !is(typeof(Comp.component_id) == ushort))
// {
// static assert(0, "Add \"mixin ECS.Component;\" in top of component structure;");
// }
static if (hasMember!(Comp, "onDestroy") && isFunction!(Comp.onDestroy)
&& is(ReturnType!(Comp.onDestroy) == void)
@ -1283,7 +1283,7 @@ export struct EntityManager
ushort comp_id = components_map.get(cast(char[]) ComponentName, ushort.max);
if (comp_id < components.length)
{
Comp.component_id = comp_id;
ecsID!Comp = comp_id;
if (components[comp_id].init_data)
Mallocator.dispose(components[comp_id].init_data);
components[comp_id] = info;
@ -1291,7 +1291,7 @@ export struct EntityManager
else
{
components.add(info);
Comp.component_id = cast(ushort)(components.length - 1);
ecsID!Comp = cast(ushort)(components.length - 1);
char[] name = Mallocator.makeArray(cast(char[]) ComponentName);
components_map.add(name, cast(ushort)(components.length - 1));
}
@ -1301,10 +1301,10 @@ export struct EntityManager
{
EventInfo info;
static if (!(hasMember!(Ev, "event_id")) || !is(typeof(Ev.event_id) == ushort))
{
static assert(0, "Add \"mixin ECS.Event;\" in top of event structure;");
}
// static if (!(hasMember!(Ev, "event_id")) || !is(typeof(Ev.event_id) == ushort))
// {
// static assert(0, "Add \"mixin ECS.Event;\" in top of event structure;");
// }
static if (hasMember!(Ev, "onDestroy") && isFunction!(Ev.onDestroy)
&& is(ReturnType!(Ev.onDestroy) == void) && Parameters!(Ev.onDestroy).length == 0)
@ -1324,12 +1324,12 @@ export struct EntityManager
ushort event_id = events_map.get(fullName!Ev, ushort.max);
if (event_id < events.length)
{
Ev.event_id = event_id;
ecsID!Ev = event_id;
}
else
{
events.add(info);
Ev.event_id = cast(ushort)(events.length - 1);
ecsID!Ev = cast(ushort)(events.length - 1);
// events_map.add(Ev.stringof, cast(ushort)(events.length - 1));
events_map.add(fullName!Ev, cast(ushort)(events.length - 1));
}
@ -1348,9 +1348,9 @@ export struct EntityManager
// static assert(is(SetFunctionAttributes!(T, functionLinkage!(s.onUpdate),
// functionAttributes!(s.onUpdate)) == typeof(&s.onUpdate)),
// "Function must match system update function."); FIXME: It's lead to crash on android build
static assert(__traits(hasMember, Sys, "system_id"), "Sys must be system type.");
// static assert(__traits(hasMember, Sys, "system_id"), "Sys must be system type.");
System* system = getSystem(Sys.system_id);
System* system = getSystem(ecsID!Sys);
assert(system != null,
"System must be registered in EntityManager before any funcion can be called.");
if (!system.m_any_system_caller)
@ -2256,7 +2256,7 @@ export struct EntityManager
ushort[num] del_ids;
static foreach (i, comp; Components)
{
del_ids[i] = comp.component_id;
del_ids[i] = ecsID!comp;
}
removeComponents(entity_id, del_ids);