Skip to content

Commit c5381f9

Browse files
committed
Time/Time - documentation updates and minor cleanup
- Removed `Time.pausedTime` Time.pausedTime has not been used / updated since b255fea in Feb 2014. There might be a case to re-explore how pause time is reported/observable, possibly with a distinction of 'current' and 'last' and the semantics of such. For instance, pause duration is only updated after the resume occurs and reflects the duration-of-the-last-pause.. - Removed `Time` _i and _len properties These are better suited by local variables. - General documentation updates. - Marked several methods such as `Timer.order` as protected - there are advanced use-cases for them, but different user-facing methods and documentations are likely in order. Also marked `Timer.sortHandler` as private; but did not change any interfaces.
1 parent 8ffd686 commit c5381f9

3 files changed

Lines changed: 141 additions & 90 deletions

File tree

src/time/Time.js

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
/**
88
* This is the core internal game clock.
9-
* It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens.
9+
*
10+
* It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens,
11+
* and also handlers the standard Timer pool.
12+
*
13+
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
1014
*
1115
* @class Phaser.Time
1216
* @constructor
@@ -37,7 +41,8 @@ Phaser.Time = function (game) {
3741
/**
3842
* An increasing value representing cumulative milliseconds since an undisclosed epoch.
3943
*
40-
* This value must _not_ be used with `Date.now()`.
44+
* While this value is in milliseconds and can be used to compute time deltas,
45+
* it must must _not_ be used with `Date.now()` as it may not use the same epoch / starting reference.
4146
*
4247
* The source may either be from a high-res source (eg. if RAF is available) or the standard Date.now;
4348
* the value can only be relied upon within a particular game instance.
@@ -78,16 +83,17 @@ Phaser.Time = function (game) {
7883
* The physics update delta, in fractional seconds.
7984
*
8085
* This should be used as an applicable multiplier by all logic update steps (eg. `preUpdate/postUpdate/update`)
81-
* to ensure consistent game timing.
86+
* to ensure consistent game timing. Game/logic timing can drift from real-world time if the system
87+
* is unable to consistently maintain the desired FPS.
8288
*
83-
* With fixed-step updates this normally equivalent to `1.0 / desiredFps`.
89+
* With fixed-step updates this is normally equivalent to `1.0 / desiredFps`.
8490
*
8591
* @property {number} physicsElapsed
8692
*/
8793
this.physicsElapsed = 0;
8894

8995
/**
90-
* The Time.physicsElapsed property * 1000.
96+
* The physics update delta, in milliseconds - equivalent to `physicsElapsed * 1000`.
9197
*
9298
* @property {number} physicsElapsedMS
9399
*/
@@ -114,57 +120,76 @@ Phaser.Time = function (game) {
114120
this.suggestedFps = null;
115121

116122
/**
117-
* @property {number} slowMotion = 1.0 - Scaling factor to make the game move smoothly in slow motion (1.0 = normal speed, 2.0 = half speed)
123+
* Scaling factor to make the game move smoothly in slow motion
124+
* - 1.0 = normal speed
125+
* - 2.0 = half speed
126+
* @property {number} slowMotion
118127
* @default
119128
*/
120129
this.slowMotion = 1.0;
121130

122131
/**
123-
* @property {boolean} advancedTiming - If true Phaser.Time will perform advanced profiling including the fps rate, fps min/max and msMin and msMax.
132+
* If true then advanced profiling, including the fps rate, fps min/max and msMin/msMax are updated.
133+
* @property {boolean} advancedTiming
124134
* @default
125135
*/
126136
this.advancedTiming = false;
127137

128138
/**
129-
* @property {number} fps - Frames per second. Only calculated if Time.advancedTiming is true.
130-
* @protected
139+
* Advanced timing result: The number of render frames record in the last second.
140+
*
141+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
142+
* @property {integer} frames
143+
* @readonly
144+
*/
145+
this.frames = 0;
146+
147+
/**
148+
* Advanced timing result: Frames per second.
149+
*
150+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
151+
* @property {number} fps
152+
* @readonly
131153
*/
132154
this.fps = 0;
133155

134156
/**
135-
* @property {number} fpsMin - The lowest rate the fps has dropped to. Only calculated if Time.advancedTiming is true.
157+
* Advanced timing result: The lowest rate the fps has dropped to.
158+
*
159+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
160+
* This value can be manually reset.
161+
* @property {number} fpsMin
136162
*/
137163
this.fpsMin = 1000;
138164

139165
/**
140-
* @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). Only calculated if Time.advancedTiming is true.
166+
* Advanced timing result: The highest rate the fps has reached (usually no higher than 60fps).
167+
*
168+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
169+
* This value can be manually reset.
170+
* @property {number} fpsMax
141171
*/
142172
this.fpsMax = 0;
143173

144174
/**
145-
* @property {number} msMin - The minimum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true.
175+
* Advanced timing result: The minimum amount of time the game has taken between consecutive frames.
176+
*
177+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
178+
* This value can be manually reset.
179+
* @property {number} msMin
146180
* @default
147181
*/
148182
this.msMin = 1000;
149183

150184
/**
151-
* @property {number} msMax - The maximum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true.
185+
* Advanced timing result: The maximum amount of time the game has taken between consecutive frames.
186+
*
187+
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
188+
* This value can be manually reset.
189+
* @property {number} msMax
152190
*/
153191
this.msMax = 0;
154192

155-
/**
156-
* The number of render frames record in the last second. Only calculated if Time.advancedTiming is true.
157-
* @property {integer} frames
158-
*/
159-
this.frames = 0;
160-
161-
/**
162-
* The `time` when the game was last paused.
163-
* @property {number} pausedTime
164-
* @protected
165-
*/
166-
this.pausedTime = 0;
167-
168193
/**
169194
* Records how long the game was last paused, in miliseconds.
170195
* (This is not updated until the game is resumed.)
@@ -185,20 +210,21 @@ Phaser.Time = function (game) {
185210
this.timeExpected = 0;
186211

187212
/**
188-
* @property {Phaser.Timer} events - This is a Phaser.Timer object bound to the master clock to which you can add timed events.
213+
* A {@link Phaser.Timer} object bound to the master clock (this Time object) which events can be added to.
214+
* @property {Phaser.Timer} events
189215
*/
190216
this.events = new Phaser.Timer(this.game, false);
191217

192218
/**
193-
* @property {number} _frameCount - count the number of calls to time.update since the last suggestedFps was calculated
194-
* @private
195-
*/
219+
* @property {number} _frameCount - count the number of calls to time.update since the last suggestedFps was calculated
220+
* @private
221+
*/
196222
this._frameCount = 0;
197223

198224
/**
199-
* @property {number} _elapsedAcumulator - sum of the elapsed time since the last suggestedFps was calculated
200-
* @private
201-
*/
225+
* @property {number} _elapsedAcumulator - sum of the elapsed time since the last suggestedFps was calculated
226+
* @private
227+
*/
202228
this._elapsedAccumulator = 0;
203229

204230
/**
@@ -231,18 +257,6 @@ Phaser.Time = function (game) {
231257
*/
232258
this._timers = [];
233259

234-
/**
235-
* @property {number} _len - Temp. array length variable.
236-
* @private
237-
*/
238-
this._len = 0;
239-
240-
/**
241-
* @property {number} _i - Temp. array counter variable.
242-
* @private
243-
*/
244-
this._i = 0;
245-
246260
};
247261

248262
Phaser.Time.prototype = {
@@ -296,7 +310,7 @@ Phaser.Time.prototype = {
296310
},
297311

298312
/**
299-
* Remove all Timer objects, regardless of their state. Also clears all Timers from the Time.events timer.
313+
* Remove all Timer objects, regardless of their state and clears all Timers from the {@link Phaser.Time#events events} timer.
300314
*
301315
* @method Phaser.Time#removeAll
302316
*/
@@ -318,7 +332,7 @@ Phaser.Time.prototype = {
318332
*
319333
* @method Phaser.Time#update
320334
* @protected
321-
* @param {number} time - The current timestamp.
335+
* @param {number} time - The current relative timestamp; see {@link Phaser.Time#now now}.
322336
*/
323337
update: function (time) {
324338

@@ -388,20 +402,20 @@ Phaser.Time.prototype = {
388402
this.events.update(this.time);
389403

390404
// Any game level timers
391-
this._i = 0;
392-
this._len = this._timers.length;
405+
var i = 0;
406+
var len = this._timers.length;
393407

394-
while (this._i < this._len)
408+
while (i < len)
395409
{
396-
if (this._timers[this._i].update(this.time))
410+
if (this._timers[i].update(this.time))
397411
{
398-
this._i++;
412+
i++;
399413
}
400414
else
401415
{
402-
this._timers.splice(this._i, 1);
403-
404-
this._len--;
416+
// Timer requests to be removed
417+
this._timers.splice(i, 1);
418+
len--;
405419
}
406420
}
407421
}

0 commit comments

Comments
 (0)