-added first mmcommando commit
This commit is contained in:
parent
77f67004dd
commit
7e7658af3b
2 changed files with 70 additions and 7 deletions
|
|
@ -21,6 +21,7 @@ import ecs.id_manager;
|
||||||
import ecs.system;
|
import ecs.system;
|
||||||
import ecs.vector;
|
import ecs.vector;
|
||||||
import ecs.events;
|
import ecs.events;
|
||||||
|
import ecs.traits;
|
||||||
|
|
||||||
alias gEM = EntityManager.instance;
|
alias gEM = EntityManager.instance;
|
||||||
alias gEntityManager = EntityManager.instance;
|
alias gEntityManager = EntityManager.instance;
|
||||||
|
|
@ -248,7 +249,7 @@ class EntityManager
|
||||||
//dfmt off
|
//dfmt off
|
||||||
static if(hasMember!(Sys,"EventInput"))
|
static if(hasMember!(Sys,"EventInput"))
|
||||||
{
|
{
|
||||||
static string genEventCompList()()
|
/*static string genEventCompList()()
|
||||||
{
|
{
|
||||||
string ret = "Sys.EventInput input;\n";
|
string ret = "Sys.EventInput input;\n";
|
||||||
string type;
|
string type;
|
||||||
|
|
@ -282,11 +283,45 @@ class EntityManager
|
||||||
~ ").sizeof);\n";
|
~ ").sizeof);\n";
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//pragma(msg,genEventCompList());
|
//pragma(msg,genEventCompList());
|
||||||
//pragma(msg,genEventCompList());
|
//pragma(msg,genEventCompList());
|
||||||
|
|
||||||
|
static void genEventCompList(Sys)(ref EventCallData data, EntityInfo* info, ref Sys.EventInput input)
|
||||||
|
{
|
||||||
|
alias EventFields=Fields!(Sys.EventInput);
|
||||||
|
foreach (eventFieldNum, ref eventField; input.tupleof)
|
||||||
|
{
|
||||||
|
alias EventFieldType = Unqual!(typeof(*eventField));
|
||||||
|
enum bool isEntity = is( EventFieldType == ecs.entity.Entity );
|
||||||
|
|
||||||
|
static if(isEntity)
|
||||||
|
{
|
||||||
|
eventField=cast(Entity*) data.block.dataBegin() + data.id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
enum long indexInEntitiesData=getIndexOfTypeInEntitiesData!(Sys.EntitiesData, EventFieldType);
|
||||||
|
static assert(indexInEntitiesData != -1);// Type present in EventInput has to be present in EntitiesData
|
||||||
|
|
||||||
|
enum bool isOptional = hasUDA!(Sys.EntitiesData.tupleof[indexInEntitiesData], "optional");
|
||||||
|
static if(isOptional)
|
||||||
|
{
|
||||||
|
eventField=null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventField = cast(EventFieldType*)(cast(void*) data.block
|
||||||
|
+ info.deltas[EventFieldType.component_id]
|
||||||
|
+ data.id * EventFieldType.sizeof);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static string checkHandler()(string member)
|
static string checkHandler()(string member)
|
||||||
{
|
{
|
||||||
string ret;
|
string ret;
|
||||||
|
|
@ -325,7 +360,9 @@ class EntityManager
|
||||||
ret ~= "static void callHandler"~event_handlers.to!string~"(ref EventCallData data)\n{\n";
|
ret ~= "static void callHandler"~event_handlers.to!string~"(ref EventCallData data)\n{\n";
|
||||||
ret ~= "Sys* s = cast(Sys*) data.system_pointer;
|
ret ~= "Sys* s = cast(Sys*) data.system_pointer;
|
||||||
EntityInfo* info = data.block.type_info;";
|
EntityInfo* info = data.block.type_info;";
|
||||||
ret ~= genEventCompList();
|
//ret ~= genEventCompList();
|
||||||
|
ret ~= "Sys.EventInput input;\n";
|
||||||
|
ret ~= "genEventCompList!(Sys)(data, info, input);";
|
||||||
ret ~= "s.handleEvent(input, *cast("~event_param~"*)data.event);";
|
ret ~= "s.handleEvent(input, *cast("~event_param~"*)data.event);";
|
||||||
ret ~= "}\n";
|
ret ~= "}\n";
|
||||||
ret ~= "system.m_event_callers["~event_handlers.to!string~"].callback = cast(void*)&callHandler"~event_handlers.to!string~";";
|
ret ~= "system.m_event_callers["~event_handlers.to!string~"].callback = cast(void*)&callHandler"~event_handlers.to!string~";";
|
||||||
|
|
@ -1171,7 +1208,7 @@ class EntityManager
|
||||||
info.size = EntityID.sizeof;
|
info.size = EntityID.sizeof;
|
||||||
info.alignment = EntityID.alignof;
|
info.alignment = EntityID.alignof;
|
||||||
|
|
||||||
info.tmpl_deltas = Mallocator.instance.makeArray!ushort(ids[$ - 1] + 1,ushort.max);
|
info.tmpl_deltas = Mallocator.instance.makeArray!ushort(ids[$ - 1] + 1, ushort.max);
|
||||||
uint components_size = EntityID.sizeof;
|
uint components_size = EntityID.sizeof;
|
||||||
|
|
||||||
foreach (i, id; ids)
|
foreach (i, id; ids)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,38 @@ module ecs.traits;
|
||||||
|
|
||||||
import std.traits;
|
import std.traits;
|
||||||
|
|
||||||
bool isForeachDelegateWithTypes(DG, Types...)() {
|
bool isForeachDelegateWithTypes(DG, Types...)()
|
||||||
|
{
|
||||||
return is(DG == delegate) && is(ReturnType!DG == int) && is(Parameters!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(int, int), int, int));
|
||||||
assert(isForeachDelegateWithTypes!(int delegate(ref int, ref int), int, int));
|
assert(isForeachDelegateWithTypes!(int delegate(ref int, ref int), int, int));
|
||||||
assert(!isForeachDelegateWithTypes!(int delegate(double), 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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue