Original Post
Hello, I just ran into a (for me) big problem regarding the dependencies between the classes in my game. I am not quite sure how to design my code in a way that I do not have to pass references and pointers over and over again. For now it looks like this: I have a Application class that contains all the subsystem-classes (window, graphics, audio, input, resource manager, scene manager...). But for my taste they depend on each other to much. E.g. the scene manager needs to know about the graphic-subsystem for drawing, the audio subsystem for playing sounds, the resource manager for loading resources and so on. The resource manager needs to know about the graphics subsytem because I need the IDirect3DDevice instanceto load textures. Then the entities in the current scene (that gets handled by the scene manager) needs some access to the graphics subsystem to draw themselves or get drawn, to the audio system to play der sounds ect.). For now my "solution" is to pass around references for all those systems to eather methods or the constructors of the classes they are needed in. Then it looks like this: In the Application-class' main loop, this method get's called:
myScreenManager->Present(myRenderWindow->GetGraphics(), myAudio);
In the scene manager then it looks like this:
void ScreenManager::Present(const shared_ptr<Graphics>& graphics, const shared_ptr<Audio> &audio)
{
myScreens.back()->Present(graphics, audio);
}
Then again the entities, that are contained by the Screen class want to load their resources so they need access to the ResourceManager again... (and so on) I really do not like this because everytime I need to access another part of my engine/game I need to update method's declaration and definition and pass them through a lot of classes until it reaches the point where I acutally need it. And I do not like singletons at all, so I don't want to use them if no one of you will convincw me to do so =) Maybe you have some suggestions or further reading for me on this topic. So, thanks in advance for that, I hope it is quite understandable what I mean ;-) Greetings from Germany Benjamin