So far, I've made a few small simple games in the past using visual c++ and Windows GDI. More recently in the past year, I've been wanting to develop more complex games and have learned through books and online tutorials about AI techniques and I have a decent understanding of how to use DirectX.
My problem is I don't know how to structure my main game loop. Essentially, I want to create my own simple game engine. I know there are plenty of game engines out there, but I want to do this as a learning experience more than anything.
Here are the three main things I know that I need in my loop.[list=1]
[*][u]Graphics update[/u] -- runs more or less as fast as it can
[*][u]Physics update[/u] -- from what I understand, this should run every predetermined set period of time to limit the number of odd physics related bugs that I see.
[*][u]AI update[/u] -- this takes care of computer "strategy", pathfinding, etc, and should only be run much less often when compared with the graphics or physics updates.
Based on what I've ready, the sudo code way of how I imagine this going looks like this:
#define PHYSICS_DELAY 30
#define AI_DELAY 500
if (time_since_last_physics_update > PHYSICS_DELAY)
if (time_since_last_ai_update > AI_DELAY)
However, this means that the time required to make it through a single loop is highly variable. It might just run the graphics update (hopefully not because from what I read, the physics should be updating about twice as fast as the graphics) or it might run all three updates.
I'm sure I'm missing something because this doesn't seem right to me at all.
Could someone please explain to me how a game loop should work? Everything I've seen up to this point that tries to explain it leaves out one part or another.