From: Anson Parker (ans@x-64.com)
Date: Mon 20 Mar 2000 - 12:34:57 IST
Hey Jay,
I've recently just started programming C (and using svgalib) so feel free to take my
advice with a grain of salt...
I'm writing a gravity/shoot-em-up type game and I struggled with the issue of keeping
the gaming speed nice across platforms (dual celeron 500 at home, and 233 laptop at
work). I found that I didn't want to limit speed in terms of framerate, but rather in terms
of keeping physics and firing rates etc the same.
The main bummer is that there's no truly cross-platform way of keeping track of micro
seconds or any sub-second timing (which is not to say there aren't some fairly OK ways
of doing it). But once I sorted this, every time my main loop runs it computes the time
difference since it was last run. Then it's simply a matter of calculating things in a time-based
manner, rather than per-loop.
This is particularly cool for things like gravity. For 'true' gravity (at any framerate) all you need
to do (ignore air resistance etc) is:
downforce = downforce + (timedelta * GRAVITY); /* rather than... */
downforce = downforce + GRAVITY; /* fine if your loop takes 1 second to run! */
I apply this principle to the rate of bulletfire, thrust, turning etc... And it means the game
behaves the same at any framerate (even 1 frame every 2 seconds... although admittedly,
that'd suck!)
I can see this would be trickier for heavily sprite-based games where there's less flexibility in
terms of varying frame-rates. But it means your code will still work in 5 years, on a quad 10Ghz
setup.
regards,
Anson.
P.S. Anyone working on an svgalib driver for the GeForce?
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST