I'm trying to learn how to produce quality object-oriented code and have been studying concepts like SOLID. I'm currently working on an entity-component-process system for a small game engine.
Currently, I have it implemented as such:
- There is a
ScreenStack
which contains a stack ofScreen
s - Each
Screen
has anEntityManager
andProcessManager
. - The
ProcessManager
updates allProcess
es given entities from theEntityManager
. - A
Process
handles all game logic, so it needs to be able to useScreenStack
to possibly push and pop screens. It can also create, remove, and change entities, so it needs theEntityManager
fromScreen
. Basically aProcess
needs to know everything about the game since it affects so much of it, but it feels wrong.
How do I go about implementing this better? It seems like everything has a clear dependency hierarchy until you get to a process, where it gets thrown out the window.
There also seems to be tight coupling when I would want to push a new screen. Say, for example, I have a process in a MainMenu
screen that checks for menu choice. If "New Game" is clicked, I need to push a new screen, which gets created at that moment. I've read that I shouldn't randomly throw in new
which this seems to be doing.