-events are simplified to handleEvent(Entity*,Event) (use entity.getComponent to get entity components)

This commit is contained in:
Mergul 2019-08-13 11:13:26 +00:00
parent 9402e917f2
commit beab56033c
2 changed files with 28 additions and 13 deletions

View file

@ -304,9 +304,9 @@ export class EntityManager
{
static void callEventHandler(Type)(ref EventCallData data)
{
Sys.EventInput input;
//Sys.EventInput input;
Sys* data_system = cast(Sys*) data.system_pointer;
EntityInfo* info = data.block.type_info;
/*EntityInfo* info = data.block.type_info;
alias EventFields = Fields!(Sys.EventInput);
foreach (ref event_field; input.tupleof)
@ -343,8 +343,9 @@ export class EntityManager
}
}
}
data_system.handleEvent(input, *cast(Type*) data.event);
}//*/
Type* event = cast(Type*) data.event;
data_system.handleEvent(/*input, */gEM.getEntity(event.entity_id), *event);
}
void setEventCallers(Sys)(ref System system)
@ -357,7 +358,19 @@ export class EntityManager
{
alias Params = Parameters!(__traits(getOverloads,
Sys, "handleEvent")[j]);
static if(Params.length == 2 && is(Params[0] == __traits(getMember, Sys, "EventInput")))
/*static if(Params.length == 2 && is(Params[0] == __traits(getMember, Sys, "EventInput")))
{
alias EventParamType = Params[1];
enum EventName = Unqual!(EventParamType).stringof;
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
assert(evt != ushort.max, "Can't register system \""~Sys.stringof~"\" due to non existing event \""~EventName~"\".");
callers[i].callback = cast(
void*)&callEventHandler!(EventParamType);
callers[i].id = EventParamType.event_id;
i++;
}*/
static if(Params.length == 2 && is(Params[0] == Entity*))
{
alias EventParamType = Params[1];
enum EventName = Unqual!(EventParamType).stringof;
@ -389,9 +402,9 @@ export class EntityManager
static struct ComponentsIndices
{
CompInfo[] readonly;
CompInfo[] mutable;
CompInfo[] excluded;
CompInfo[] optional;
CompInfo[] mutable;
CompInfo[] req;
string entites_array;
}