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:
Mergul 2020-07-08 22:04:13 +02:00
parent b0b64b965f
commit a0efa4e67d
5 changed files with 53 additions and 15 deletions

View file

@ -118,7 +118,8 @@
"-unittest"
],
"dflags-gdc": [
"-fno-druntime"
"-fno-druntime",
"-lpthread"
],
"sourcePaths": ["source/","tests/"],
"mainSourceFile":"tests/runner.d",

View file

@ -42,7 +42,7 @@ struct Entity
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.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);
}
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;
return true;
}

View file

@ -382,7 +382,8 @@ export struct EntityManager
else
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;
System system;
@ -421,7 +422,8 @@ export struct EntityManager
static if (Params.length == 2 && is(Params[0] == Entity*))
{
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);
assert(evt != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing event \"" ~ EventName ~ "\".");
@ -482,7 +484,8 @@ export struct EntityManager
string name;
static if (isArray!MemberType)
{ // 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;
@ -707,7 +710,8 @@ export struct EntityManager
string name;
static if (isArray!MemberType)
{ // 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;
}
@ -763,7 +767,7 @@ export struct EntityManager
{
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));
}
@ -1259,8 +1263,9 @@ export struct EntityManager
{
ComponentInfo info;
enum ComponentName = fullyQualifiedName!Comp;
//enum ComponentName = Comp.stringof;
// enum ComponentName = fullyQualifiedName!Comp;
enum ComponentName = fullName!Comp;
// enum ComponentName = Comp.stringof;
static if (!(hasMember!(Comp, "component_id")) || !is(typeof(Comp.component_id) == ushort))
{
@ -1337,7 +1342,7 @@ export struct EntityManager
info.alignment = Ev.alignof;
//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)
{
Ev.event_id = event_id;
@ -1347,7 +1352,7 @@ export struct EntityManager
events.add(info);
Ev.event_id = 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));
}
}

View file

@ -37,3 +37,35 @@ static long getIndexOfTypeInEntitiesData(EntitiesData, Type)()
}
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);
}

View file

@ -401,7 +401,7 @@ unittest
System* ecs_system = gEM.getSystem(EmptySystem.system_id);
assert(ecs_system !is null);
assert(ecs_system.id == EmptySystem.system_id);
assert(ecs_system.name == "EmptySystem");
assert(ecs_system.name == "tests.basic.EmptySystem");
gEM.begin();
@ -605,7 +605,7 @@ unittest
assert(ecs_system !is null);
assert(ecs_system.id == LongAddSystem.system_id);
assert(ecs_system.priority == -1);
assert(ecs_system.name == "LongAddSystem");
assert(ecs_system.name == "tests.basic.LongAddSystem");
ushort[1] ids = [CLong.component_id];
EntityTemplate* tmpl = gEM.allocateTemplate(ids);