Hi,
I’ve noticed the following problem with SDL 1.2.1 and Windows 2000:
SDL_GetTicks() seem to have a granularity of 10 or 15 ms there!
The problem showed up in my private “delay” function (used in the
games “Rocks’n’Diamonds” and “Mirror Magic”): To wait for a certain
amount of x milliseconds as precise as possible, I split x into
x = x1 * 10 ms + x2 (with x2 < 10 ms), then I “SDL_Delay(x1 * 10)”,
then I wait for x2 milliseconds using a busy-loop with SDL_GetTicks().
This works quite fine under Linux (2.2.x and 2.4.x kernels tested) and
with Windows95 and Windows98, but not with Windows2000.
Where SDL_GetTicks() has a granularity of 1 ms normally, it has a
granularity of 10 ms on my first Windows2000 installation and a
granularity of 15 ms on my second Windows2000 installation (which
are installed identically from the same original Windows2000 CD).
I’ve tracked down the problem with the following piece of test code:
delay20ms()
{
unsigned long count1 = SDL_GetTicks(), count2, current_ms, test;
current_ms = SDL_GetTicks();
test = -1;
while (current_ms < count1 + 20) /* busy wait 20 milliseconds */
{
current_ms = SDL_GetTicks();
if (test != current_ms)
{
fprintf(stderr, "current_ms == %ld\n", current_ms);
test = current_ms;
}
}
count2 = SDL_GetTicks();
fprintf(stderr, "delay == %ld\n", count2 - count1);
}
The function prints out each change of the result of SDL_GetTicks()
and finally prints out the time interval effectively delayed.
(For testing, the function was called multiple times with the
printed output being redirected to a file.)
Under Linux and Windows95/98, I get what I expected:
[…]
rocksndiamonds: current_ms == 2320
rocksndiamonds: current_ms == 2321
rocksndiamonds: current_ms == 2322
rocksndiamonds: current_ms == 2323
rocksndiamonds: delay == 20
rocksndiamonds: current_ms == 2323
rocksndiamonds: current_ms == 2324
rocksndiamonds: current_ms == 2325
rocksndiamonds: current_ms == 2326
[…]
rocksndiamonds: current_ms == 2341
rocksndiamonds: current_ms == 2342
rocksndiamonds: current_ms == 2343
rocksndiamonds: delay == 20
rocksndiamonds: current_ms == 2343
rocksndiamonds: current_ms == 2344
rocksndiamonds: current_ms == 2345
[…]
Under my first Windows2000 installation (PII/700MHz), I get:
[…]
rocksndiamonds.exe: current_ms == 3214
rocksndiamonds.exe: current_ms == 3224
rocksndiamonds.exe: current_ms == 3234
rocksndiamonds.exe: delay == 20
rocksndiamonds.exe: current_ms == 3234
rocksndiamonds.exe: current_ms == 3244
rocksndiamonds.exe: current_ms == 3254
rocksndiamonds.exe: delay == 20
rocksndiamonds.exe: current_ms == 3254
rocksndiamonds.exe: current_ms == 3264
[…]
Very strange, although still the well known time slice of 10 ms.
Under my second Windows2000 installation (PIII/800MHz), I get:
[…]
rocksndiamonds.exe: current_ms == 2000
rocksndiamonds.exe: current_ms == 2015
rocksndiamonds.exe: current_ms == 2031
rocksndiamonds.exe: delay == 31
rocksndiamonds.exe: current_ms == 2031
rocksndiamonds.exe: current_ms == 2047
rocksndiamonds.exe: current_ms == 2062
rocksndiamonds.exe: delay == 31
rocksndiamonds.exe: current_ms == 2062
rocksndiamonds.exe: current_ms == 2078
[…]
Even more strange: A time slice of 15/16 ms!
The two tested Linux installations run on the same hardware
as the two tested Windows installations, without this problem.
Has anyone made similar observations with SDL?
What the heck is going on here?
What can I do to get usable results from SDL_GetTicks()?
Completely confused…
Best regards,
Holger–
holger.schemel at mediaways.net