Syncing Update and Draw at a Target Framerate

Started by
0 comments, last by skytiger 13 years, 4 months ago
Hi,

I'd like to be able to have the calls between Update and Draw be synchronized (i.e., have exactly one Update call for every Draw call) AND be called at exactly 60Hz.

In the Initialize function, I tried the following, which didn't help:
this.IsFixedTimeStep = true;this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, (int)Math.Round(1000.0f/60.0f));base.Initialize();
When I set:
this.IsFixedTimeStep = false
Then, the Update and Draw functions sync, but the framerate is erratic, and certainly not 60 fps. If I then go:
_graphics_device_manager.SynchronizeWithVerticalRetrace = false;
Then, the rate is limited to the screen's refresh rate, which is around 60. This doesn't feel like a solution--limiting the game solely by the monitor's refresh rate. For one thing, it could cause problems; for example, some of the new 3D displays run at 120Hz, which would make the Update and Draw class go twice as fast!

Help please!

I'm using XNA 4.0.

Thanks,
-G

[Edited by - Geometrian on December 6, 2010 12:15:50 AM]

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
read up on these:

GraphicsDeviceManager.PreparingDeviceSettings
PreparingDeviceSettingsEventArgs.GraphicsDeviceInformation.PresentationParameters.FullScreenRefreshRateInHz
PreparingDeviceSettingsEventArgs.GraphicsDeviceInformation.Adapter.CurrentDisplayMode.RefreshRate
PreparingDeviceSettingsEventArgs.PresentationParameters.PresentationInterval

if you leave fixedtimestep off xna will attempt 1 Update() to 1 Draw()

120hz is only possible if your frametime is < 8.3 milliseconds
so most 60 fps games will maintain 60 fps even with 120hz refresh

I skip the XNA Update() completely and use an update thread
with a couple of wait handles - this gives 1:1 Update:Draw
plus both methods can take 16.5 milliseconds and I still get 60 fps ...

this approach can be complicated as you need to double buffer any data required in the draw calls ...

This topic is closed to new replies.

Advertisement