Fps question and more

It seems like i am limited in regulating my fps by the timer resolution in SDL.
I can only manage to regulate 1sec/10ms allowed per frame = 100 fps or 1sec/20ms = 50fps.
How would I set a cap at something like 60 or 70 fps if I can only track a frame in 10ms
increments.

Also, on rare occasions a rectangle is not completely drawn or is drawn in the wrong spot
or looks garbled(random pixels). Is there a way to detect if this happened and then refresh the area or to
prevent it? I am using a dirty rectangle system with UpdateRects and just ported my game to SDL. There were no
draw errors in my other implementation. With Allegro to vsync I could just call a function vsync(),
how would I do this with SDL? mac os x port btw
thanks

It seems like i am limited in regulating my fps by the timer
resolution in SDL. I can only manage to regulate 1sec/10ms allowed
per frame = 100 fps or 1sec/20ms = 50fps. How would I set a cap at
something like 60 or 70 fps if I can only track a frame in 10ms
increments.

Unless you’re on some broken version of Windows (some release of NT or
Win2k, I think), you should be able to get ms accuracy with
SDL_GetTicks(). However, it is true that you generally cannot
schedule with better accuracy than 10 ms. This applies to pretty much
all platforms. QNX, later Linux 2.5 kernels and some other OSes can
do betters, but that’s pretty much irrelevant unless you’re going to
build your own gaming machines or something.

So, the simple answer is “You don’t.” A more useful answer would be
that you can throttle the frame rate to an average of those 60 or
70 fps you want. Calculate the desired delay, wait and then check
SDL_GetTicks() to find out where you are after that. Feed the error
forward into the next delay time calculation.

Also, on rare occasions a rectangle is not completely drawn or is
drawn in the wrong spot or looks garbled(random pixels). Is there
a way to detect if this happened and then refresh the area or to
prevent it? I am using a dirty rectangle system with UpdateRects
and just ported my game to SDL. There were no draw errors in my
other implementation.

Why does it happen in the first place? This definitely sounds like a
bug somewhere. I’ve never seen it with any SDL code, so I suspect it
has something to do with your drivers and/or the SDL backend you’re
using.

With Allegro to vsync I could just call a
function vsync(), how would I do this with SDL?

Direct retrace sync is rather pointless unless you have an RTOS (or no
real OS at all, like in the old days). This is part because of poor
scheduling timing, part because h/w accelerated displays render
asynchronously. (Try retrace syncing on the application side while
rendering with OpenGL and you’ll see what I mean. :slight_smile:

The SDL logic is based on the idea that it’s the video driver or
hardware that does the sync.

You just send a page off with SDL_Flip() and let the backend or driver
do it’s thing. If retrace sync is at all possible (it isn’t on some
targets), the application will sync indirectly, either by blocking in
SDL_Flip(), or by blocking the next time you try to lock the display
surface.

Note that this is only possible with double buffered h/w surface
displays! Single buffered displays (or displays with “fake” s/w back
buffers) don’t pageflip (obviously), and therefore cannot retrace
sync by definition. (Of course, it would be theoretically possible to
do so, but you’ll need an RTOS, or you’ll only make things worse.
Constant tearing in a fixed place isn’t nice at all.)

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

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Friday 16 May 2003 14.28, jrschnayer at ucdavis.edu wrote:

David Olofson wrote:

Note that this is only possible with double buffered h/w surface
displays! Single buffered displays (or displays with “fake” s/w back
buffers) don’t pageflip (obviously), and therefore cannot retrace
sync by definition. (Of course, it would be theoretically possible to

I’ve found that SDL apps under W32 using hardware overlay DOES sync to
the vertical refresh.

I’ve written a small player that use SDL for display and avcodec for
decoding, and I’ve found that while the linux version was able to decode
at 250+ fps with low resolution (3xx x 2xx) divx movies the windows
version was struck at 84.xxxfps, I tried then to decode 7xx x 5xx movies
and I was still at 84.xxx fps. All this benchmarks are in windowed mode,
of course with the sync code and audio disabled :slight_smile:

So, at least the w32 target, is able in some situation to do retrace
sync drawing also on windowed mode :slight_smile:

Bye,
Gabry

David Olofson wrote:

Note that this is only possible with double buffered h/w surface
displays! Single buffered displays (or displays with “fake” s/w
back buffers) don’t pageflip (obviously), and therefore cannot
retrace sync by definition. (Of course, it would be theoretically
possible to

I’ve found that SDL apps under W32 using hardware overlay DOES sync
to the vertical refresh.

A real hardware overlay (ie one that’s not blitted through the 3D
accelerator) is effectively a display of it’s own that’s applied on
top of the normal graphics right before or in the RAMDAC. (Maybe even
after on some cards; dunno for sure.) So, the overlay can be page
flipping or whatever, and it has nothing to do with whatever the
normal video subsystem is doing.

[…]

So, at least the w32 target, is able in some situation to do
retrace sync drawing also on windowed mode :slight_smile:

Except that it’s not really windowed mode, it has nothing to do with
Win32, and it’s totally hardware dependent. :slight_smile:

BTW, I’m still wondering if Mac OS X is the first “consumer OS” to
come with a double buffered desktop environment, or if that’s just
another rumor. (That should also allow retrace sync in windowed mode,
and it doesn’t require any weird hardware.)

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

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 22 May 2003 17.47, Gabriele Greco wrote: