Fixed unittests and betterC compilation (after adding fullyQualifiedName instead of simple stringof)
-added new trait to get full name of structure (witho module and package, not tested on more nested packages) -some small improvements (like adding const to function which need it)
This commit is contained in:
parent
b0b64b965f
commit
a0efa4e67d
5 changed files with 53 additions and 15 deletions
3
dub.json
3
dub.json
|
|
@ -118,7 +118,8 @@
|
||||||
"-unittest"
|
"-unittest"
|
||||||
],
|
],
|
||||||
"dflags-gdc": [
|
"dflags-gdc": [
|
||||||
"-fno-druntime"
|
"-fno-druntime",
|
||||||
|
"-lpthread"
|
||||||
],
|
],
|
||||||
"sourcePaths": ["source/","tests/"],
|
"sourcePaths": ["source/","tests/"],
|
||||||
"mainSourceFile":"tests/runner.d",
|
"mainSourceFile":"tests/runner.d",
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ struct Entity
|
||||||
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);
|
return cast(T*)(cast(void*)block + info.deltas[T.component_id] + block.entityIndex(&this) * T.sizeof);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasComponent(ushort component_id)
|
bool hasComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
EntityManager.EntitiesBlock* block = gEM.getMetaData(&this);
|
||||||
EntityManager.EntityInfo* info = block.type_info;
|
EntityManager.EntityInfo* info = block.type_info;
|
||||||
|
|
@ -72,9 +72,9 @@ struct EntityMeta
|
||||||
return cast(T*)(cast(void*)block + block.type_info.deltas[T.component_id] + index * T.sizeof);
|
return cast(T*)(cast(void*)block + block.type_info.deltas[T.component_id] + index * T.sizeof);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasComponent(ushort component_id)
|
bool hasComponent(ushort component_id) const
|
||||||
{
|
{
|
||||||
EntityManager.EntityInfo* info = block.type_info;
|
const EntityManager.EntityInfo* info = block.type_info;
|
||||||
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
if (component_id >= info.deltas.length || info.deltas[component_id] == 0)return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,8 @@ export struct EntityManager
|
||||||
else
|
else
|
||||||
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
|
||||||
|
|
||||||
enum SystemName = fullyQualifiedName!Sys;
|
// enum SystemName = fullyQualifiedName!Sys;
|
||||||
|
enum SystemName = fullName!Sys;
|
||||||
//enum SystemName = Sys.stringof;
|
//enum SystemName = Sys.stringof;
|
||||||
|
|
||||||
System system;
|
System system;
|
||||||
|
|
@ -421,7 +422,8 @@ export struct EntityManager
|
||||||
static if (Params.length == 2 && is(Params[0] == Entity*))
|
static if (Params.length == 2 && is(Params[0] == Entity*))
|
||||||
{
|
{
|
||||||
alias EventParamType = Params[1];
|
alias EventParamType = Params[1];
|
||||||
enum EventName = fullyQualifiedName!(Unqual!(EventParamType));//.stringof;
|
enum EventName = fullName!(Unqual!(EventParamType));
|
||||||
|
// enum EventName = fullyQualifiedName!(Unqual!(EventParamType));//.stringof;
|
||||||
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
|
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
|
||||||
assert(evt != ushort.max, "Can't register system \"" ~ SystemName
|
assert(evt != ushort.max, "Can't register system \"" ~ SystemName
|
||||||
~ "\" due to non existing event \"" ~ EventName ~ "\".");
|
~ "\" due to non existing event \"" ~ EventName ~ "\".");
|
||||||
|
|
@ -482,7 +484,8 @@ export struct EntityManager
|
||||||
string name;
|
string name;
|
||||||
static if (isArray!MemberType)
|
static if (isArray!MemberType)
|
||||||
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
||||||
name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));//.stringof;
|
// name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));//.stringof;
|
||||||
|
name = fullName!(Unqual!(ForeachType!MemberType));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_optional;
|
bool is_optional;
|
||||||
|
|
@ -707,7 +710,8 @@ export struct EntityManager
|
||||||
string name;
|
string name;
|
||||||
static if (isArray!MemberType)
|
static if (isArray!MemberType)
|
||||||
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
{ // Workaround. This code is never called with: not an array type, but compiler prints an error
|
||||||
name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
|
// name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
|
||||||
|
name = fullName!(Unqual!(ForeachType!MemberType));
|
||||||
//name = Unqual!(ForeachType!MemberType).stringof;
|
//name = Unqual!(ForeachType!MemberType).stringof;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -763,7 +767,7 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
foreach (str; Sys.ExcludedComponents)
|
foreach (str; Sys.ExcludedComponents)
|
||||||
{
|
{
|
||||||
components_info.addExcluded(CompInfo(str.stringof, fullyQualifiedName!str));
|
components_info.addExcluded(CompInfo(str.stringof, fullName!str));
|
||||||
// components_info.addExcluded(CompInfo(str.stringof, str.stringof));
|
// components_info.addExcluded(CompInfo(str.stringof, str.stringof));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1259,8 +1263,9 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
ComponentInfo info;
|
ComponentInfo info;
|
||||||
|
|
||||||
enum ComponentName = fullyQualifiedName!Comp;
|
// enum ComponentName = fullyQualifiedName!Comp;
|
||||||
//enum ComponentName = Comp.stringof;
|
enum ComponentName = fullName!Comp;
|
||||||
|
// enum ComponentName = Comp.stringof;
|
||||||
|
|
||||||
static if (!(hasMember!(Comp, "component_id")) || !is(typeof(Comp.component_id) == ushort))
|
static if (!(hasMember!(Comp, "component_id")) || !is(typeof(Comp.component_id) == ushort))
|
||||||
{
|
{
|
||||||
|
|
@ -1337,7 +1342,7 @@ export struct EntityManager
|
||||||
info.alignment = Ev.alignof;
|
info.alignment = Ev.alignof;
|
||||||
|
|
||||||
//ushort event_id = events_map.get(Ev.stringof, ushort.max);
|
//ushort event_id = events_map.get(Ev.stringof, ushort.max);
|
||||||
ushort event_id = events_map.get(fullyQualifiedName!Ev, ushort.max);
|
ushort event_id = events_map.get(fullName!Ev, ushort.max);
|
||||||
if (event_id < events.length)
|
if (event_id < events.length)
|
||||||
{
|
{
|
||||||
Ev.event_id = event_id;
|
Ev.event_id = event_id;
|
||||||
|
|
@ -1347,7 +1352,7 @@ export struct EntityManager
|
||||||
events.add(info);
|
events.add(info);
|
||||||
Ev.event_id = cast(ushort)(events.length - 1);
|
Ev.event_id = cast(ushort)(events.length - 1);
|
||||||
// events_map.add(Ev.stringof, cast(ushort)(events.length - 1));
|
// events_map.add(Ev.stringof, cast(ushort)(events.length - 1));
|
||||||
events_map.add(fullyQualifiedName!Ev, cast(ushort)(events.length - 1));
|
events_map.add(fullName!Ev, cast(ushort)(events.length - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,3 +37,35 @@ static long getIndexOfTypeInEntitiesData(EntitiesData, Type)()
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string attachParentName(alias T, string str)()
|
||||||
|
{
|
||||||
|
alias parent = __traits(parent, T);
|
||||||
|
enum parent_str = parent.stringof;
|
||||||
|
static if(parent_str[0..7] == "module ")
|
||||||
|
{
|
||||||
|
static if(__traits(compiles, __traits(parent, parent)))
|
||||||
|
{
|
||||||
|
return attachParentName!(parent, parent_str[7 .. $] ~ '.' ~ str);
|
||||||
|
}
|
||||||
|
else return parent_str[8 .. $] ~ '.' ~ str;
|
||||||
|
}
|
||||||
|
else static if(parent_str[0..8] == "package ")
|
||||||
|
{
|
||||||
|
static if(__traits(compiles, __traits(parent, parent)))
|
||||||
|
{
|
||||||
|
return attachParentName!(parent, parent_str[8 .. $] ~ '.' ~ str);
|
||||||
|
}
|
||||||
|
else return parent_str[8 .. $] ~ '.' ~ str;
|
||||||
|
}
|
||||||
|
else static if(__traits(compiles, __traits(parent, parent)))
|
||||||
|
{
|
||||||
|
return attachParentName!(parent, parent_str ~ '.' ~ str);
|
||||||
|
}
|
||||||
|
else return parent_str ~ '.' ~ str;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string fullName(T)()
|
||||||
|
{
|
||||||
|
return attachParentName!(T, T.stringof);
|
||||||
|
}
|
||||||
|
|
@ -401,7 +401,7 @@ unittest
|
||||||
System* ecs_system = gEM.getSystem(EmptySystem.system_id);
|
System* ecs_system = gEM.getSystem(EmptySystem.system_id);
|
||||||
assert(ecs_system !is null);
|
assert(ecs_system !is null);
|
||||||
assert(ecs_system.id == EmptySystem.system_id);
|
assert(ecs_system.id == EmptySystem.system_id);
|
||||||
assert(ecs_system.name == "EmptySystem");
|
assert(ecs_system.name == "tests.basic.EmptySystem");
|
||||||
|
|
||||||
gEM.begin();
|
gEM.begin();
|
||||||
|
|
||||||
|
|
@ -605,7 +605,7 @@ unittest
|
||||||
assert(ecs_system !is null);
|
assert(ecs_system !is null);
|
||||||
assert(ecs_system.id == LongAddSystem.system_id);
|
assert(ecs_system.id == LongAddSystem.system_id);
|
||||||
assert(ecs_system.priority == -1);
|
assert(ecs_system.priority == -1);
|
||||||
assert(ecs_system.name == "LongAddSystem");
|
assert(ecs_system.name == "tests.basic.LongAddSystem");
|
||||||
|
|
||||||
ushort[1] ids = [CLong.component_id];
|
ushort[1] ids = [CLong.component_id];
|
||||||
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
EntityTemplate* tmpl = gEM.allocateTemplate(ids);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue