Improve fullName template
fullName now support multi-pararmeter templates
This commit is contained in:
parent
6a600d22c8
commit
1a5452d6cc
3 changed files with 43 additions and 6 deletions
|
|
@ -386,6 +386,7 @@ 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 = __traits(fullyQualifiedName,Sys);
|
||||||
// enum SystemName = fullyQualifiedName!Sys;
|
// enum SystemName = fullyQualifiedName!Sys;
|
||||||
enum SystemName = fullName!Sys;
|
enum SystemName = fullName!Sys;
|
||||||
//enum SystemName = Sys.stringof;
|
//enum SystemName = Sys.stringof;
|
||||||
|
|
@ -427,7 +428,8 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
alias EventParamType = Params[1];
|
alias EventParamType = Params[1];
|
||||||
enum EventName = fullName!(Unqual!(EventParamType));
|
enum EventName = fullName!(Unqual!(EventParamType));
|
||||||
// enum EventName = fullyQualifiedName!(Unqual!(EventParamType));//.stringof;
|
// enum EventName = __traits(fullyQualifiedName,Unqual!(EventParamType));
|
||||||
|
// enum EventName = fullyQualifiedName!(Unqual!(EventParamType));
|
||||||
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
|
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
|
||||||
assert(evt != ushort.max,
|
assert(evt != ushort.max,
|
||||||
"Can't register system \"" ~ SystemName
|
"Can't register system \"" ~ SystemName
|
||||||
|
|
@ -489,8 +491,10 @@ 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 = __traits(fullyQualifiedName,Unqual!(ForeachType!MemberType));
|
||||||
name = fullName!(Unqual!(typeof(MemberType.init[0])));
|
// name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
|
||||||
|
// name = fullName!(Unqual!(typeof(MemberType.init[0])));
|
||||||
|
name = fullName!(Unqual!(Unqual!(ForeachType!MemberType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_optional;
|
bool is_optional;
|
||||||
|
|
@ -715,8 +719,9 @@ 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 = __traits(fullyQualifiedName,Unqual!(ForeachType!MemberType));
|
||||||
// name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
|
// name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
|
||||||
name = fullName!(Unqual!(typeof(MemberType.init[0])));
|
name = fullName!(Unqual!(ForeachType!MemberType));
|
||||||
//name = Unqual!(ForeachType!MemberType).stringof;
|
//name = Unqual!(ForeachType!MemberType).stringof;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1296,6 +1301,7 @@ export struct EntityManager
|
||||||
{
|
{
|
||||||
ComponentInfo info;
|
ComponentInfo info;
|
||||||
|
|
||||||
|
// enum ComponentName = __traits(fullyQualifiedName,Comp);
|
||||||
// enum ComponentName = fullyQualifiedName!Comp;
|
// enum ComponentName = fullyQualifiedName!Comp;
|
||||||
enum ComponentName = fullName!Comp;
|
enum ComponentName = fullName!Comp;
|
||||||
// enum ComponentName = Comp.stringof;
|
// enum ComponentName = Comp.stringof;
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,17 @@ template fullName(alias T : X!A, alias X, A...)
|
||||||
enum fullName = fullName!parent ~ '.' ~ __traits(identifier, X) ~ "!(" ~ fullName!A ~ ")";
|
enum fullName = fullName!parent ~ '.' ~ __traits(identifier, X) ~ "!(" ~ fullName!A ~ ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template fullName(T...)
|
||||||
|
{
|
||||||
|
static if(__traits(compiles, __traits(parent, T[0])))
|
||||||
|
{
|
||||||
|
alias parent = __traits(parent, T[0]);
|
||||||
|
enum fullName = fullName!parent ~ '.' ~ __traits(identifier, T[0]) ~ ", " ~ fullName!(T[1 .. $]);
|
||||||
|
}
|
||||||
|
else static if(__traits(compiles, __traits(identifier, T[0])))enum fullName = __traits(identifier, T[0]) ~ ", " ~ fullName!(T[1 .. $]);
|
||||||
|
else enum fullName = T[0].stringof ~ ", " ~ fullName!(T[1 .. $]);
|
||||||
|
}
|
||||||
|
|
||||||
template fullName(alias T)
|
template fullName(alias T)
|
||||||
{
|
{
|
||||||
static if(__traits(compiles, __traits(parent, T)))
|
static if(__traits(compiles, __traits(parent, T)))
|
||||||
|
|
|
||||||
24
tests/bugs.d
24
tests/bugs.d
|
|
@ -177,6 +177,7 @@ unittest
|
||||||
@("3-template-system-compilation-file")
|
@("3-template-system-compilation-file")
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TemplateSystem(T)
|
struct TemplateSystem(T)
|
||||||
{
|
{
|
||||||
struct EntitiesData
|
struct EntitiesData
|
||||||
|
|
@ -184,8 +185,19 @@ unittest
|
||||||
uint length;
|
uint length;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint a;
|
T a;
|
||||||
uint b;
|
}
|
||||||
|
|
||||||
|
struct TemplateSystem2(T, T2, T3)
|
||||||
|
{
|
||||||
|
struct EntitiesData
|
||||||
|
{
|
||||||
|
uint length;
|
||||||
|
}
|
||||||
|
|
||||||
|
T a;
|
||||||
|
T2 b;
|
||||||
|
T3 c;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TempalteComponent(T)
|
struct TempalteComponent(T)
|
||||||
|
|
@ -193,13 +205,21 @@ unittest
|
||||||
T parameter;
|
T parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TempalteComponent2(T, T2)
|
||||||
|
{
|
||||||
|
T parameter;
|
||||||
|
T2 parameter2;
|
||||||
|
}
|
||||||
|
|
||||||
gEntityManager.initialize(0);
|
gEntityManager.initialize(0);
|
||||||
|
|
||||||
gEntityManager.beginRegister();
|
gEntityManager.beginRegister();
|
||||||
|
|
||||||
gEntityManager.registerComponent!CInt;
|
gEntityManager.registerComponent!CInt;
|
||||||
gEntityManager.registerComponent!(TempalteComponent!uint);
|
gEntityManager.registerComponent!(TempalteComponent!uint);
|
||||||
|
gEntityManager.registerComponent!(TempalteComponent2!(float,int));
|
||||||
gEntityManager.registerSystem!(TemplateSystem!CInt)(0);
|
gEntityManager.registerSystem!(TemplateSystem!CInt)(0);
|
||||||
|
gEntityManager.registerSystem!(TemplateSystem2!(CInt, uint, float))(0);
|
||||||
|
|
||||||
gEntityManager.endRegister();
|
gEntityManager.endRegister();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue