-added first mmcommando commit

This commit is contained in:
Mergul 2019-04-06 14:24:31 +00:00
parent 77f67004dd
commit 7e7658af3b
2 changed files with 70 additions and 7 deletions

View file

@ -2,12 +2,38 @@ module ecs.traits;
import std.traits;
bool isForeachDelegateWithTypes(DG, Types...)() {
bool isForeachDelegateWithTypes(DG, Types...)()
{
return is(DG == delegate) && is(ReturnType!DG == int) && is(Parameters!DG == Types);
}
unittest {
unittest
{
assert(isForeachDelegateWithTypes!(int delegate(int, int), int, int));
assert(isForeachDelegateWithTypes!(int delegate(ref int, ref int), int, int));
assert(!isForeachDelegateWithTypes!(int delegate(double), int, int));
}
}
/************************************************************************************************************************
* Returns index of Component/Entity array in System's EntitiesData struct
*/
static long getIndexOfTypeInEntitiesData(EntitiesData, Type)()
{
alias EntitiesDataFields = Fields!(EntitiesData);
long index = -1;
foreach (fieldNum, FieldType; Fields!(EntitiesData))
{
static if (!isBasicType!(FieldType)) // Not basic type
{
// FieldType should be something like: 'const(SomeComponent)[]'
enum bool entitiesMatches = is(Type == Unqual!(ForeachType!(FieldType)));
static if (entitiesMatches)
{
index = fieldNum;
break;
}
}
}
return index;
}