[SDL] Re: Question about ignoring mouse events

David Olofson david at olofson.net
Wed Nov 16 07:07:31 PST 2005

On Wednesday 16 November 2005 14.26, Román Gorojovsky wrote:
> Yes, thank you, that *almost* worked.
> But if you do "while (SDL_PollEvent(&event))" the loop won't even
> start, because usually at that point you don't have any event.

Uhm, well, that's the idea; if there are no events, this loop should 
not run. Conversely, the loop should spin as long as there are 
events, in order to empty the queue before exiting.

Note that the latter (emptying the event queue before you move on) is 
very important! If you don't do it that way, you'll get this horrible 
"rubber band" delay effect as soon as your rendering loop cannot spin 
at least once per input event. (Which it most likely cannot, unless 
the user has a low frame rate mouse and/or you're doing OpenGL 
rendering without retrace sync.)

So, what I'm saying is, this event decoding loop should be an inner 
loop, inside the main/rendering loop. That way, it simply does 
nothing if there are no events.

(Well, there are cases where you actually want the event loop to be 
the outer loop, or logically equivalent, but then you generally want 
to use SDL_WaitEvent instead, and either way, this rarely applies to 
games, where there is usually stuff going on even when there are no 
input events.)

//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.net --- http://www.reologica.se ---

More information about the SDL mailing list