Timer performance

Does not using many timers result in a worse performance than using “if
(SDL_GetTicks() - x > y)” ?

Since I’m at the beginnning of my game programming, it’s very important to
know what to use.

[Either:]

if (SDL_GetTicks() - time >= 100)
MoveSprite(x, y);

[Or:]

Uint32 func(Uint32 interval, void *param)
{
MoveSprite(x, y);
return 1;
}

Uint32 (func_ptr)(Uint32, void) = func;

SDL_AddTimer(100, func_ptr, (void*)1);

? Please help!

Does not using many timers result in a worse >performance than using “if
(SDL_GetTicks() - x > y)” ?>

Are “x” and “y” always the same value? Try making your game
hardware-independent and have “x” and “y” be calculated based on
elapsed time, so that faster computers will show smoother animation by
using smaller values.–

Olivier A. Dagenais - Software Architect and Developer

“NIL” wrote in message
news:9iul2d$lpk$1 at ftp.lokigames.com

Since I’m at the beginnning of my game programming, it’s very
important to
know what to use.

[Either:]

if (SDL_GetTicks() - time >= 100)
MoveSprite(x, y);

[Or:]

Uint32 func(Uint32 interval, void *param)
{
MoveSprite(x, y);
return 1;
}

Uint32 (func_ptr)(Uint32, void) = func;

SDL_AddTimer(100, func_ptr, (void*)1);

? Please help!

Does not using many timers result in a worse >performance than
using “if
(SDL_GetTicks() - x > y)” ?

Since I’m at the beginnning of my game programming, it’s very important to
know what to use.

[Either:]
if (SDL_GetTicks() - time >= 100)
[Or:]
SDL_AddTimer(100, func_ptr, (void*)1);

Timers are probably more overhead, but callbacks are obnoxious anyhow. You
code is almost always more readable, maintainable, and less buggy when
you don’t have to jump all over the place in signal handlers, callbacks,
and threads.

–ryan.

on 7/16/01 5:01 AM, NIL at sebh at gmx.de wrote:

Since I’m at the beginnning of my game programming, it’s very important to
know what to use.

[Either:]

if (SDL_GetTicks() - time >= 100)
MoveSprite(x, y);

[Or:]

Uint32 func(Uint32 interval, void *param)
{
MoveSprite(x, y);
return 1;
}

Uint32 (func_ptr)(Uint32, void) = func;

SDL_AddTimer(100, func_ptr, (void*)1);

? Please help!

Does not using many timers result in a worse >performance than using “if
(SDL_GetTicks() - x > y)” ?

In the SDL documentation on timers it says the callback function may not
always be executed in the same thread as your main loop. So you might run
into some problems if the sprite data is mucked with by more than one code
segment. Also the problem with using a timer is you’re setting an unexact
maximum on the “smoothness” of motion, etc. The timer is unexact because
process scheduling always adds a variable amount of overhead. The motion has
a maximum “smoothness” since the sprite will be at best moved once every
100ms. What if you’re running on a very fast machine that can do better? I
could describe a better way to do this bu just go to the link below:

http://www.gamedev.net/reference/articles/ftimedj.zip
(its what olivier mentioned, updating motion based on elapsed time)________________________
Ajay Ayyagari
@Ajay_Ayyagari