I'm putting together a ECS for my game with another two main components: an event bus for communication and a Lua interpreter to load scripts.
Now, the parent element is a framework/game object with references to all this three components. My question is, what is the best communication pattern: drill the interpreter and any other orchestration objects down to every system or centralize all those calls in a subscriptor for the eventbus, and make everything from there.
Example:
// Plan A
public class CollisionEntitySystem extends EntityProcessingSystem {
LuaEngine mEngine;
EventBus mBus;
MoreThings mThings;
public CollisionEntitySystem(LuaEngine engine, EventBus bus, MoreThings things){
mEngine = engine;
mBus = bus;
mThings = things;
}
@Override
protected void process(Entity e) {
//Something wonderful happened here
mEngine.load("onCollision.lua", parameters);
}
};
// Plan B
public class CollisionEntitySystem extends EntityProcessingSystem {
Bus mEventBus;
public CollisionEntitySystem(Bus bus){
mEventBus= bus;
}
@Override
protected void process(Entity e) {
//Something wonderful happened here
mEventBus.post(EventScriptCall.create("OnCollision", paremeters))
}
};
Given that the event bus post is synch the results are the same, so it all boils down to architectural differences: centralized logic and hundreds of event objects or disperse logic with less objects.