-add ecsID template function (get Component/System/Event ID, passes tests)
-removed some ECS mixins code
This commit is contained in:
parent
13c82acad4
commit
a926b79223
9 changed files with 138 additions and 123 deletions
|
|
@ -53,6 +53,7 @@ module bubel.ecs.core;
|
|||
|
||||
public import bubel.ecs.manager;
|
||||
public import bubel.ecs.entity;
|
||||
public import bubel.ecs.traits : ecsID;
|
||||
|
||||
/************************************************************************************************************************
|
||||
Main struct used as namespace for templates.
|
||||
|
|
@ -60,12 +61,12 @@ Main struct used as namespace for templates.
|
|||
static struct ECS
|
||||
{
|
||||
/************************************************************************************************************************
|
||||
Mark structure as System. Should be added on top of structure (before any data).
|
||||
Set default system parameters (number of parallel jobs)
|
||||
*/
|
||||
mixin template System(uint jobs_count = 32)
|
||||
{
|
||||
__gshared ushort system_id = ushort.max;
|
||||
uint __ecs_jobs_count = jobs_count;
|
||||
// __gshared ushort system_id = ushort.max;
|
||||
__gshared uint __ecs_jobs_count = jobs_count;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
|
|
@ -73,21 +74,21 @@ static struct ECS
|
|||
*/
|
||||
mixin template Component()
|
||||
{
|
||||
__gshared ushort component_id = ushort.max;
|
||||
//__gshared ushort component_id = ushort.max;
|
||||
|
||||
ComponentRef ref_() @nogc nothrow return
|
||||
{
|
||||
return ComponentRef(&this, component_id);
|
||||
return ComponentRef(&this, ecsID!(typeof(this)));
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
Mark structure as Event. Should be added on top of structure (before any data).
|
||||
*/
|
||||
mixin template Event()
|
||||
{
|
||||
__gshared ushort event_id = ushort.max;
|
||||
}
|
||||
// mixin template Event()
|
||||
// {
|
||||
// __gshared ushort event_id = ushort.max;
|
||||
// }
|
||||
|
||||
/************************************************************************************************************************
|
||||
Make list of excluded components. This template get structure types as argument. Should be added inside System structure.
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ module bubel.ecs.entity;
|
|||
|
||||
import bubel.ecs.system;
|
||||
import bubel.ecs.manager;
|
||||
import bubel.ecs.traits : ecsID;
|
||||
|
||||
/************************************************************************************************************************
|
||||
Entity ID structure. Used as reference to Entity. Pointer to entity should be ever used to store entity reference!
|
||||
|
|
@ -40,7 +41,7 @@ struct Entity
|
|||
return null;
|
||||
|
||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);*/
|
||||
return cast(T*)getComponent(T.component_id);
|
||||
return cast(T*)getComponent(ecsID!T);
|
||||
}
|
||||
|
||||
void* getComponent(ushort component_id) const
|
||||
|
|
@ -81,7 +82,7 @@ struct EntityMeta
|
|||
if (T.component_id >= info.deltas.length || info.deltas[T.component_id] == 0)
|
||||
return null;
|
||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + index * T.sizeof);*/
|
||||
return cast(T*)getComponent(T.component_id);
|
||||
return cast(T*)getComponent(ecsID!T);
|
||||
}
|
||||
|
||||
void* getComponent(ushort component_id) const
|
||||
|
|
@ -125,8 +126,8 @@ export struct EntityTemplate
|
|||
*/
|
||||
T* getComponent(T)() nothrow @nogc
|
||||
{
|
||||
if(T.component_id >= info.tmpl_deltas.length || info.tmpl_deltas[T.component_id] == ushort.max)return null;
|
||||
return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]);
|
||||
if(ecsID!T >= info.tmpl_deltas.length || info.tmpl_deltas[ecsID!T] == ushort.max)return null;
|
||||
return cast(T*)(entity_data.ptr + info.tmpl_deltas[ecsID!T]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import bubel.ecs.block_allocator;
|
|||
import bubel.ecs.entity;
|
||||
import bubel.ecs.manager;
|
||||
import bubel.ecs.std;
|
||||
import bubel.ecs.traits : ecsID;
|
||||
|
||||
import std.algorithm.comparison : max;
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ package struct EventManager
|
|||
{
|
||||
uint block_id = current_index + thread_id;
|
||||
|
||||
EventData* data = &events[Ev.event_id];
|
||||
EventData* data = &events[ecsID!Ev];
|
||||
EventBlock* block = data.blocks[block_id];
|
||||
//EntityManager.EventInfo* info = &manager.events[Ev.event_id];
|
||||
//event.entity_id = id;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,18 @@ module bubel.ecs.traits;
|
|||
|
||||
import std.traits;
|
||||
|
||||
ref ushort ecsID(T)()
|
||||
{
|
||||
__gshared ushort id = ushort.max;
|
||||
return id;
|
||||
}
|
||||
|
||||
ref ushort ecsID(T)(T obj)
|
||||
{
|
||||
static if(isPointer!T)return ecsID!(PointerTarget!T);
|
||||
else return ecsID!T;
|
||||
}
|
||||
|
||||
bool isForeachDelegateWithTypes(DG, Types...)()
|
||||
{
|
||||
return is(DG == delegate) && is(ReturnType!DG == int) && is(Parameters!DG == Types);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ void beforeEveryTest()
|
|||
|
||||
gEM.endRegister();
|
||||
|
||||
tmpl = gEM.allocateTemplate([CLong.component_id, CInt.component_id, CUInt.component_id, CBig.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CLong, ecsID!CInt, ecsID!CUInt, ecsID!CBig].staticArray);
|
||||
foreach(i; 0 .. 100_000)gEM.addEntity(tmpl);
|
||||
}
|
||||
|
||||
|
|
|
|||
138
tests/basic.d
138
tests/basic.d
|
|
@ -115,7 +115,7 @@ struct EmptySystem
|
|||
|
||||
void beforeEveryTest()
|
||||
{
|
||||
CUnregistered.component_id = ushort.max;
|
||||
ecsID!CUnregistered = ushort.max;
|
||||
gEM.initialize(0);
|
||||
|
||||
gEM.beginRegister();
|
||||
|
|
@ -138,17 +138,17 @@ void afterEveryTest()
|
|||
@("EntityMeta")
|
||||
unittest
|
||||
{
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate([CInt.component_id, CFloat.component_id, CFlag.component_id].staticArray);
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate([ecsID!CInt, ecsID!CFloat, ecsID!CFlag].staticArray);
|
||||
Entity* entity = gEM.addEntity(tmpl_);
|
||||
EntityMeta meta = entity.getMeta();
|
||||
assert(meta.hasComponent(CInt.component_id));
|
||||
assert(meta.hasComponent(ecsID!CInt));
|
||||
assert(meta.getComponent!CInt);
|
||||
assert(meta.hasComponent(CFloat.component_id));
|
||||
assert(meta.hasComponent(ecsID!CFloat));
|
||||
assert(meta.getComponent!CFloat);
|
||||
assert(!meta.getComponent!CLong);
|
||||
assert(!meta.hasComponent(CLong.component_id));
|
||||
assert(!meta.hasComponent(ecsID!CLong));
|
||||
assert(!meta.getComponent!CUnregistered);
|
||||
assert(!meta.hasComponent(CUnregistered.component_id));
|
||||
assert(!meta.hasComponent(ecsID!CUnregistered));
|
||||
assert(*meta.getComponent!CInt == 1);
|
||||
assert(*meta.getComponent!CFloat == 2.0);
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ unittest
|
|||
@("AddEntity")
|
||||
unittest
|
||||
{
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate([CInt.component_id, CFloat.component_id, CFlag.component_id].staticArray);
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate([ecsID!CInt, ecsID!CFloat, ecsID!CFlag].staticArray);
|
||||
assert(tmpl_.info.components.length == 3);
|
||||
assert(tmpl_.info.size == (CInt.sizeof + CFloat.sizeof + EntityID.sizeof));
|
||||
assert(tmpl_.getComponent!CInt);
|
||||
|
|
@ -185,8 +185,8 @@ unittest
|
|||
//Entity* entity3 = gEM.addEntity(tmpl_, [cint.ref_, clong.ref_].staticArray);
|
||||
Entity* entity3 = gEM.addEntity(tmpl_, [CInt(10).ref_, CLong().ref_, CFlag().ref_].staticArray);
|
||||
EntityID id = entity3.id;
|
||||
assert(entity3.hasComponent(CInt.component_id));
|
||||
assert(entity3.hasComponent(CFloat.component_id));
|
||||
assert(entity3.hasComponent(ecsID!CInt));
|
||||
assert(entity3.hasComponent(ecsID!CFloat));
|
||||
assert(*entity3.getComponent!CInt == 10);
|
||||
assert(*entity3.getComponent!CFloat == 2.0);
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ unittest
|
|||
assert(*entity3.getComponent!CFloat == 2.0);
|
||||
assert(*entity3.getComponent!CShort == 2);
|
||||
|
||||
gEM.removeComponents(entity3.id, [CFlag().component_id,CShort(2).component_id].staticArray);
|
||||
gEM.removeComponents(entity3.id, [ecsID!CFlag,ecsID!CShort].staticArray);
|
||||
gEM.commit();
|
||||
entity3 = gEM.getEntity(id);
|
||||
assert(entity3.getComponent!CInt);
|
||||
|
|
@ -212,7 +212,7 @@ unittest
|
|||
assert(*entity3.getComponent!CFloat == 2.0);
|
||||
|
||||
gEM.addComponents(entity3.id, [CFlag().ref_,CShort(2).ref_].staticArray);
|
||||
gEM.removeComponents(entity3.id, [CUnregistered.component_id].staticArray);
|
||||
gEM.removeComponents(entity3.id, [ecsID!CUnregistered].staticArray);
|
||||
gEM.commit();
|
||||
entity3 = gEM.getEntity(id);
|
||||
assert(entity3.getComponent!CInt);
|
||||
|
|
@ -235,7 +235,7 @@ unittest
|
|||
assert(entity3.getComponent!CUnregistered);
|
||||
assert(*entity3.getComponent!CUnregistered == 4);
|
||||
|
||||
gEM.removeComponents(entity3.id, [CUnregistered.component_id].staticArray);
|
||||
gEM.removeComponents(entity3.id, [ecsID!CUnregistered].staticArray);
|
||||
gEM.commit();
|
||||
entity3 = gEM.getEntity(id);
|
||||
assert(!entity3.getComponent!CUnregistered);
|
||||
|
|
@ -247,9 +247,9 @@ unittest
|
|||
unittest
|
||||
{
|
||||
//basic template allocation
|
||||
ushort[2] ids = [CInt.component_id, CFloat.component_id];
|
||||
ushort[2] ids = [ecsID!CInt, ecsID!CFloat];
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate(ids);
|
||||
EntityTemplate* tmpl_d = gEM.allocateTemplate([CFloat.component_id, CInt.component_id, CFloat.component_id].staticArray);
|
||||
EntityTemplate* tmpl_d = gEM.allocateTemplate([ecsID!CFloat, ecsID!CInt, ecsID!CFloat].staticArray);
|
||||
EntityTemplate* tmpl_cp = gEM.allocateTemplate(tmpl_);
|
||||
assert(tmpl_d.info == tmpl_.info);
|
||||
assert(tmpl_cp.info == tmpl_cp.info);
|
||||
|
|
@ -268,7 +268,7 @@ unittest
|
|||
*tmpl_.getComponent!CFloat = 5.0;
|
||||
|
||||
//allocate template from template with additional components
|
||||
ushort[2] ids2 = [CDouble.component_id,CFlag.component_id];
|
||||
ushort[2] ids2 = [ecsID!CDouble,ecsID!CFlag];
|
||||
EntityTemplate* tmpl_2 = gEM.allocateTemplate(tmpl_, ids2);
|
||||
assert(tmpl_2.info.components.length == 4);
|
||||
assert(tmpl_2.getComponent!CInt);
|
||||
|
|
@ -313,7 +313,7 @@ unittest
|
|||
assert(*tmpl_4.getComponent!CDouble == 3.0);
|
||||
|
||||
//allocate template from template with three additional component
|
||||
ushort[3] ids3 = [CDouble.component_id, CLong.component_id, CShort.component_id];
|
||||
ushort[3] ids3 = [ecsID!CDouble, ecsID!CLong, ecsID!CShort];
|
||||
EntityTemplate* tmpl_5 = gEM.allocateTemplate(tmpl_2, ids3);
|
||||
assert(tmpl_5.info.components.length == 6);
|
||||
assert(tmpl_5.getComponent!CInt);
|
||||
|
|
@ -328,7 +328,7 @@ unittest
|
|||
assert(*tmpl_5.getComponent!CShort == 12);
|
||||
|
||||
//allocate template from template without one component
|
||||
ushort[1] rem_ids = [CFloat.component_id];
|
||||
ushort[1] rem_ids = [ecsID!CFloat];
|
||||
EntityTemplate* tmpl_6 = gEM.allocateTemplate(tmpl_, null, rem_ids);
|
||||
assert(tmpl_6.info.components.length == 1);
|
||||
assert(tmpl_6.getComponent!CInt);
|
||||
|
|
@ -358,8 +358,8 @@ unittest
|
|||
unittest
|
||||
{
|
||||
//basic template allocation
|
||||
ushort[2] ids = [CFloat.component_id, CInt.component_id];
|
||||
ushort[2] ids2 = [CInt.component_id, CFloat.component_id];
|
||||
ushort[2] ids = [ecsID!CFloat, ecsID!CInt];
|
||||
ushort[2] ids2 = [ecsID!CInt, ecsID!CFloat];
|
||||
EntityTemplate* tmpl_ = gEM.allocateTemplate(ids);
|
||||
EntityTemplate* tmpl_2 = gEM.allocateTemplate(ids2);
|
||||
assert(tmpl_.info.components.length == 2);
|
||||
|
|
@ -398,9 +398,9 @@ unittest
|
|||
assert(system !is null);
|
||||
assert(system.count == 0);
|
||||
|
||||
System* ecs_system = gEM.getSystem(EmptySystem.system_id);
|
||||
System* ecs_system = gEM.getSystem(ecsID!EmptySystem);
|
||||
assert(ecs_system !is null);
|
||||
assert(ecs_system.id == EmptySystem.system_id);
|
||||
assert(ecs_system.id == ecsID!EmptySystem);
|
||||
assert(ecs_system.name == "tests.basic.EmptySystem");
|
||||
|
||||
gEM.begin();
|
||||
|
|
@ -502,7 +502,7 @@ unittest
|
|||
//FIXME: currently destroy is only called with Manager.destory which is bug, but there is no workaround for this by now
|
||||
//assert(destroy == 1);
|
||||
|
||||
System* ecs_system = gEM.getSystem(system.system_id);
|
||||
System* ecs_system = gEM.getSystem(system.ecsID);
|
||||
|
||||
ecs_system.enable();
|
||||
assert(system.enable == 1);
|
||||
|
|
@ -513,7 +513,7 @@ unittest
|
|||
assert(system.disable == 1);
|
||||
|
||||
|
||||
ushort[2] ids = [CLong.component_id,CFloat.component_id];
|
||||
ushort[2] ids = [ecsID!CLong,ecsID!CFloat];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
gEM.addEntity(tmpl);
|
||||
|
|
@ -527,7 +527,7 @@ unittest
|
|||
gEM.end();
|
||||
assert(system.end == 1);
|
||||
|
||||
ushort[2] ids2 = [CLong.component_id, CInt.component_id];
|
||||
ushort[2] ids2 = [ecsID!CLong, ecsID!CInt];
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2);
|
||||
scope (exit) gEM.freeTemplate(tmpl2);
|
||||
gEM.addEntity(tmpl2);
|
||||
|
|
@ -542,7 +542,7 @@ unittest
|
|||
gEM.end();
|
||||
assert(system.end == 2);
|
||||
|
||||
ushort[2] ids3 = [CLong.component_id, CShort.component_id];
|
||||
ushort[2] ids3 = [ecsID!CLong, ecsID!CShort];
|
||||
EntityTemplate* tmpl3 = gEM.allocateTemplate(ids3);
|
||||
scope (exit) gEM.freeTemplate(tmpl3);
|
||||
gEM.addEntity(tmpl3);
|
||||
|
|
@ -601,13 +601,13 @@ unittest
|
|||
assert(system !is null);
|
||||
assert(system.updates_count == 0);
|
||||
|
||||
System* ecs_system = gEM.getSystem(LongAddSystem.system_id);
|
||||
System* ecs_system = gEM.getSystem(ecsID!LongAddSystem);
|
||||
assert(ecs_system !is null);
|
||||
assert(ecs_system.id == LongAddSystem.system_id);
|
||||
assert(ecs_system.id == ecsID!LongAddSystem);
|
||||
assert(ecs_system.priority == -1);
|
||||
assert(ecs_system.name == "tests.basic.LongAddSystem");
|
||||
|
||||
ushort[1] ids = [CLong.component_id];
|
||||
ushort[1] ids = [ecsID!CLong];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
gEM.addEntity(tmpl);
|
||||
|
|
@ -757,19 +757,19 @@ unittest
|
|||
assert(system.remove == 0);
|
||||
assert(system.change == 0);
|
||||
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([CLong.component_id,CFloat.component_id].staticArray);
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([ecsID!CLong,ecsID!CFloat].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
EntityID id0 = gEM.addEntity(tmpl).id;
|
||||
gEM.commit();
|
||||
assert(system.add == 1);
|
||||
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([CLong.component_id, CInt.component_id].staticArray);
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CLong, ecsID!CInt].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl2);
|
||||
EntityID id1 = gEM.addEntity(tmpl2).id;
|
||||
gEM.commit();
|
||||
assert(system.add == 2);
|
||||
|
||||
EntityTemplate* tmpl3 = gEM.allocateTemplate([CLong.component_id, CShort.component_id].staticArray);
|
||||
EntityTemplate* tmpl3 = gEM.allocateTemplate([ecsID!CLong, ecsID!CShort].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl3);
|
||||
EntityID id2 = gEM.addEntity(tmpl3).id;
|
||||
gEM.commit();
|
||||
|
|
@ -778,19 +778,19 @@ unittest
|
|||
gEM.beginRegister();
|
||||
gEM.endRegister();
|
||||
|
||||
gEM.removeComponents(id0, [CFloat.component_id].staticArray);
|
||||
gEM.removeComponents(id0, [ecsID!CFloat].staticArray);
|
||||
gEM.commit();
|
||||
assert(system.add == 2);
|
||||
assert(system.remove == 0);
|
||||
assert(system.change == 0);
|
||||
|
||||
gEM.removeComponents(id1, [CInt.component_id].staticArray);
|
||||
gEM.removeComponents(id1, [ecsID!CInt].staticArray);
|
||||
gEM.commit();
|
||||
assert(system.add == 2);
|
||||
assert(system.remove == 0);
|
||||
assert(system.change == 1);
|
||||
|
||||
gEM.removeComponents(id2, [CShort.component_id].staticArray);
|
||||
gEM.removeComponents(id2, [ecsID!CShort].staticArray);
|
||||
gEM.commit();
|
||||
assert(system.add == 3);
|
||||
assert(system.remove == 0);
|
||||
|
|
@ -889,7 +889,7 @@ unittest
|
|||
}
|
||||
|
||||
assert(gEM.getSystem!TestSystem is null);
|
||||
assert(gEM.getSystem(TestSystem.system_id) is null);
|
||||
assert(gEM.getSystem(ecsID!TestSystem) is null);
|
||||
}
|
||||
|
||||
@("MultithreadedUpdate")
|
||||
|
|
@ -961,10 +961,10 @@ unittest
|
|||
TestSystem* system = gEM.getSystem!TestSystem;
|
||||
TestEmptySystem* empty_system = gEM.getSystem!TestEmptySystem;
|
||||
|
||||
ushort[2] ids = [CLong.component_id,CFloat.component_id];
|
||||
ushort[2] ids = [ecsID!CLong,ecsID!CFloat];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([CLong.component_id,CInt.component_id,CShort.component_id,CFloat.component_id].staticArray);
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CLong,ecsID!CInt,ecsID!CShort,ecsID!CFloat].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl2);
|
||||
|
||||
gEM.begin();
|
||||
|
|
@ -1059,7 +1059,7 @@ unittest
|
|||
@("AddRemoveEntities")
|
||||
unittest
|
||||
{
|
||||
ushort[3] ids = [CLong.component_id,CFloat.component_id,CShort.component_id];
|
||||
ushort[3] ids = [ecsID!CLong,ecsID!CFloat,ecsID!CShort];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
|
||||
|
|
@ -1089,7 +1089,7 @@ unittest
|
|||
|
||||
gEM.endRegister();
|
||||
|
||||
ushort[1] ids = [CLong.component_id];
|
||||
ushort[1] ids = [ecsID!CLong];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
|
||||
|
|
@ -1118,7 +1118,7 @@ unittest
|
|||
assert(*entity.getComponent!CShort == 15);
|
||||
assert(*entity.getComponent!CFloat == 13);
|
||||
|
||||
ushort[3] ids2 = [CFloat.component_id, CLong.component_id, CUnregistered.component_id];
|
||||
ushort[3] ids2 = [ecsID!CFloat, ecsID!CLong, ecsID!CUnregistered];
|
||||
gEM.removeComponents(id, ids2);
|
||||
gEM.commit();
|
||||
|
||||
|
|
@ -1161,12 +1161,12 @@ unittest
|
|||
{
|
||||
struct ETest
|
||||
{
|
||||
mixin ECS.Event;
|
||||
// mixin ECS.Event;
|
||||
}
|
||||
|
||||
struct ETest2
|
||||
{
|
||||
mixin ECS.Event;
|
||||
// mixin ECS.Event;
|
||||
|
||||
void onDestroy()
|
||||
{
|
||||
|
|
@ -1253,10 +1253,10 @@ unittest
|
|||
|
||||
gEM.endRegister();
|
||||
|
||||
ushort[1] ids = [CLong.component_id];
|
||||
ushort[1] ids = [ecsID!CLong];
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
ushort[1] ids2 = [CShort.component_id];
|
||||
ushort[1] ids2 = [ecsID!CShort];
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate(ids2);
|
||||
scope (exit) gEM.freeTemplate(tmpl2);
|
||||
|
||||
|
|
@ -1348,11 +1348,11 @@ unittest
|
|||
|
||||
gEM.endRegister();
|
||||
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([CInt.component_id].staticArray);
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([ecsID!CInt].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl);
|
||||
EntityID id1 = gEM.addEntity(tmpl).id;
|
||||
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([CInt.component_id, CLong.component_id].staticArray);
|
||||
EntityTemplate* tmpl2 = gEM.allocateTemplate([ecsID!CInt, ecsID!CLong].staticArray);
|
||||
scope (exit) gEM.freeTemplate(tmpl2);
|
||||
EntityID id2 = gEM.addEntity(tmpl2).id;
|
||||
|
||||
|
|
@ -1471,22 +1471,22 @@ unittest
|
|||
const (EntityManager.UpdatePass)* pass = gEM.getPass("update");
|
||||
assert(pass != null);
|
||||
assert(pass.system_callers.length == 5);
|
||||
assert(pass.system_callers[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[1].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[2].system_id == TestSystem3.system_id);
|
||||
assert(pass.system_callers[3].system_id == TestSystem4.system_id);
|
||||
assert(pass.system_callers[4].system_id == TestSystem5.system_id);
|
||||
assert(pass.system_callers[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[1].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[2].system_id == ecsID!TestSystem3);
|
||||
assert(pass.system_callers[3].system_id == ecsID!TestSystem4);
|
||||
assert(pass.system_callers[4].system_id == ecsID!TestSystem5);
|
||||
assert(pass.system_callers[0].dependencies.length == 0);
|
||||
assert(pass.system_callers[1].dependencies.length == 1);
|
||||
assert(pass.system_callers[2].dependencies.length == 1);
|
||||
assert(pass.system_callers[3].dependencies.length == 3);
|
||||
assert(pass.system_callers[4].dependencies.length == 1);
|
||||
assert(pass.system_callers[1].dependencies[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[2].dependencies[0].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[3].dependencies[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[3].dependencies[1].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[3].dependencies[2].system_id == TestSystem3.system_id);
|
||||
assert(pass.system_callers[4].dependencies[0].system_id == TestSystem4.system_id);
|
||||
assert(pass.system_callers[1].dependencies[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[2].dependencies[0].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[3].dependencies[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[3].dependencies[1].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[3].dependencies[2].system_id == ecsID!TestSystem3);
|
||||
assert(pass.system_callers[4].dependencies[0].system_id == ecsID!TestSystem4);
|
||||
}
|
||||
|
||||
@("ExternalSystemDependencies")
|
||||
|
|
@ -1598,21 +1598,21 @@ unittest
|
|||
const (EntityManager.UpdatePass)* pass = gEM.getPass("update");
|
||||
assert(pass != null);
|
||||
assert(pass.system_callers.length == 5);
|
||||
assert(pass.system_callers[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[1].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[2].system_id == TestSystem3.system_id);
|
||||
assert(pass.system_callers[3].system_id == TestSystem4.system_id);
|
||||
assert(pass.system_callers[4].system_id == TestSystem5.system_id);
|
||||
assert(pass.system_callers[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[1].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[2].system_id == ecsID!TestSystem3);
|
||||
assert(pass.system_callers[3].system_id == ecsID!TestSystem4);
|
||||
assert(pass.system_callers[4].system_id == ecsID!TestSystem5);
|
||||
assert(pass.system_callers[0].dependencies.length == 0);
|
||||
assert(pass.system_callers[1].dependencies.length == 1);
|
||||
assert(pass.system_callers[2].dependencies.length == 1);
|
||||
assert(pass.system_callers[3].dependencies.length == 3);
|
||||
assert(pass.system_callers[4].dependencies.length == 2);
|
||||
assert(pass.system_callers[1].dependencies[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[2].dependencies[0].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[3].dependencies[0].system_id == TestSystem.system_id);
|
||||
assert(pass.system_callers[3].dependencies[1].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[3].dependencies[2].system_id == TestSystem3.system_id);
|
||||
assert(pass.system_callers[4].dependencies[0].system_id == TestSystem2.system_id);
|
||||
assert(pass.system_callers[4].dependencies[1].system_id == TestSystem4.system_id);
|
||||
assert(pass.system_callers[1].dependencies[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[2].dependencies[0].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[3].dependencies[0].system_id == ecsID!TestSystem);
|
||||
assert(pass.system_callers[3].dependencies[1].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[3].dependencies[2].system_id == ecsID!TestSystem3);
|
||||
assert(pass.system_callers[4].dependencies[0].system_id == ecsID!TestSystem2);
|
||||
assert(pass.system_callers[4].dependencies[1].system_id == ecsID!TestSystem4);
|
||||
}
|
||||
12
tests/bugs.d
12
tests/bugs.d
|
|
@ -21,14 +21,14 @@ unittest
|
|||
{
|
||||
struct Event1
|
||||
{
|
||||
mixin ECS.Event;
|
||||
// mixin ECS.Event;
|
||||
|
||||
EntityID id;
|
||||
}
|
||||
|
||||
struct Event2
|
||||
{
|
||||
mixin ECS.Event;
|
||||
// mixin ECS.Event;
|
||||
}
|
||||
|
||||
struct System1
|
||||
|
|
@ -45,7 +45,7 @@ unittest
|
|||
|
||||
void onCreate()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CInt.component_id, CLong.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CInt, ecsID!CLong].staticArray);
|
||||
}
|
||||
|
||||
void onDestroy()
|
||||
|
|
@ -118,7 +118,7 @@ unittest
|
|||
|
||||
gEM.endRegister();
|
||||
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([CInt.component_id, CLong.component_id].staticArray);
|
||||
EntityTemplate* tmpl = gEM.allocateTemplate([ecsID!CInt, ecsID!CLong].staticArray);
|
||||
EntityID id = gEM.addEntity(tmpl,[CLong(10).ref_, CInt(6).ref_].staticArray).id;
|
||||
EntityID id2 = gEM.addEntity(tmpl,[CInt(4).ref_].staticArray).id;
|
||||
gEM.freeTemplate(tmpl);
|
||||
|
|
@ -126,13 +126,13 @@ unittest
|
|||
|
||||
gEM.sendEvent(id2, Event1(id));
|
||||
|
||||
gEM.getSystem(System2.system_id).disable();
|
||||
gEM.getSystem(ecsID!System2).disable();
|
||||
|
||||
gEM.begin();
|
||||
gEM.update();
|
||||
gEM.end();
|
||||
|
||||
gEM.getSystem(System2.system_id).enable();
|
||||
gEM.getSystem(ecsID!System2).enable();
|
||||
|
||||
gEM.begin();
|
||||
gEM.update();
|
||||
|
|
|
|||
16
tests/perf.d
16
tests/perf.d
|
|
@ -86,22 +86,22 @@ void afterEveryTest()
|
|||
|
||||
void smallTmpl()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CShort.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CShort].staticArray);
|
||||
}
|
||||
|
||||
void bigTmpl()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CBig.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CBig].staticArray);
|
||||
}
|
||||
|
||||
void multiSmallTmpl()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CShort.component_id, CLong.component_id, CInt.component_id, CUInt.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CShort, ecsID!CLong, ecsID!CInt, ecsID!CUInt].staticArray);
|
||||
}
|
||||
|
||||
void multiBigTmpl()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CLong.component_id, CInt.component_id, CUInt.component_id, CBig.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CLong, ecsID!CInt, ecsID!CUInt, ecsID!CBig].staticArray);
|
||||
}
|
||||
|
||||
@("AddEntities100k1comp2b") @(before, &smallTmpl)
|
||||
|
|
@ -138,25 +138,25 @@ void allocDealloc100k()
|
|||
|
||||
void smallTmplPreAlloc()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CShort.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CShort].staticArray);
|
||||
allocDealloc100k();
|
||||
}
|
||||
|
||||
void bigTmplPreAlloc()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CBig.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CBig].staticArray);
|
||||
allocDealloc100k();
|
||||
}
|
||||
|
||||
void multiSmallTmplPreAlloc()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CShort.component_id, CLong.component_id, CInt.component_id, CUInt.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CShort, ecsID!CLong, ecsID!CInt, ecsID!CUInt].staticArray);
|
||||
allocDealloc100k();
|
||||
}
|
||||
|
||||
void multiBigTmplPreAlloc()
|
||||
{
|
||||
tmpl = gEM.allocateTemplate([CLong.component_id, CInt.component_id, CUInt.component_id, CBig.component_id].staticArray);
|
||||
tmpl = gEM.allocateTemplate([ecsID!CLong, ecsID!CInt, ecsID!CUInt, ecsID!CBig].staticArray);
|
||||
allocDealloc100k();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue