bubel-ecs/source/ecs/traits.d
Dawid Masiukiewicz 54a6d5dec2 CI and common update:
-added webpage deploymnet stage
-added separate build stage which build all binaries and generate documentation
-added Emscripten build stage for merge to master only
-added VBO batch rendering (current default, no render mode switch yet)
-fixed camera positioning calculation
-fixed buffer issue with WebGL
-added viewport scalling (at least 300 pixels height). Pixels are scalled if screen is bigger.
-center demos gameplay area
-added fullpage html template for Emscripten build
2020-05-01 19:26:21 +00:00

39 lines
1.1 KiB
D

module ecs.traits;
import std.traits;
bool isForeachDelegateWithTypes(DG, Types...)()
{
return is(DG == delegate) && is(ReturnType!DG == int) && is(Parameters!DG == Types);
}
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;
}