Skip to content

Commit e5b82eb

Browse files
committed
Fixed delta spike handling.
1 parent 02a06bc commit e5b82eb

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

v3/src/boot/VariableTimeStep.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ var VariableTimeStep = function (game, framerate)
2020
this.time = 0;
2121
this.startTime = 0;
2222
this.lastTime = 0;
23-
this.runOff = 0;
2423

2524
this.delta = 0;
2625
this.deltaIndex = 0;
2726
this.deltaHistory = [];
28-
this.deltaSmoothingMax = 30;
27+
this.deltaSmoothingMax = 10;
2928
};
3029

3130
VariableTimeStep.prototype.constructor = VariableTimeStep;
@@ -70,26 +69,26 @@ VariableTimeStep.prototype = {
7069

7170
step: function (time)
7271
{
72+
var idx = this.deltaIndex;
73+
var history = this.deltaHistory;
74+
var max = this.deltaSmoothingMax;
75+
7376
// delta time
7477
var dt = (time - this.lastTime) / 1000;
7578

7679
if (dt < 0 || dt > 1)
7780
{
78-
// Loop skip, probably super bad start time
79-
this.runOff = time - this.lastTime;
80-
this.lastTime = time;
81-
return;
81+
// Probably super bad start time or browser tab inactivity / context loss
82+
// so use the last 'sane' dt value
83+
84+
dt = history[idx];
8285
}
8386

8487
// clamp delta to 0.0001 to 0.5 range
8588
dt = Math.max(Math.min(dt, 0.5), 0.0001);
8689

8790
// Smooth out the delta over the previous X frames
8891

89-
var idx = this.deltaIndex;
90-
var history = this.deltaHistory;
91-
var max = this.deltaSmoothingMax;
92-
9392
// add the delta to the smoothing array
9493
history[idx] = dt;
9594

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '77d3f640-2f92-11e7-94cb-df78655b45e3'
2+
build: '1fea37a0-2f97-11e7-93dd-fd6f78427b2e'
33
};
44
module.exports = CHECKSUM;

0 commit comments

Comments
 (0)