• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EnginePhysics Engine Support for Variable Time StepsPhysics Engine Support for Variable Time Steps
Previous
 
Next
New Post
10/13/2011 4:22 AM
 
Nieldy
No Ranking

Joined: 6/24/2011
Posts: 32
Physics Engine Support for Variable Time Steps 

Hi,

Just wanted to get some advice about using the Game.IsFixedTimeStep setting when using the DigitalRune Physics library. I'll explain my predicament first...

The problem I have is that initially I was running my game using IsFixedTimeStep = true, but then I was finding that my game would all of a sudden go jerky even though my internal frame rate counter was saying it was running at 60fps. Also, one of my CPU cores would go to 100%. This could go on for a minute or two (sometimes less, sometimes more), then it would go smooth again and the CPU core would go down to something like 10% (even though nothing different was happening in the game). Anyway, I couldn't work out what the problem was because the fps was still reporting as 60fps and it didn't seem to be a GC issue (I'm not allocating much memory while in the play state, and the behavior was a bit too weird), until I found this thread <http://forums.create.msdn.com/forums/...>, where lots of people are having the same issue. It appears to be an XNA issue that occurs for some people with Windows 7, when IsFixedTimeStep is set true (something to do with the fixed timing built into the Game class... but I'm not too sure of the exact reason). Anyway, some people have come up with hacks to change the way the fixed timing works, but I'd rather avoid this if possible. By the way, this issue also happens when running your Vehicle physics demo, so I'm pretty sure it's not just due to an issue with my game.

So, now I'm running my game with IsFixedTimeStep = false. For the most part it's much smoother and I don't get the CPU load issue anymore, but I do notice that my car occasionally jumps a bit, which looks to be an issue with the Simulation (the fps doesn't change from 60 when this happens by the way). I've noticed that in the Physics samples from you guys that I've looked at, the IsFixedTimeStep property is set true, so I'm not sure if the Simulation class doesn't handle it correctly when this is set false.

Could you give me some advice as to whether the Simulation class is designed to work ok when IsFixedTimeStep is set false? If so, then maybe I just need to tweak my Simulation settings a little.


Thanks for your help as always,


Stephen

 
New Post
10/13/2011 9:52 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Physics Engine Support for Variable Time Steps 

Hi, I have tested it and got the same XNA fixed time step problems on a Win 7 x64 PC: Sometimes the framerate is 60 fps and low CPU utilization but most of the time I get 49 fps and one CPU core is at 100%. :-(
If IsFixedTimeStep = false, I get 700 fps.

In our vehicle system I do not see any problems when I run it using a variable time step.

Here is some background information about the Simulation and time stepping:

In general, it is recommended to use a fixed time step for physics simulation because the simulation uses numerical integration, where the numerical error depends on the time step size.  You will want to tune and optimize your physics to be stable for your target frame rate. If you simulate using a variable time step, then the simulation results are not repeatable. A variable time step can lead to critical gameplay failures. For example: varying character controller jump heights or varying ballistic curves of cannon balls that should hit a target.

A fixed time step has proven so essential that we have made it the default in our Simulation. The Simulation uses two values to configure the timing: Simulation.Settings.Timing.FixedTimeStep and Simulation.Settings.Timing.MaxNumberOfSteps. And internally in Simulation.Update() it does something like this:

_accumulatedTime += MathHelper.Clamp(deltaTime, 0, Simulation.Settings.Timing.FixedTimeStep * Simulation.Settings.Timing.MaxNumberOfSteps);
while (_accumulatedTime >= Simulation.Settings.Timing.FixedTimeStep)
{
  // Advance simulation by FixedTimeStep
  ...
 
  _accumulatedTime -= Simulation.Settings.Timing.FixedTimeStep;
}

 

That means, you can use a variable XNA time step and call Simulation.Update(variableTime). The simulation will divide this time into fixed time steps internally.

If, for some reason, you want to force the simulation to use a variable time step, then you have to update FixedTimeStep before each Update() call:

Simulation.Settings.Timing.FixedTimeStep = variableTime;
Simulation.Update(variableTime);

 

Since XNA Game.IsFixedTimeStep is buggy, you might want to try to set IsFixedTimeStep = false and do the fixed time stepping in Game.Update() manually:

protected override void Update(GameTime gameTime)
{
  _accumulatedTime += MathHelper.Clamp((float)gameTime.ElapsedGameTime.TotalSeconds, 0, Simulation.Settings.Timing.FixedTimeStep * Simulation.Settings.Timing.MaxNumberOfSteps);
  while (_accumulatedTime >= Simulation.Settings.Timing.FixedTimeStep)
  {
    // Update game logic and simulation with FixedTimeStep.
    ...
    _accumulatedTime -= Simulation.Settings.Timing.FixedTimeStep;
  }
  base.Update(gameTime);
}

 

Be aware that XNA GameComponents are updated in base.Update(), therefore they are still updated with the variable time step. This could cause problems and the interaction of the GameComponents with other fixed time step game logic must be designed carefully.

 
New Post
10/14/2011 3:55 AM
 
Nieldy
No Ranking

Joined: 6/24/2011
Posts: 32
Re: Physics Engine Support for Variable Time Steps 

Thanks Helmut,


Good to know that the Simulation internally handles a variable game time correctly. Overall, using Game.IsFixedTimeStep = false seems to be a good option (since that's what most games outside of XNA seem to do anyway). I'll investigate that jumping issue further. It doesn't seem to be that frequent, and it may just be my Simulation settings aren't set up properly.


Cheers,

 
New Post
10/14/2011 7:59 AM
 
Sweenie
No Ranking

Joined: 9/16/2011
Posts: 9
Re: Physics Engine Support for Variable Time Steps 

You might get stuttering/jumping when the physics aren't updated at the same rate as the rendering.
You can solve this by doing som interpolation though.
Glenn Fiedler explains this pretty well in this article.

http://gafferongames.com/game-physics/fix-your-timestep/

 
New Post
10/14/2011 10:03 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Physics Engine Support for Variable Time Steps 
I am curious. Have you tried the interpolation (as described by Glenn Fiedler) and seen a noticable improvement? I have tested it before but it didn't make a difference in my tests - but maybe I have tested the wrong scenarios...
 
New Post
10/14/2011 1:25 PM
 
Sweenie
No Ranking

Joined: 9/16/2011
Posts: 9
Re: Physics Engine Support for Variable Time Steps 

Yes, I'm using this interpolation method in my simulation and it makes a big difference.

Though the stuttering is more visible when I run the simulation on a slower computer which have very irregular rendering framerates.
On my gaming computer the framerate is high and stable so the stuttering isn't as noticeable.

I will see if I can make a demo that demonstrates the difference.(I'm not using Digital Rune in my simulation though, it's c++ using the Newton physics engine, but that shouldn't matter)  

 
New Post
10/14/2011 6:09 PM
 
Sweenie
No Ranking

Joined: 9/16/2011
Posts: 9
Re: Physics Engine Support for Variable Time Steps 

Ok, here it is...

When you run it(and if it starts) you will see two rotating objects.
These are just two rigid bodies with a fixed angular velocity of 1.
The blue object is using interpolation and the green one doesn't.
On both of my computers(a slow one and a faster gaming computer) I get a slight stutter mostly visible at the far edges of the green object.
The blue object doesn't stutter at all.

I hope you can see the effect.

Interpolation Demo

 
New Post
10/14/2011 6:50 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Physics Engine Support for Variable Time Steps 

Thanks Sweenie, that was very helpful.

We will probably add a sample for variable time step and the interpolation to DigitalRune Physics.

Does Newton have any built-in support for the interpolation?

 
New Post
10/14/2011 10:42 PM
 
Sweenie
No Ranking

Joined: 9/16/2011
Posts: 9
Re: Physics Engine Support for Variable Time Steps  Modified By Sweenie  on 10/14/2011 10:49:28 PM

Not that I'm aware of.

Think that Bullet Physics engine have that though. They have something called MotionState which takes care of that.
Suppose it's kinda like the Pose in Digital Rune.

Really look forward to your graphics library though, I really want to move my little game project over to .NET. :)
For me c++ is like using the stairs, I prefer taking the elevator instead(.NET) ;)


 
New Post
10/15/2011 4:23 AM
 
Nieldy
No Ranking

Joined: 6/24/2011
Posts: 32
Re: Physics Engine Support for Variable Time Steps 
HelmutG wrote:

Thanks Sweenie, that was very helpful.

We will probably add a sample for variable time step and the interpolation to DigitalRune Physics.

Does Newton have any built-in support for the interpolation?

 A DigitalRune sample for this would be fantastic. Thank Helmut, and thanks Sweenie for your very informative input and demonstration.

 
 Page 1 of 2
12Next 
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EnginePhysics Engine Support for Variable Time StepsPhysics Engine Support for Variable Time Steps


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement