Hello,
I'm getting back into C++, and the first task has been moving my game to C++.
Basically as of now it looks like:
Code:
think_init();
render_init();
while(running == GL_TRUE)
{
/* ... */
think_frame(delta, gameDelta);
/* ... */
render_frame();
}
think_cleanup();
render_cleanup();
Where 'think' & 'render' do the thinking (ie processing input, moving objects, changing the game state) and render just renders the scene according to the state (might be menu & game).
Right now, the 'subsystems' access the data of other subsystems through extern global variables,
render.c
Code:
struct render_s render;
/* blah */
render.h
Code:
extern struct render_s
{
int width, height;
int fps; /* frames per second */
} render;
Anyone can see that's not very wise, anything in my program can change the width/height of 'struct render_s render'. Hence I have turned to C++,
How do I give access to render members to each part of my program at any point in time? I've researched the idea of a singleton, Would it be best to do:
Code:
int main(void)
{
/* ... */
application MyApp(); /* where the MyApp class holds instances of render & think classes */
}
And then share one instance of MyApp() ? (In a file included by all 'classes' perhaps?)
Sorry if my post is so long, but I'm trying to sort this out
Thanks!