File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
3130VariableTimeStep . 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
Original file line number Diff line number Diff line change 11var CHECKSUM = {
2- build : '77d3f640-2f92 -11e7-94cb-df78655b45e3 '
2+ build : '1fea37a0-2f97 -11e7-93dd-fd6f78427b2e '
33} ;
44module . exports = CHECKSUM ;
You can’t perform that action at this time.
0 commit comments