Why not have a global message queue, something like:
messageQueue.push_back(shared_ptr<Event>(new DamageEvent(entityB, 10, entityA))); With:
DamageEvent(Entity* toDamage, uint amount, Entity* damageDealer); And at the end of the game loop/event handling:
while(!messageQueue.empty()) {
Event e = messageQueue.front();
messageQueue.pop_front();
e.Execute(); }
I
while(!messageQueue.empty()) { Event e = messageQueue.front(); messageQueue.pop_front(); e.Execute(); } I think this is the Command pattern. And Execute()Execute() is a pure virtual in EventEvent, which derivatives define and do stuff. So here: DamageEvent::Execute() {
toDamage->takeDamage(amount); //Or of course, you could now have entityA get points, or a recognition of damage, or anything.
}
DamageEvent::Execute() { toDamage->takeDamage(amount); // Or of course, you could now have entityA get points, or a recognition of damage, or anything. }