Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

Syncing Update and Draw at a Target Framerate

This topic is 2781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 ...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!