From 6a600d22c812a879b5991329067cb2f7c42debfd Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 27 Apr 2023 23:08:27 +0200 Subject: [PATCH] Refactored fullName template New fullName implementation gives same result as fullyQualifiedName for normal types and templated ones, and still works in BetterC --- source/bubel/ecs/traits.d | 37 +++++++++++-------------------------- tests/basic.d | 16 ++++++++++++++++ tests/bugs.d | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/source/bubel/ecs/traits.d b/source/bubel/ecs/traits.d index 79901db..e18f656 100644 --- a/source/bubel/ecs/traits.d +++ b/source/bubel/ecs/traits.d @@ -63,34 +63,19 @@ static long getIndexOfTypeInEntitiesData(EntitiesData, Type)() return index; } -static string attachParentName(alias T, string str)() +template fullName(alias T : X!A, alias X, A...) { - 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[7 .. $] ~ '.' ~ 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; + alias parent = __traits(parent, X); + enum fullName = fullName!parent ~ '.' ~ __traits(identifier, X) ~ "!(" ~ fullName!A ~ ")"; } -static string fullName(T)() +template fullName(alias T) { - return attachParentName!(T, T.stringof); + static if(__traits(compiles, __traits(parent, T))) + { + alias parent = __traits(parent, T); + enum fullName = fullName!parent ~ '.' ~ __traits(identifier, T); + } + else static if(__traits(compiles, __traits(identifier, T)))enum fullName = __traits(identifier, T); + else enum fullName = T.stringof; } \ No newline at end of file diff --git a/tests/basic.d b/tests/basic.d index ea54382..e353549 100644 --- a/tests/basic.d +++ b/tests/basic.d @@ -160,6 +160,22 @@ void afterEveryTest() gEntityManager.destroy(); } +@("RegisteredNames") +unittest +{ + import bubel.ecs.traits; + + gEntityManager.beginRegister(); + gEntityManager.registerSystem!EmptySystem(0); + gEntityManager.registerSystem!EntityCounterSystem(0); + gEntityManager.endRegister(); + + System* empty_system = gEntityManager.getSystem(becsID!EmptySystem); + System* counter_system = gEntityManager.getSystem(becsID!EntityCounterSystem); + assert(empty_system.name == "tests.basic.EmptySystem", fullName!EmptySystem); + assert(counter_system.name == "tests.basic.EntityCounterSystem", fullName!EntityCounterSystem); +} + @("EntityMeta") unittest { diff --git a/tests/bugs.d b/tests/bugs.d index 10a3c62..9b59973 100644 --- a/tests/bugs.d +++ b/tests/bugs.d @@ -172,4 +172,35 @@ unittest gEntityManager.commit(); gEntityManager.destroy(); -} \ No newline at end of file +} + +@("3-template-system-compilation-file") +unittest +{ + struct TemplateSystem(T) + { + struct EntitiesData + { + uint length; + } + + uint a; + uint b; + } + + struct TempalteComponent(T) + { + T parameter; + } + + gEntityManager.initialize(0); + + gEntityManager.beginRegister(); + + gEntityManager.registerComponent!CInt; + gEntityManager.registerComponent!(TempalteComponent!uint); + gEntityManager.registerSystem!(TemplateSystem!CInt)(0); + + gEntityManager.endRegister(); + +}