Skip to content

Commit b255fea

Browse files
committed
Time.advancedTiming is a new boolean property. If true Time.fps, fpsMin, fpsMax, frames, msMin and msMax will be calculated, otherwise they remain at their defaults.
1 parent 8fafb3d commit b255fea

4 files changed

Lines changed: 33 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Significant API changes:
7777
* The Keyboard class has had a complete overhaul. Phaser.Key objects are created automatically, there are fixes against duration and keys reset properly on visibility loss.
7878
* Keyboard.removeKey has been removed. The way the new keyboard manager works means it's no longer required.
7979
* When a game un-pauses (from a visibility loss) it resets all Input components.
80+
* Time.advancedTiming is a new boolean property. If true Time.fps, fpsMin, fpsMax, frames, msMin and msMax will be calculated, otherwise they remain at their defaults.
8081

8182

8283
New features:

src/input/Pointer.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,6 @@ Phaser.Pointer.prototype = {
206206
this.button = event.button;
207207
}
208208

209-
// Fix to stop rogue browser plugins from blocking the visibility state event
210-
if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.scale.incorrectOrientation === false)
211-
{
212-
// this.game.paused = false;
213-
// return this;
214-
}
215-
216209
this._history.length = 0;
217210
this.active = true;
218211
this.withinGame = true;

src/input/Touch.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ Phaser.Touch.prototype = {
152152
return _this.onTouchCancel(event);
153153
};
154154

155-
this.game.renderer.view.addEventListener('touchstart', this._onTouchStart, false);
156-
this.game.renderer.view.addEventListener('touchmove', this._onTouchMove, false);
157-
this.game.renderer.view.addEventListener('touchend', this._onTouchEnd, false);
158-
this.game.renderer.view.addEventListener('touchenter', this._onTouchEnter, false);
159-
this.game.renderer.view.addEventListener('touchleave', this._onTouchLeave, false);
160-
this.game.renderer.view.addEventListener('touchcancel', this._onTouchCancel, false);
155+
this.game.canvas.addEventListener('touchstart', this._onTouchStart, false);
156+
this.game.canvas.addEventListener('touchmove', this._onTouchMove, false);
157+
this.game.canvas.addEventListener('touchend', this._onTouchEnd, false);
158+
this.game.canvas.addEventListener('touchenter', this._onTouchEnter, false);
159+
this.game.canvas.addEventListener('touchleave', this._onTouchLeave, false);
160+
this.game.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
161161
}
162162

163163
},

src/time/Time.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,35 @@ Phaser.Time = function (game) {
4444
this.pausedTime = 0;
4545

4646
/**
47-
* @property {number} fps - Frames per second.
47+
* @property {boolean} advancedTiming - If true Phaser.Time will perform advanced profiling including the fps rate, fps min/max and msMin and msMax.
48+
* @default
49+
*/
50+
this.advancedTiming = false;
51+
52+
/**
53+
* @property {number} fps - Frames per second. Only calculated if Time.advancedTiming is true.
4854
* @protected
4955
*/
5056
this.fps = 0;
5157

5258
/**
53-
* @property {number} fpsMin - The lowest rate the fps has dropped to.
59+
* @property {number} fpsMin - The lowest rate the fps has dropped to. Only calculated if Time.advancedTiming is true.
5460
*/
5561
this.fpsMin = 1000;
5662

5763
/**
58-
* @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps).
64+
* @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). Only calculated if Time.advancedTiming is true.
5965
*/
6066
this.fpsMax = 0;
6167

6268
/**
63-
* @property {number} msMin - The minimum amount of time the game has taken between two frames.
69+
* @property {number} msMin - The minimum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true.
6470
* @default
6571
*/
6672
this.msMin = 1000;
6773

6874
/**
69-
* @property {number} msMax - The maximum amount of time the game has taken between two frames.
75+
* @property {number} msMax - The maximum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true.
7076
*/
7177
this.msMax = 0;
7278

@@ -76,7 +82,7 @@ Phaser.Time = function (game) {
7682
this.physicsElapsed = 0;
7783

7884
/**
79-
* @property {number} frames - The number of frames record in the last second.
85+
* @property {number} frames - The number of frames record in the last second. Only calculated if Time.advancedTiming is true.
8086
*/
8187
this.frames = 0;
8288

@@ -142,10 +148,6 @@ Phaser.Time = function (game) {
142148
*/
143149
this._i = 0;
144150

145-
// Listen for game pause/resume events
146-
// this.game.onPause.add(this.gamePaused, this);
147-
// this.game.onResume.add(this.gameResumed, this);
148-
149151
};
150152

151153
Phaser.Time.prototype = {
@@ -218,41 +220,36 @@ Phaser.Time.prototype = {
218220

219221
this.elapsed = this.now - this.time;
220222

221-
/*
222-
this.msMin = this.game.math.min(this.msMin, this.elapsed);
223-
this.msMax = this.game.math.max(this.msMax, this.elapsed);
223+
if (this.advancedTiming)
224+
{
225+
this.msMin = this.game.math.min(this.msMin, this.elapsed);
226+
this.msMax = this.game.math.max(this.msMax, this.elapsed);
224227

225-
this.frames++;
228+
this.frames++;
226229

227-
if (this.now > this._timeLastSecond + 1000)
228-
{
229-
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
230-
this.fpsMin = this.game.math.min(this.fpsMin, this.fps);
231-
this.fpsMax = this.game.math.max(this.fpsMax, this.fps);
232-
this._timeLastSecond = this.now;
233-
this.frames = 0;
230+
if (this.now > this._timeLastSecond + 1000)
231+
{
232+
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
233+
this.fpsMin = this.game.math.min(this.fpsMin, this.fps);
234+
this.fpsMax = this.game.math.max(this.fpsMax, this.fps);
235+
this._timeLastSecond = this.now;
236+
this.frames = 0;
237+
}
234238
}
235-
*/
236239

237240
this.time = this.now;
238241
this.lastTime = time + this.timeToCall;
239242

240-
/*
241243
this.physicsElapsed = 1.0 * (this.elapsed / 1000);
242244

243245
// Clamp the delta
244246
if (this.physicsElapsed > 0.05)
245247
{
246248
this.physicsElapsed = 0.05;
247249
}
248-
*/
249250

250251
// Paused but still running?
251-
if (this.game.paused)
252-
{
253-
// this.pausedTime = this.now - this._pauseStarted;
254-
}
255-
else
252+
if (!this.game.paused)
256253
{
257254
// Our internal Phaser.Timer
258255
this.events.update(this.now);

0 commit comments

Comments
 (0)