My game base consists of a series of modules organized as classes that are created, updated and interact as needed.
A few examples might be: CWindowManager , CGraphicsManager , CPhysicsManager , etc.
I am ashamed to say that I am currently using global pointers for them ( extern CWindowManager* g_WindowManager; ), and I know that this is probably bad.
In any case, the fact is that these modules must be created and deleted dynamically, and this is in the correct order, of course. The problem is also that modules like CPhysicsManager are scene dependent, so they are deleted when the scene switches and then is re-created.
Now I would like to abandon the use of globals to work with modules in my game.
I am not afraid of refactoring, but I cannot think of what would be the best alternative to globals.
I was thinking of creating a CModuleManager class and storing the module instances there as members, which are then produced from the CModule base class. Although I can not imagine how this will work in detail.
This seems like a common problem in software development and especially in game development, therefore:
- What is the best option for managing modules compared to simply using global pointers?
source share