[SDL] Re: SDLu, was time stamped events, was [SDL] Detecting Double Clicks

Rainer Deyke root at rainerdeyke.com
Thu Jan 17 13:36:01 PST 2002


"Fro Joe" <tennies at uwplatt.edu> wrote in message
news:mailman.1011300185.20047.sdl at libsdl.org...
> Actually, after further thought, SDL_GetTicksSince() is rather
trivial and
> people are going to argue that because of that, it shouldn't be in
the SDL.
>
> Uint32 SDL_GetTicksSince(Uint32 timestamp)
> {
> /* ha to all you C Programmers your '{' should be on a new line...
> READABILITY FIRST */
>    Uint32 currentTime = SDL_GetTicks();
>    if (currentTime > timestamp)
>       return currentTime - timestamp;
>    return (0xFFFFFFFF - timestamp) + currentTime;
> }

It's more trivial than that:

  Uint32 SDL_GetTicksSince(Uint32 timestamp)
  {
    return SDL_GetTicks() - timestamp;
  }

The above works reliably across the wraparound at 0xffffffff.  Really.

The relatively complicated and incorrect (off by 1 across wraparound
boundary) code you posted above is the strongest argument for
'SDL_GetTicksSince' in SDL yet.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the SDL mailing list