[SDL] SDL_PollEvent()

Ryan C. Gordon icculus at icculus.org
Wed Nov 8 11:54:30 PST 2006


> would making it a poll/select call be bad? or just too much work for the 
> gain? i like to make light apps, that only hit the cpu when they need to 
> by waiting on input until its time to swap buffers.

The problem is twofold:
1) SDL needs to poll a few things that are unrelated, like timers, 
joysticks, window events, etc, so you probably couldn't push them all 
into one select() without really messing up the internals of SDL.

2) Most systems SDL targets don't have a select() that can target all 
the things that we poll for...some don't even _have_ a select() call. 
Even on Unix, we can't promise that everything we'd wait on would be a 
real file handle on any given run of the program.

3) ("Twofold"?) ... if you want to select() with a timeout, then draw 
some stuff and swap buffers, you could just poll, swap buffers, and 
sleep for some amount of time...and you still wouldn't notice the event 
loop in a CPU profiling.

That being said, if you don't have to redraw, SDL_WaitEvent() could 
possibly do what you want...there's a patch in Bugzilla to make it do 
the right thing in most cases; largely this was for embedded devices 
that want to put the CPU to sleep until it's definitely needed. For a 
desktop system, I really wouldn't bother.

     http://bugzilla.libsdl.org/show_bug.cgi?id=323

SDL_WaitEvent() does not specify a timeout (hmm...maybe something like 
it should for SDL 1.3, though...).

--ryan.






More information about the SDL mailing list