I'm trying to achieve the same effect in an XNA game, without writing my own Game class, since the Game class does an awful lot for me that I can't be bothered to do myself.
I've come up with a fairly naive implementation, that seems to work, but I want someone with more XNA experience to take a look and see if I'm doing something that's going to cause problems.
Yes, I know I've got an allocation in my loop, but Microsoft in their wisdom decided to make the fields on the GameTime class readonly, so I'm not sure how I can get around that.
long t = 0;
const long dt = TimeSpan.TicksPerSecond / 60;
long currentTime = 0;
long accumulator = 0;
protected override void Update(GameTime gameTime)
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
long newTime = gameTime.TotalGameTime.Ticks;
long deltaTime = newTime - currentTime;
currentTime = newTime;
accumulator += deltaTime;
while (accumulator >= dt)
base.Update(new GameTime(gameTime.TotalGameTime, TimeSpan.FromTicks(dt)));
t += dt;
accumulator -= dt;
// TODO: Add your update logic here
Edit: In case it's not clear, I'm using the following lines to turn off VSync and allow the render loop to run as fast as possible.
graphics.SynchronizeWithVerticalRetrace = false;
IsFixedTimeStep = false;