[SDL] SDL_PollEvent()

David Olofson david at olofson.net
Thu Nov 9 10:37:25 PST 2006


On Thursday 09 November 2006 15:00, pixel fairy wrote:
> the whole point was making the app light on the cpu. i ended up
> using SDL_Delay like this
> 
> while(1) {
>      check_events()
>      update_state()
>      draw(backbuffer)
>      delay()
>      SDL_GL_SwapBuffer()
> }
> 
> i think that swapping buffers at frame update time would be
> more consistant since the time to draw is more variable, but
> it probably doesnt make much differnce. havent tested this yet.

Then we're talking about a more or less completely different problem. 
SDL_GL_SwapBuffer() is *supposed* to block as needed to keep the loop 
in sync with the display refresh, but unfortunately, you cannot rely 
on this to work everywhere.

If you get 100% CPU load with the above loop, it's because something 
prevents SDL_GL_SwapBuffer() from synchronizing with the display 
refresh. It could be a broken driver, or an incorrectly configured 
driver. Some old drivers don't implement retrace sync at all, whereas 
hhe latter is commonly done deliberately by players of certain games, 
due to game logic bugs that favor players with insane frame rates. 
Drivers can usually be configured to override anything applications 
say, so there's no reliable way that an application can enforce 
retrace sync, even if the driver supports it.

The really bad news is many drivers install with retrace sync disabled 
by default, and the vast majority of users have no clue as to what 
this is all about. :-(

What you're doing above is the last resort, and it's about all you can 
do, short of just having users of broken systems pay with 100% CPU 
load.

The problem with a delay in the render loop is that it often results 
in less smooth animation on properly configured systems (it just 
interferes with the retrace sync), so you should probably make it 
optional, or possibly switch it on automatically when needed.


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

.-------  http://olofson.net - Games, SDL examples  -------.
|        http://zeespace.net - 2.5D rendering engine       |
|       http://audiality.org - Music/audio engine          |
|     http://eel.olofson.net - Real time scripting         |
'--  http://www.reologica.se - Rheology instrumentation  --'




More information about the SDL mailing list