Hello,
I'm new to this whole game programming thing -- but not new to programming. Basically I'm writting a little game in C, and I have a few questions that various books & tutorials I've read seem to miss.
I'm managing internal engine states & looping as such,
menu.h
extern struct menu_s
{
int isAcitve;
} menu;
render.h
extern struct render_s
{
int maxfps;
} render;
render.c
void render_frame(void)
{
/* render everything */
if(menu.isActive)
menu_render();
}
think.c
/* physics, animation & such (update game states) */
void think_frame(float delta)
{
/* ... */
if(menu.isActive)
menu_think(delta);
}
main.c
for(;;)
{
sTime = timenow();
think_frame(delta);
if(should_render_for_maxfps(render.maxfps) == GL_TRUE)
{
render_frame();
}
delta = timenow() - sTime;
}
Basically my question is, can I merge 'thinking' & 'rendering' together? And should I be limiting the FPS of my think frames? (ie using 100% of the CPU because I can seems like a waste)? Since 'think' and 'render' are in different functions I also have to check the state of the menu each frame twice, seems like a waste -- could I do:
render.c
void render_frame(float delta)
{
menu_frame(delta); /* does menu cals and renders? */
}
And then limit render_frame to maxFps?
Thanks in advance :)
I'd hate for my game to use 100% CPU if it didn't have to.