[SDL] SDL alternative to glutIdleFunc()?
William Brodie-Tyrrell
william at brodie-tyrrell.org
Sat Oct 21 18:26:33 PDT 2006
Stoned koala bears drooled eucalyptus spit in awe as Eric Lilja said:
> Ok, I had a similar loop that called SDL_WaitEvent() before. When I try
> your variant with two loops and the inner one calls SDL_PollEvent() my
> simple program consumes 100 % CPU...
David beat me to it but as he said, it's because the program is
generating frames as fast as the video card can page flip. In my
simple demos, it runs at 500-700fps - a meaningless number but it
shows that the cycles aren't going nowhere, they're going to lots of
frames that you don't see more than a few scanlines of each.
If you enable sync to vertical retrace (video card driver option), the
program will pause inside SDL_GL_SwapBuffers() and the CPU utilisation
should drop dramatically as long as the retrace wait isn't itself a
polling loop; since it's inside the graphics drivers it should be a
proper process yield, i.e. taken off the runnable queue until the
retrace occurs.
The inside loop that polls for events will go around only once for each
event that has been received; if no events are coming in then the inner
loop does nothing.
If you change it to wait for any SDL events before doing a redraw,
that'd be kind of bad (for a game) since nothing would happen until
user events appeared. If you're trying to write a windowing system or
something, then I guess that'd be good.
--
William Brodie-Tyrrell
Carpe Diem - fish of the day.
<william at brodie-tyrrell.org>
http://www.brodie-tyrrell.org/
More information about the SDL
mailing list