SDL event loop

when we handle input like this:

SDL_Event event;
while (!done) {
while(SDL_PollEvent(&event)) {

}
}

do we keep polling for next event over and over? Isn’t this a busy waiting if
there are not frequent inputs?

Frank

when we handle input like this:

SDL_Event event;
while (!done) {
while(SDL_PollEvent(&event)) {

}
}

do we keep polling for next event over and over? Isn’t this a busy
waiting if
there are not frequent inputs?

Nope, not if you actually do anything in the outer while() loop.

Preferably, SDL_Flip() should result in a proper block on retrace sync
for each rendered frame. If you want to be nice to the system and not
burn all cycles on targets that can’t retrace sync, you can throttle
using SDL_GetTicks() and SDL_Delay().

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 30 January 2005 17.31, Franki wrote:

That depends on what you’re doing. If you are drawing an animation, and
do an SDL_Flip() in that outer while loop, then it doesn’t hurt to poll
in this manner.

If your app is exclusively event driven (redrawing only on input), then
you should use SDL_WaitEvent instead, which will block.

Richard Schreyer

Franki wrote:> when we handle input like this:

SDL_Event event;
while (!done) {
while(SDL_PollEvent(&event)) {

}
}

do we keep polling for next event over and over? Isn’t this a busy waiting if
there are not frequent inputs?