Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Was thinking this morning, I 99.9% of the time, only see a main game loop, looking like this, just as much so where the delta is passed into update():

while running
getDeltaTime()
...
f(deltatime)
---

Now the question I was thinking to myself was what if between getDeltaTime() and f(deltaTime), the code in the middle took 1 second (large value to be easy). That means f(deltaTime) would have moved whatever object less distance than it was supposed to. This would of course be solved by grabbing the delta time directly before it is used.

Should this be a factor to be concerned with in any case?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

deltatime is the time between two consecutive calls to getDeltaTime(). If a particular frame takes very long, that will show in the next iteration, and the model will be updated accordingly.

That being said, you're right: you should call f(..) straight away. Other code after it. Delays introduced by that extra code, as well as the time it takes to update the model itself, will show in the delta of the next frame.

share|improve this answer
    
That makes sense, not something I have considered before, but I will keep immediate calling in mind. –  Rick Taemen May 30 '13 at 9:56
add comment

Yes, it is a factor. Some engines take this into account in some cases. For example AndEngine and its LimitedFPSEngine:

@Override
public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException {
    final long preferredFrameLengthNanoseconds = this.mPreferredFrameLengthNanoseconds;
    final long deltaFrameLengthNanoseconds = preferredFrameLengthNanoseconds - pNanosecondsElapsed;

    if (deltaFrameLengthNanoseconds <= 0) {
        super.onUpdate(pNanosecondsElapsed);
    } else {
        final int sleepTimeMilliseconds = (int) (deltaFrameLengthNanoseconds / TimeConstants.NANOSECONDS_PER_MILLISECOND);

        Thread.sleep(sleepTimeMilliseconds);
        super.onUpdate(pNanosecondsElapsed + deltaFrameLengthNanoseconds);
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.