Seed history properly and dt clamp.

This commit is contained in:
Richard Davey 2017-05-03 02:21:32 +01:00
parent e5b82eb9b9
commit 9eb1676482
2 changed files with 10 additions and 7 deletions

View file

@ -54,7 +54,7 @@ VariableTimeStep.prototype = {
for (var i = 0; i < this.deltaSmoothingMax; i++)
{
history[i] = 0;
history[i] = 0.0166;
}
this.delta = 0;
@ -76,16 +76,19 @@ VariableTimeStep.prototype = {
// delta time
var dt = (time - this.lastTime) / 1000;
if (dt < 0 || dt > 1)
// min / max range
if (dt < 0.0001 || dt > 0.5)
{
// Probably super bad start time or browser tab inactivity / context loss
// so use the last 'sane' dt value
dt = history[idx];
}
console.log('dt sync', dt, 'ms over', history[idx]);
// clamp delta to 0.0001 to 0.5 range
dt = Math.max(Math.min(dt, 0.5), 0.0001);
dt = history[idx];
// clamp delta to 0.0001 to 0.5 range
dt = Math.max(Math.min(dt, 0.5), 0.0001);
}
// Smooth out the delta over the previous X frames

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '1fea37a0-2f97-11e7-93dd-fd6f78427b2e'
build: 'f7392da0-2f9d-11e7-ba4c-5959ed8510b1'
};
module.exports = CHECKSUM;