Skip to content

Commit 7aa3b3b

Browse files
committed
TimeStep.now is a new property that holds the exact performance.now value, as set at the start of the current game step. Also, completed jsdocs.
1 parent b86d737 commit 7aa3b3b

1 file changed

Lines changed: 47 additions & 23 deletions

File tree

src/core/TimeStep.js

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,37 +185,39 @@ var TimeStep = new Class({
185185
this.forceSetTimeOut = GetValue(config, 'forceSetTimeOut', false);
186186

187187
/**
188-
* [description]
188+
* The time, calculated at the start of the current step, as smoothed by the delta value.
189189
*
190190
* @name Phaser.Core.TimeStep#time
191-
* @type {integer}
191+
* @type {number}
192192
* @default 0
193193
* @since 3.0.0
194194
*/
195195
this.time = 0;
196196

197197
/**
198-
* [description]
198+
* The time at which the game started running. This value is adjusted if the game is then
199+
* paused and resumes.
199200
*
200201
* @name Phaser.Core.TimeStep#startTime
201-
* @type {integer}
202+
* @type {number}
202203
* @default 0
203204
* @since 3.0.0
204205
*/
205206
this.startTime = 0;
206207

207208
/**
208-
* [description]
209+
* The time, as returned by `performance.now` of the previous step.
209210
*
210211
* @name Phaser.Core.TimeStep#lastTime
211-
* @type {integer}
212+
* @type {number}
212213
* @default 0
213214
* @since 3.0.0
214215
*/
215216
this.lastTime = 0;
216217

217218
/**
218-
* [description]
219+
* The current frame the game is on. This counter is incremented once every game step, regardless of how much
220+
* time has passed and is unaffected by delta smoothing.
219221
*
220222
* @name Phaser.Core.TimeStep#frame
221223
* @type {integer}
@@ -226,7 +228,8 @@ var TimeStep = new Class({
226228
this.frame = 0;
227229

228230
/**
229-
* [description]
231+
* Is the browser currently considered in focus by the Page Visibility API?
232+
* This value is set in the `blur` method, which is called automatically by the Game instance.
230233
*
231234
* @name Phaser.Core.TimeStep#inFocus
232235
* @type {boolean}
@@ -237,18 +240,18 @@ var TimeStep = new Class({
237240
this.inFocus = true;
238241

239242
/**
240-
* [description]
243+
* The timestamp at which the game became paused, as determined by the Page Visibility API.
241244
*
242245
* @name Phaser.Core.TimeStep#_pauseTime
243-
* @type {integer}
246+
* @type {number}
244247
* @private
245248
* @default 0
246249
* @since 3.0.0
247250
*/
248251
this._pauseTime = 0;
249252

250253
/**
251-
* [description]
254+
* An internal counter to allow for the browser 'cooling down' after coming back into focus.
252255
*
253256
* @name Phaser.Core.TimeStep#_coolDown
254257
* @type {integer}
@@ -259,7 +262,7 @@ var TimeStep = new Class({
259262
this._coolDown = 0;
260263

261264
/**
262-
* [description]
265+
* The delta time, in ms, since the last game step. This is a clamped and smoothed average value.
263266
*
264267
* @name Phaser.Core.TimeStep#delta
265268
* @type {integer}
@@ -269,7 +272,7 @@ var TimeStep = new Class({
269272
this.delta = 0;
270273

271274
/**
272-
* [description]
275+
* Internal index of the delta history position.
273276
*
274277
* @name Phaser.Core.TimeStep#deltaIndex
275278
* @type {integer}
@@ -279,7 +282,7 @@ var TimeStep = new Class({
279282
this.deltaIndex = 0;
280283

281284
/**
282-
* [description]
285+
* Internal array holding the previous delta values, used for delta smoothing.
283286
*
284287
* @name Phaser.Core.TimeStep#deltaHistory
285288
* @type {integer[]}
@@ -288,7 +291,9 @@ var TimeStep = new Class({
288291
this.deltaHistory = [];
289292

290293
/**
291-
* [description]
294+
* The maximum number of delta values that are retained in order to calculate a smoothed moving average.
295+
*
296+
* This can be changed in the Game Config via the `fps.deltaHistory` property. The default is 10.
292297
*
293298
* @name Phaser.Core.TimeStep#deltaSmoothingMax
294299
* @type {integer}
@@ -298,7 +303,10 @@ var TimeStep = new Class({
298303
this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10);
299304

300305
/**
301-
* [description]
306+
* The number of frames that the cooldown is set to after the browser panics over the FPS rate, usually
307+
* as a result of switching tabs and regaining focus.
308+
*
309+
* This can be changed in the Game Config via the `fps.panicMax` property. The default is 120.
302310
*
303311
* @name Phaser.Core.TimeStep#panicMax
304312
* @type {integer}
@@ -309,19 +317,31 @@ var TimeStep = new Class({
309317

310318
/**
311319
* The actual elapsed time in ms between one update and the next.
312-
* Unlike with `delta` no smoothing, capping, or averaging is applied to this value.
313-
* So please be careful when using this value in calculations.
320+
*
321+
* Unlike with `delta`, no smoothing, capping, or averaging is applied to this value.
322+
* So please be careful when using this value in math calculations.
314323
*
315324
* @name Phaser.Core.TimeStep#rawDelta
316325
* @type {number}
317326
* @default 0
318327
* @since 3.0.0
319328
*/
320329
this.rawDelta = 0;
330+
331+
/**
332+
* The time, as returned by `performance.now` at the very start of the current step.
333+
* This can differ from the `time` value in that it isn't calculated based on the delta value.
334+
*
335+
* @name Phaser.Core.TimeStep#now
336+
* @type {number}
337+
* @default 0
338+
* @since 3.18.0
339+
*/
340+
this.now = 0;
321341
},
322342

323343
/**
324-
* Called when the DOM window.onBlur event triggers.
344+
* Called by the Game instance when the DOM window.onBlur event triggers.
325345
*
326346
* @method Phaser.Core.TimeStep#blur
327347
* @since 3.0.0
@@ -332,7 +352,7 @@ var TimeStep = new Class({
332352
},
333353

334354
/**
335-
* Called when the DOM window.onFocus event triggers.
355+
* Called by the Game instance when the DOM window.onFocus event triggers.
336356
*
337357
* @method Phaser.Core.TimeStep#focus
338358
* @since 3.0.0
@@ -369,7 +389,8 @@ var TimeStep = new Class({
369389
},
370390

371391
/**
372-
* [description]
392+
* Resets the time, lastTime, fps averages and delta history.
393+
* Called automatically when a browser sleeps them resumes.
373394
*
374395
* @method Phaser.Core.TimeStep#resetDelta
375396
* @since 3.0.0
@@ -442,8 +463,11 @@ var TimeStep = new Class({
442463
// Because the timestamp passed in from raf represents the beginning of the main thread frame that we’re currently in,
443464
// not the actual time now. As we want to compare this time value against Event timeStamps and the like, we need a
444465
// more accurate one:
466+
445467
var time = window.performance.now();
446468

469+
this.now = time;
470+
447471
var before = time - this.lastTime;
448472

449473
if (before < 0)
@@ -558,7 +582,7 @@ var TimeStep = new Class({
558582
},
559583

560584
/**
561-
* Manually calls TimeStep.step, passing in the performance.now value to it.
585+
* Manually calls `TimeStep.step`.
562586
*
563587
* @method Phaser.Core.TimeStep#tick
564588
* @since 3.0.0
@@ -608,7 +632,7 @@ var TimeStep = new Class({
608632

609633
this.running = true;
610634

611-
this.step(window.performance.now());
635+
this.step();
612636
},
613637

614638
/**

0 commit comments

Comments
 (0)