piku wrote:What's
do, and what are the two parameters being passed in to it for?
This calls our game to do a logic update - move stuff around etc.
The TARGET_TIME is the 'elapsed time' for a logic frame. Its like this as we have a define so we can change the logic time for different games.
The 'first' parameter lets the logic know that this is the first logic frame to process. We need this as the input isnt changed inside the game tick - so for example mouse clicks are only processed when 'first' is true.
piku wrote:Is this correct:
Each frame of your game has to complete before the next one is due, and this whole process needs to be done quickly enough that we see the end result as fluid animation?
Yes.
piku wrote:
So, if your game logic and screen drawing takes too long, the game slows down and framerate and responsiveness drops. If your machine is quicker than the game needs, the game runs too quickly and becomes unplayable.
Usually its the drawing that stalls. For whatever the stall was, you have to do multiple logic updates. i.e. if we take 30ms to draw a frame, then each time round we do 2 logic updates for each draw.
piku wrote:
So what you have to do is accept that on a slow machine the game is going to run slowly, and concentrate on making it not run out of control on fast machines. And to do that a delay needs calculating each frame, based on a desired framerate - "I want this to run at at least 30fps".
This copes with slow & fast just as well. The aim of this code is to give the same play experience on a wide range of PCs.
When its slow, we just run the logic (logic is usually much faster than rendering). If you cant process the logic fast enough, then increase TARGET_TIME.
piku wrote:
In that case, how is it that Doom might run at a smooth 30fps on my 486, but on your Pentium it runs at an equally smooth 57fps? And yet your player isn't running around the screen any quicker than mine? Is that where you somehow disconnect screen drawing from game logic?
Yes.
The logic runs as though the game is running (for example) at 50fps all the time (thats what TARGET_TIME is for).The rendering is seperated so it draws at the speed the machine can cope with.
On fast machines the sleep at the end throttles the game back to 5fps, and on slower machines it runs the logic 50 times a second irrespective of the number of times we draw.
The code 'radio' posted is delta-timing. It works, but you have to make sure your logic is coded correctly. And it does not give fully 'deterministic' results - i.e. floating point error differences mean that a replay wont match the original.
The beauty of this system is that the ogic is fixed rate still so easier to code, you can build exact replays, and it runs on fast/slow machines perfectly.
Hope that all makes sense

<Blatant Plug>Feel free to try out any of the games on our site (link in sig.) Both the Java web games & the C++ downloads use this exact code to cope with PC speeds and we test on PCs ranging from 400 MHz PIIs up to Athlon64 3200s