In my project, I have multiple subsystems organized as classes.
I need those classes to communicate (so be able to access the other one via a pointer), and I want to implement this in the best way as possible.
I basically see three possible solutions here:
If subsystem X needs to access subsystem Y, add a member variable to class X pointing to an instance of Y. When X is created, pass to it the pointer to Y and have the member variable
m_pSystemY
set.Declare a global variable
CSystemX * g_SystemX
for every subsystem. It will be filled with a pointer to the freshly created subsystem instance on program start. Later on, you can easily access it from anywhere.Create a sophisticated subsystem manager class. All subsystems are stored in an array. You need to call a function in order to access a specific subsystem.
My questions:
Which one of these solutions should I use for my game engine project?
Does anybody of you have personal experience with any of these methods?