If there’s an API that guarantees that time will not go
backwards, it’s implementation(s) should also make sure you can
actually trust the API spec.
The SDL 1.2.5 man files don’t say anything about this, so I’m
wondering whether you should really assume that SDL_GetTicks
won’t move backwards… I think not.
From the web site for SDL_GetTicks
“Get the number of milliseconds since the SDL library
initialization.”
From that definition I fail to see how it could go backwards !
Well, yeah. However, ‘man gettimeofday’ says:
“The tv_sec member of the struct is the number of seconds since the
Epoch (see time(2)), and tv_usec is the amount of microseconds
past the current tv_sec value.”
If this way of describing it implies that time cannot go backwards,
then there must be a bug in the way NTP adjusts time.
Both Linux and Windows have counters which are based on how long
the system has been up (maybe in ms), and these should be
independant of anything that NTP may be doing to the system clock.
That’s a good point. IIRC, the Win32 API docs explicitly say that the
multimedia timers are not necessarilly in sync with system time. So,
Win32 shouldn’t have a problem with mmtimers and NTP.
I haven’t looked at the SDL code to see what they are using, but
the function and any of your code should be using these functions
and not anything to do with the “clock” time.
Yeah. SDL_GetTicks for Linux:On Tuesday 24 December 2002 18.21, andy preston wrote:
On Tue, 2002-12-24 at 08:49, David Olofson wrote:
Uint32 SDL_GetTicks (void)
{
#ifdef USE_RDTSC
unsigned long long now;
if ( ! cpu_mhz1000 ) {
return 0; /* Shouldn’t happen. BUG!! */
}
rdtsc(now);
return (Uint32)((now-start)/cpu_mhz1000);
#else
struct timeval now;
Uint32 ticks;
gettimeofday(&now, NULL);
ticks=(now.tv_sec-start.tv_sec)*1000 +
(now.tv_usec-start.tv_usec)/1000;
return(ticks);
#endif /* USE_RDTSC */
}
So, unless RDTSC is used, SDL_GetTicks() can potentially do the wrong
thing when NTP is used. (Or if the user changes the system clock
while your program is running.)
Maybe it should keep the last ‘ticks’ returned, and if the result is
less than that, adjust start.* and return 0?
Would have been nice if SDL could be informed of system clock
adjustments, but that might be overkill, if at all possible.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`---------------------------> http://olofson.net/audiality -’
— http://olofson.net — http://www.reologica.se —