-fixed issue with ExcludedComponents as enum or alias

-removed way to add excluded component by adding attribiute @excluded (it's very stupid way)
This commit is contained in:
Mergul 2019-04-06 20:27:28 +00:00
parent fe158e1b60
commit 9220a28f7c
3 changed files with 23 additions and 28 deletions

View file

@ -2,7 +2,7 @@ module ecs.attributes;
///Used to mark optional components for system. ///Used to mark optional components for system.
enum optional = "optional"; enum optional = "optional";
///Used to mark components excluded from update for system. Enum 'ExcludedComponents' should be used instead of it. //Used to mark components excluded from update for system. Enum 'ExcludedComponents' should be used instead of it.
enum excluded = "excluded"; //enum excluded = "excluded";
///Used to mark readonly components for system. "const" can be used insted. ///Used to mark readonly components for system. "const" can be used insted.
enum readonly = "readonly"; enum readonly = "readonly";

View file

@ -349,16 +349,16 @@ class EntityManager
} }
bool checkExcludedComponentsSomething(Sys)()
{
return __traits(compiles, allSameType!(string, typeof(Sys.ExcludedComponents))) && allSameType!(string,
typeof(Sys.ExcludedComponents)) && isExpressions!(Sys.ExcludedComponents);
}
static ComponentsIndices getComponentsInfo() static ComponentsIndices getComponentsInfo()
{ {
ComponentsIndices components_info; ComponentsIndices components_info;
bool checkExcludedComponentsSomething(Sys)()
{
return __traits(compiles, allSameType!(string, typeof(Sys.ExcludedComponents))) && allSameType!(string,
typeof(Sys.ExcludedComponents)) && isExpressions!(Sys.ExcludedComponents);
}
foreach (member; __traits(allMembers, Sys.EntitiesData)) foreach (member; __traits(allMembers, Sys.EntitiesData))
{ {
alias MemberType = typeof(__traits(getMember, Sys.EntitiesData, member)); alias MemberType = typeof(__traits(getMember, Sys.EntitiesData, member));
@ -375,7 +375,7 @@ class EntityManager
} }
bool is_optional; bool is_optional;
bool is_excluded; //bool is_excluded;
bool is_read_only; bool is_read_only;
if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int))) if (is(CopyConstness!(ForeachType!(MemberType), int) == const(int)))
@ -389,10 +389,10 @@ class EntityManager
{ {
is_optional = true; is_optional = true;
} }
else if (att == "excluded") /*else if (att == "excluded")
{ {
is_excluded = true; is_excluded = true;
} }*/
if (att == "readonly") if (att == "readonly")
{ {
is_read_only = true; is_read_only = true;
@ -406,10 +406,10 @@ class EntityManager
{ {
components_info.mutable ~= CompInfo(member,name); components_info.mutable ~= CompInfo(member,name);
} }
if (is_excluded) /*if (is_excluded)
{ {
components_info.excluded ~= CompInfo(member,name); components_info.excluded ~= CompInfo(member,name);
} }*/
if (is_optional) if (is_optional)
{ {
components_info.optional ~= CompInfo(member,name); components_info.optional ~= CompInfo(member,name);
@ -418,13 +418,13 @@ class EntityManager
{ {
components_info.readonly ~= CompInfo(member,name); components_info.readonly ~= CompInfo(member,name);
} }
if (is_excluded == false && is_optional == false) if (/*is_excluded == false &&*/ is_optional == false)
{ //is Req { //is Req
components_info.req ~= CompInfo(member,name); components_info.req ~= CompInfo(member,name);
} }
assert(!(is_optional && is_excluded), /*assert(!(is_optional && is_excluded),
"EntitiesData member can't have both \"@optional\" and \"@excluded\"."); "EntitiesData member can't have both \"@optional\" and \"@excluded\".");*/
} }
@ -432,21 +432,16 @@ class EntityManager
{ {
static if (is(Sys.ExcludedComponents == enum)) static if (is(Sys.ExcludedComponents == enum))
{ {
foreach (str; Fields!(Sys.ExcludedComponents)) foreach (str; __traits(allMembers, Sys.ExcludedComponents))
{ {
ComponentInfo info; components_info.excluded ~= CompInfo(str,str);
info.is_excluded = true;
info.name = str.stringof;
} }
} }
else static if (checkExcludedComponentsSomething!Sys) else static if (checkExcludedComponentsSomething!Sys)
{ {
foreach (str; Sys.ExcludedComponents) foreach (str; Sys.ExcludedComponents)
{ {
ComponentInfo info; components_info.excluded ~= CompInfo(str,str);
info.is_excluded = true;
info.name = str;
} }
} }

View file

@ -344,14 +344,14 @@ struct TestSystem2
{ {
mixin ECS.System!16; //__gshared ushort system_id; mixin ECS.System!16; //__gshared ushort system_id;
/*enum ExcludedComponents0 /*enum ExcludedComponents
{ {
TestComp, TestComp,
TestComp4 TestComp4
} }*/
alias ExcludedComponents = AliasSeq!("TestComp", "TestComp4");
//alias ExcludedComponents = AliasSeq!("TestComp", "TestComp4");
/*
string ExcludedComponents2;*/ string ExcludedComponents2;*/
static struct EntitiesData static struct EntitiesData