SDL_AddTimer

Hello!

I’m writing a simple emulator and I have to limit the speed of execution.
According to the docs there are two ways:

  • Use a timer callback function. This may have the bad effect that it runs in a
    seperate thread or uses alarm signals, but it’s easier to implement.
  • Or you can get the number of milliseconds passed, and move the object if, for
    example, 30 ms passed.

There is an example how to do it the second way. I’d rather use a timer callback
function. The declaration of my function looks like this:

bool Execute();

I get convertion and type mismatch errors. Do I have to do it the other way?

Stefan wrote:

Hello!

I’m writing a simple emulator and I have to limit the speed of execution.
According to the docs there are two ways:

  • Use a timer callback function. This may have the bad effect that it runs in a
    seperate thread or uses alarm signals, but it’s easier to implement.
  • Or you can get the number of milliseconds passed, and move the object if, for
    example, 30 ms passed.

There is an example how to do it the second way. I’d rather use a timer callback
function. The declaration of my function looks like this:

bool Execute();

I get convertion and type mismatch errors. Do I have to do it the other way?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Try naming your function something else. I assume that declaration comes
with an actual usage somewhere down the line? You also might try using
SDL_gfx for framerate limiting, or borrowing the code that limits framerate
from them.

-TomT64

Hi Guys,

I’m using the SDL_PushEvent() technique at
https://wiki.libsdl.org/SDL_AddTimer so that my timer is processed on the
main thread.

The only problem is that it seems I lose the convenience of changing (or
deleting) the timer using the return value of the callback.

How could I write a callback to use SDL_PushEvent() and then get the result
of my event loop function to reset the timer interval?

Of course, I could RemoveTimer and AddTimer, but it would be nice to have a
more compact solution.

cheers,
jack