Skip to content

Commit 74e4357

Browse files
committed
Added rawDelta property to TimeStep and made sure the time value passed to update is the non-smoothed version.
1 parent 1e409d7 commit 74e4357

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

v3/src/boot/TimeStep.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
1212
// panicMax: 120
1313
// }
1414

15+
// http://www.testufo.com/#test=animation-time-graph
16+
//
17+
1518
var TimeStep = function (game, config)
1619
{
1720
this.game = game;
@@ -61,6 +64,10 @@ var TimeStep = function (game, config)
6164
this.deltaHistory = [];
6265
this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10);
6366
this.panicMax = GetValue(config, 'panicMax', 120);
67+
68+
// The actual elapsed time in ms between one update and the next.
69+
// No smoothing, no capping, no averaging. So please be aware of this when using the contents of this property.
70+
this.rawDelta = 0;
6471
};
6572

6673
TimeStep.prototype.constructor = TimeStep;
@@ -72,23 +79,23 @@ TimeStep.prototype = {
7279
{
7380
this.inFocus = false;
7481

75-
console.log('TimeStep.blur');
82+
// console.log('TimeStep.blur');
7683
},
7784

7885
// Called when the DOM window.onFocus event triggers
7986
focus: function ()
8087
{
8188
this.inFocus = true;
8289

83-
console.log('TimeStep.focus');
90+
// console.log('TimeStep.focus');
8491

8592
this.resetDelta();
8693
},
8794

8895
// Called when the visibility API says the game is 'hidden' (tab switch, etc)
8996
pause: function ()
9097
{
91-
console.log('TimeStep.pause');
98+
// console.log('TimeStep.pause');
9299

93100
this._pauseTime = window.performance.now();
94101
},
@@ -100,7 +107,7 @@ TimeStep.prototype = {
100107

101108
this.startTime += this.time - this._pauseTime;
102109

103-
console.log('TimeStep.resume - paused for', (this.time - this._pauseTime));
110+
// console.log('TimeStep.resume - paused for', (this.time - this._pauseTime));
104111
},
105112

106113
resetDelta: function ()
@@ -157,12 +164,14 @@ TimeStep.prototype = {
157164

158165
this.frame++;
159166

167+
this.rawDelta = time - this.lastTime;
168+
160169
var idx = this.deltaIndex;
161170
var history = this.deltaHistory;
162171
var max = this.deltaSmoothingMax;
163172

164173
// delta time (time is in ms)
165-
var dt;
174+
var dt = (time - this.lastTime);
166175

167176
// When a browser switches tab, then comes back again, it takes around 10 frames before
168177
// the delta time settles down so we employ a 'cooling down' period before we start
@@ -175,10 +184,6 @@ TimeStep.prototype = {
175184
dt = this._target;
176185
// debug = (time - this.lastTime);
177186
}
178-
else
179-
{
180-
dt = (time - this.lastTime);
181-
}
182187

183188
// min / max range (yes, the < and > should be this way around)
184189
if (dt > this._min || dt < this._max)
@@ -231,24 +236,25 @@ TimeStep.prototype = {
231236
this.delta = avg;
232237

233238
// Real-world timer advance
234-
this.time += avg;
239+
// this.time += avg;
240+
this.time += this.rawDelta;
235241

236242
// Update the estimate of the frame rate, `fps`. Every second, the number
237243
// of frames that occurred in that second are included in an exponential
238244
// moving average of all frames per second, with an alpha of 0.25. This
239245
// means that more recent seconds affect the estimated frame rate more than
240246
// older seconds.
241-
//
247+
//
242248
// When a browser window is NOT minimized, but is covered up (i.e. you're using
243249
// another app which has spawned a window over the top of the browser), then it
244250
// will start to throttle the raf callback time. It waits for a while, and then
245251
// starts to drop the frame rate at 1 frame per second until it's down to just over 1fps.
246252
// So if the game was running at 60fps, and the player opens a new window, then
247253
// after 60 seconds (+ the 'buffer time') it'll be down to 1fps, so rafin'g at 1Hz.
248-
//
254+
//
249255
// When they make the game visible again, the frame rate is increased at a rate of
250256
// approx. 8fps, back up to 60fps (or the max it can obtain)
251-
//
257+
//
252258
// There is no easy way to determine if this drop in frame rate is because the
253259
// browser is throttling raf, or because the game is struggling with performance
254260
// because you're asking it to do too much on the device.
@@ -272,7 +278,7 @@ TimeStep.prototype = {
272278
// Interpolation - how far between what is expected and where we are?
273279
var interpolation = avg / this._target;
274280

275-
this.callback(this.time, avg, interpolation);
281+
this.callback(time, avg, interpolation);
276282

277283
// Shift time value over
278284
this.lastTime = time;

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: 'b0193f70-4be8-11e7-b4be-973197875ba4'
2+
build: '17021190-4c47-11e7-a481-8b4cb4cf5fd2'
33
};
44
module.exports = CHECKSUM;

0 commit comments

Comments
 (0)