mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Fixed delta spike handling.
This commit is contained in:
parent
02a06bc7e3
commit
e5b82eb9b9
2 changed files with 10 additions and 11 deletions
|
@ -20,12 +20,11 @@ var VariableTimeStep = function (game, framerate)
|
|||
this.time = 0;
|
||||
this.startTime = 0;
|
||||
this.lastTime = 0;
|
||||
this.runOff = 0;
|
||||
|
||||
this.delta = 0;
|
||||
this.deltaIndex = 0;
|
||||
this.deltaHistory = [];
|
||||
this.deltaSmoothingMax = 30;
|
||||
this.deltaSmoothingMax = 10;
|
||||
};
|
||||
|
||||
VariableTimeStep.prototype.constructor = VariableTimeStep;
|
||||
|
@ -70,15 +69,19 @@ VariableTimeStep.prototype = {
|
|||
|
||||
step: function (time)
|
||||
{
|
||||
var idx = this.deltaIndex;
|
||||
var history = this.deltaHistory;
|
||||
var max = this.deltaSmoothingMax;
|
||||
|
||||
// delta time
|
||||
var dt = (time - this.lastTime) / 1000;
|
||||
|
||||
if (dt < 0 || dt > 1)
|
||||
{
|
||||
// Loop skip, probably super bad start time
|
||||
this.runOff = time - this.lastTime;
|
||||
this.lastTime = time;
|
||||
return;
|
||||
// Probably super bad start time or browser tab inactivity / context loss
|
||||
// so use the last 'sane' dt value
|
||||
|
||||
dt = history[idx];
|
||||
}
|
||||
|
||||
// clamp delta to 0.0001 to 0.5 range
|
||||
|
@ -86,10 +89,6 @@ VariableTimeStep.prototype = {
|
|||
|
||||
// Smooth out the delta over the previous X frames
|
||||
|
||||
var idx = this.deltaIndex;
|
||||
var history = this.deltaHistory;
|
||||
var max = this.deltaSmoothingMax;
|
||||
|
||||
// add the delta to the smoothing array
|
||||
history[idx] = dt;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '77d3f640-2f92-11e7-94cb-df78655b45e3'
|
||||
build: '1fea37a0-2f97-11e7-93dd-fd6f78427b2e'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
Loading…
Reference in a new issue