Changed Components/System/Events names to full name (with module) and fixed bug with flag

This commit is contained in:
Mergul 2020-07-01 19:26:47 +02:00
parent ffc19d4723
commit ef4faf2755

View file

@ -382,6 +382,9 @@ export struct EntityManager
else
assert(pass < passes.length, "Update pass (ID " ~ pass.to!string ~ ") doesn't exist.");
enum SystemName = fullyQualifiedName!Sys;
//enum SystemName = Sys.stringof;
System system;
system.m_pass = pass;
@ -418,9 +421,9 @@ export struct EntityManager
static if (Params.length == 2 && is(Params[0] == Entity*))
{
alias EventParamType = Params[1];
enum EventName = Unqual!(EventParamType).stringof;
enum EventName = fullyQualifiedName!(Unqual!(EventParamType));//.stringof;
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
assert(evt != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(evt != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing event \"" ~ EventName ~ "\".");
callers[i].callback = cast(void*)&callEventHandler!(EventParamType);
@ -479,7 +482,7 @@ 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 = Unqual!(ForeachType!MemberType).stringof;
name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));//.stringof;
}
bool is_optional;
@ -704,7 +707,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 = Unqual!(ForeachType!MemberType).stringof;
name = fullyQualifiedName!(Unqual!(ForeachType!MemberType));
//name = Unqual!(ForeachType!MemberType).stringof;
}
bool is_optional;
@ -759,7 +763,8 @@ export struct EntityManager
{
foreach (str; Sys.ExcludedComponents)
{
components_info.addExcluded(CompInfo(str.stringof, str.stringof));
components_info.addExcluded(CompInfo(str.stringof, fullyQualifiedName!str));
// components_info.addExcluded(CompInfo(str.stringof, str.stringof));
}
}
@ -828,10 +833,10 @@ export struct EntityManager
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing component.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
system.m_components[iii] = comp;
}
@ -840,10 +845,10 @@ export struct EntityManager
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing component.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
system.m_excluded_components[iii] = comp;
}
@ -852,10 +857,10 @@ export struct EntityManager
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing component.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
system.m_optional_components[iii] = comp;
}
@ -864,10 +869,10 @@ export struct EntityManager
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing component.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
system.m_read_only_components[iii] = comp;
}
@ -876,10 +881,10 @@ export struct EntityManager
ushort comp = components_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing component.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing component \"" ~ comp_info.type ~ "\".");
system.m_writable_components[iii] = comp;
}
@ -1155,10 +1160,10 @@ export struct EntityManager
ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing dependency.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing dependency \"" ~ comp_info.type ~ "\".");
system.m_readonly_dependencies[iii] = comp;
}
@ -1168,15 +1173,15 @@ export struct EntityManager
ushort comp = external_dependencies_map.get(cast(char[]) comp_info.type, ushort.max);
version (D_BetterC)
assert(comp != ushort.max,
"Can't register system \"" ~ Sys.stringof
"Can't register system \"" ~ SystemName
~ "\" due to non existing dependency.");
else
assert(comp != ushort.max, "Can't register system \"" ~ Sys.stringof
assert(comp != ushort.max, "Can't register system \"" ~ SystemName
~ "\" due to non existing dependency \"" ~ comp_info.type ~ "\".");
system.m_writable_dependencies[iii] = comp;
}
ushort sys_id = systems_map.get(cast(char[]) Sys.stringof, ushort.max);
ushort sys_id = systems_map.get(cast(char[]) SystemName, ushort.max);
if (sys_id < systems.length)
{
systems[sys_id].disable();
@ -1195,7 +1200,7 @@ export struct EntityManager
}
else
{
system.m_name = Mallocator.makeArray(cast(char[]) Sys.stringof);
system.m_name = Mallocator.makeArray(cast(char[]) SystemName);
systems_map.add(system.m_name, cast(ushort) systems.length);
@ -1254,6 +1259,9 @@ export struct EntityManager
{
ComponentInfo info;
enum ComponentName = fullyQualifiedName!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;");
@ -1290,7 +1298,7 @@ export struct EntityManager
info.init_data = Mallocator.makeArray!ubyte(Comp.sizeof);
*cast(Comp*) info.init_data.ptr = Comp.init; // = Comp();
ushort comp_id = components_map.get(cast(char[]) Comp.stringof, ushort.max);
ushort comp_id = components_map.get(cast(char[]) ComponentName, ushort.max);
if (comp_id < components.length)
{
Comp.component_id = comp_id;
@ -1300,9 +1308,7 @@ export struct EntityManager
{
components.add(info);
Comp.component_id = cast(ushort)(components.length - 1);
char[] name = Mallocator.makeArray(cast(char[]) Comp.stringof);
/*char[] name = Mallocator.makeArray!char(Comp.stringof.length);
name[0..$] = Comp.stringof;*/
char[] name = Mallocator.makeArray(cast(char[]) ComponentName);
components_map.add(name, cast(ushort)(components.length - 1));
}
}
@ -1330,7 +1336,8 @@ export struct EntityManager
info.size = Ev.sizeof;
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);
if (event_id < events.length)
{
Ev.event_id = event_id;
@ -1339,7 +1346,8 @@ 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(Ev.stringof, cast(ushort)(events.length - 1));
events_map.add(fullyQualifiedName!Ev, cast(ushort)(events.length - 1));
}
}
@ -1861,6 +1869,7 @@ export struct EntityManager
foreach (i, id; ids)
{
if(current_delta == 0)current_delta = ushort.max;
alignNum(current_delta, components[id].alignment);
info.deltas[id] = cast(ushort) current_delta;
current_delta += entites_in_block * components[id].size;