Original Post
Edit: Sorry, I should have said, this is c++.
Could someone please help me out with some code.
I have a global class - cGameEngine.
I have two other classes - cRenderEngine and cGameStates.
cGameEngine manages the game, initialises the other two classes and manages the game states.
cRenderEngine handles OpenGL, and cGameStates is an abstract base class from which I derive my game states - InitialState, PlayState and so on.
So far cGameEngine initialises cRenderEngine on creation and has functions to Model 3D, 2D and to render - called through the renderengine object.
cGameEngine also creates a game states stack, and initialises some game states.
So far so good (although I have no idea if this is a wise way of doing things - it's as far as I've been able to work out).
What I want to happen, is for the game states to handle the renderengine though the gamengine object.
I can get the renderengine to function through the gameengine object, because the renderengine object is a member of the game engine object, but I can't get the game state objects to access the gameengine object, because the game states are object members of gameengine.
I understand that I need to pass a pointer from gameengine to the game states, but I can't find how to do this with out upsetting something.
I've managed to find a way to pass a gameengine pointer as far as the gamestates base class, but it isn't inherited by the derived game state objects, and gives me an error regarding explicit and default constructors.
Could some body please provide the code I would need to add to the cGameStates abstract base class, and the derived gamestate classes.
Also, is this a sensible way of doing things? It seems pretty tidy, but I'm a bit worried about memory leaks and so on, not really knowing how to look for them.
Thanks to everyone looks and/or comments.
Could someone please help me out with some code.
I have a global class - cGameEngine.
I have two other classes - cRenderEngine and cGameStates.
cGameEngine manages the game, initialises the other two classes and manages the game states.
cRenderEngine handles OpenGL, and cGameStates is an abstract base class from which I derive my game states - InitialState, PlayState and so on.
So far cGameEngine initialises cRenderEngine on creation and has functions to Model 3D, 2D and to render - called through the renderengine object.
cGameEngine also creates a game states stack, and initialises some game states.
So far so good (although I have no idea if this is a wise way of doing things - it's as far as I've been able to work out).
What I want to happen, is for the game states to handle the renderengine though the gamengine object.
I can get the renderengine to function through the gameengine object, because the renderengine object is a member of the game engine object, but I can't get the game state objects to access the gameengine object, because the game states are object members of gameengine.
I understand that I need to pass a pointer from gameengine to the game states, but I can't find how to do this with out upsetting something.
I've managed to find a way to pass a gameengine pointer as far as the gamestates base class, but it isn't inherited by the derived game state objects, and gives me an error regarding explicit and default constructors.
Could some body please provide the code I would need to add to the cGameStates abstract base class, and the derived gamestate classes.
Also, is this a sensible way of doing things? It seems pretty tidy, but I'm a bit worried about memory leaks and so on, not really knowing how to look for them.
Thanks to everyone looks and/or comments.