Variable-step update() in game loop is falling behind, how can I get around this?

Posted by ThatsGobbles on Game Development See other posts from Game Development or by ThatsGobbles
Published on 2011-06-28T21:37:44Z Indexed on 2012/06/20 3:24 UTC
Read the original article Hit count: 135

Filed under:
|
|

I'm working on a minimal game engine for my next game. I'm using the delta update method like shown:

void update(double delta) {
    // Update code that uses `delta` goes here
}

I have a deep hierarchy of updatable objects, with a root updatable that contains several updatables, each of which contains more updatables, etc. Normally I'd just iterate through each of the root's children and update each one, which would then do the same for its children, and so on. However, passing a fixed value of delta to the root means that by the time the leaf updatables are reached, it's been longer since delta seconds that have elapsed. This is causing noticable desyncing in my game, and time synchronization is very important in my case (I'm working on a rhythm game).

Any ideas on how I should tackle this? I've considered using StopWatches and a global readable timer, but any advice would be helpful. I'm also open to moving to fixed timesteps as opposed to variable.

© Game Development or respective owner

Related posts about timer

Related posts about synchronization