Hello forum!
I have following modules: Audio, Window/Graphics (renderer), (Keyboard-)Inputs and the current Level.
Audio and Window are a direct part of the engine class. The engine class is the first class that gets created and simply owns game states, audio- and graphics-module.
The level state is active once the player actually decided to play. As a result, the level-module is part of this state.
Within the level-module resides the actual collection of entities and their components.
Now, when the level state is being iterated over, the level module iterates over all graphics components of each entity (e.g. player or enemy). The graphics component have to use quite some getters to finally obtain the graphics module and force it draw them.
Same for the audio-module.
While the combination of getters convey "ah, this the dependency-chain", it creates the issue, that modules need to know about the existence of other modules.
Is it wise to switch this to a more centralised approach?
If yes, what design pattern would suit here to avoid that?
My idea: Using a messenger module. All other modules only need to know the messenger. An audio component uses getters to return the messenger module and creates a to-do-task.
E.g. "audio", "play sound" and "audio proxy".
Once all components are done, the upper modules start to iterate over their very own message board array/list/... and simply do what is needed.
While I can see the audio module removing tasks, the renderer module cannot.
Every graphics component would add x-coordinate, y-coordinate and the texture-proxy/vertex array.
This is being executed by the graphics module every frame. Once a graphics component wants to change their data, they can simply update their given task in the message board.
Drawback: It increases the amount of allocated memory. Which is not that of a huge amount, as we are talking about strings and pointers.
I know there is the KISS-principle - but I thought it might be a wonderful way of learning how to tackle this dependency-"issue".
Thanks for taking your time to read my thread, I'm really curious on what wonderful solution exist for this case : )