I'm working on this game engine of increasing complexity and before I really start messing up the connectivity between different objects, I wanted to ask you for some professional opinions on the subject.
Consider the following ownership hierarchy, I hope the class names kind of explain their purpose (a "doodad" is any static game object, such as a tree or rock):
CApplication (1) CGraphics (1) CInput (1) CTimer (1) CScene (1) CPlayer (1) CMonster (N) CDoodad (N)In many cases I want to pass information from the graphics or timer object into a monster or doodad object, previously I've done so by passing them as pointer arguments in their respective methods:
CMonster::Update( CGraphics* pGraphics, CTimer* pTimer );
When an object is updated or rendered it calls the same method for every other object that it owns, and this means that if I pass objects by reference then I have to either store the pointer internally or pass it as a function argument all the way from the top of the hierarchy (I personally dislike the idea of having to store the direct pointer, just in case I have to recreate some object instance).
I'm starting to realize that my application is becoming cluttered and a bit obscure. The best solution I could think of myself is to pass the root CApplication instance as a reference into every newly created object and store it internally (this is one class instance that should never get recreated during the running of the application).
So my real question is, is this a good idea or is there a better solution?
Many thanks in advance !
- Dave