I’m in the process of developing a game. My problem is this.. I’m going to implement the observer pattern to have my game objects “subscribe” to events that happen. For instance one character shoots which in turn creates a “sound event” and other characters will be able to subscribe to “sound events” so they can hear it too.
My block comes from if I have a character class and other class types which will subscribe to those events and I have multiple character objects how will my event dispatcher/message bus have communication to all of the individual objects?
- Would there be a global event dispatcher?
- Should the event dispatcher be a singleton?
- Will the event dispatcher hold references to every individual object that it needs?
- How can I keep this system decoupled and not have a unnecessarily large unmanageable event system?
I’m aware I can have a
std::vector which can store objects of classtype
character and dynamically call each ones
OnEvent function, but should all my objects be communicating with one global event system? (A event system singleton maybe?)