[SDL] cdaudio from mounted cd
neocdsdl at yahoo.com
Tue Mar 29 14:02:05 PST 2005
On Friday 11 March 2005 13.14, Olof Bjarnason wrote:
> Say you fix your logic rate to 100 Hz, that is 10 ms per frame. Try
> to find as accurate as possible a time measurement, SDL_GetTicks()
> has 10 ms granularity
SDL_GetTicks() has 1 ms granularity everywhere, except possibly on
some "broken" platform. (IIRC, there was some issue with WinNT, until
SDL had a workaround for it.) Most platforms have some call that
delivers sub-ms accurate timestamps.
It's the scheduling (that is, SDL timers) that has 10 granularity on
> so it is not ideal but might prove good enough
> at least it won't "drift" as time goes by. The trick is to keep a
> variable for your current "logic time" or "game time", which tries
> to "follow" the computer time / real time as good as possible.
Yep, good point. You need to do that whether or not timestamps are ms
accurate, because ms granularity is just not suficient unless you get
very low frame rates.
> The processing of the events might be done in a separate thread to
> enable granularity higher than the FPS rate! It might be a bit
> tricky though maybe someone can fill up on this.
Should work, though you have to timestamp events as they come in, and
enqueue them for actual processing in the game logic code, or you
might as well just process all events first thing every rendering
Of course, this adds to latency - though in most cases, constant
latency is better than random jitter, even when significantly higher.
That said, I don't think it matters much unless you get *very* low
frame rates - and then you can't play the game anyway... Timestamped
input events might help to make mouse tracking smoother, though - but
only if the timestamps are more accurate than the rendering frame
rate. (So as long as SDL's 100 Hz event loop is inbetween you and the
input API, it's not going to help much.)
> Another issue is the limited size of the gameTime_ms. If it is
> unsigned 32bit, we get approx. 4*10^9 ms = 4*10^6 s = 4*10 / (60*60)
> h ~= 4.400 hrs ~= 180 days. How long can a pong game get? :)
> Anyway you must make sure getCurrentTime_ms() starts counting at 0
> when the program boots..
...or base all game logic on delta times, with wrap safe delta time
calculations. (Pretty trivial with integers.)
Note that with fixed rate logic, you can use simple integer counters
(counting logic frames) to keep track of object life times and the
like. Doesn't get any simpler than that. :-)
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL