From b255fea85f7b4bb9b0a335a1407300db83e3f671 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Tue, 25 Feb 2014 03:50:52 +0000 Subject: [PATCH] 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. --- README.md | 1 + src/input/Pointer.js | 7 ------ src/input/Touch.js | 12 +++++----- src/time/Time.js | 57 +++++++++++++++++++++----------------------- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 57a71abf1..5629186b4 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ Significant API changes: * 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. * Keyboard.removeKey has been removed. The way the new keyboard manager works means it's no longer required. * When a game un-pauses (from a visibility loss) it resets all Input components. +* 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. New features: diff --git a/src/input/Pointer.js b/src/input/Pointer.js index 874e69f69..6cf28f600 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -206,13 +206,6 @@ Phaser.Pointer.prototype = { this.button = event.button; } - // Fix to stop rogue browser plugins from blocking the visibility state event - if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.scale.incorrectOrientation === false) - { - // this.game.paused = false; - // return this; - } - this._history.length = 0; this.active = true; this.withinGame = true; diff --git a/src/input/Touch.js b/src/input/Touch.js index b97011187..ed0e5abc2 100644 --- a/src/input/Touch.js +++ b/src/input/Touch.js @@ -152,12 +152,12 @@ Phaser.Touch.prototype = { return _this.onTouchCancel(event); }; - this.game.renderer.view.addEventListener('touchstart', this._onTouchStart, false); - this.game.renderer.view.addEventListener('touchmove', this._onTouchMove, false); - this.game.renderer.view.addEventListener('touchend', this._onTouchEnd, false); - this.game.renderer.view.addEventListener('touchenter', this._onTouchEnter, false); - this.game.renderer.view.addEventListener('touchleave', this._onTouchLeave, false); - this.game.renderer.view.addEventListener('touchcancel', this._onTouchCancel, false); + this.game.canvas.addEventListener('touchstart', this._onTouchStart, false); + this.game.canvas.addEventListener('touchmove', this._onTouchMove, false); + this.game.canvas.addEventListener('touchend', this._onTouchEnd, false); + this.game.canvas.addEventListener('touchenter', this._onTouchEnter, false); + this.game.canvas.addEventListener('touchleave', this._onTouchLeave, false); + this.game.canvas.addEventListener('touchcancel', this._onTouchCancel, false); } }, diff --git a/src/time/Time.js b/src/time/Time.js index f71ba1f3f..d52744c4e 100644 --- a/src/time/Time.js +++ b/src/time/Time.js @@ -44,29 +44,35 @@ Phaser.Time = function (game) { this.pausedTime = 0; /** - * @property {number} fps - Frames per second. + * @property {boolean} advancedTiming - If true Phaser.Time will perform advanced profiling including the fps rate, fps min/max and msMin and msMax. + * @default + */ + this.advancedTiming = false; + + /** + * @property {number} fps - Frames per second. Only calculated if Time.advancedTiming is true. * @protected */ this.fps = 0; /** - * @property {number} fpsMin - The lowest rate the fps has dropped to. + * @property {number} fpsMin - The lowest rate the fps has dropped to. Only calculated if Time.advancedTiming is true. */ this.fpsMin = 1000; /** - * @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). + * @property {number} fpsMax - The highest rate the fps has reached (usually no higher than 60fps). Only calculated if Time.advancedTiming is true. */ this.fpsMax = 0; /** - * @property {number} msMin - The minimum amount of time the game has taken between two frames. + * @property {number} msMin - The minimum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true. * @default */ this.msMin = 1000; /** - * @property {number} msMax - The maximum amount of time the game has taken between two frames. + * @property {number} msMax - The maximum amount of time the game has taken between two frames. Only calculated if Time.advancedTiming is true. */ this.msMax = 0; @@ -76,7 +82,7 @@ Phaser.Time = function (game) { this.physicsElapsed = 0; /** - * @property {number} frames - The number of frames record in the last second. + * @property {number} frames - The number of frames record in the last second. Only calculated if Time.advancedTiming is true. */ this.frames = 0; @@ -142,10 +148,6 @@ Phaser.Time = function (game) { */ this._i = 0; - // Listen for game pause/resume events - // this.game.onPause.add(this.gamePaused, this); - // this.game.onResume.add(this.gameResumed, this); - }; Phaser.Time.prototype = { @@ -218,26 +220,26 @@ Phaser.Time.prototype = { this.elapsed = this.now - this.time; - /* - this.msMin = this.game.math.min(this.msMin, this.elapsed); - this.msMax = this.game.math.max(this.msMax, this.elapsed); - - this.frames++; - - if (this.now > this._timeLastSecond + 1000) + if (this.advancedTiming) { - this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond)); - this.fpsMin = this.game.math.min(this.fpsMin, this.fps); - this.fpsMax = this.game.math.max(this.fpsMax, this.fps); - this._timeLastSecond = this.now; - this.frames = 0; + this.msMin = this.game.math.min(this.msMin, this.elapsed); + this.msMax = this.game.math.max(this.msMax, this.elapsed); + + this.frames++; + + if (this.now > this._timeLastSecond + 1000) + { + this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond)); + this.fpsMin = this.game.math.min(this.fpsMin, this.fps); + this.fpsMax = this.game.math.max(this.fpsMax, this.fps); + this._timeLastSecond = this.now; + this.frames = 0; + } } - */ this.time = this.now; this.lastTime = time + this.timeToCall; - /* this.physicsElapsed = 1.0 * (this.elapsed / 1000); // Clamp the delta @@ -245,14 +247,9 @@ Phaser.Time.prototype = { { this.physicsElapsed = 0.05; } - */ // Paused but still running? - if (this.game.paused) - { - // this.pausedTime = this.now - this._pauseStarted; - } - else + if (!this.game.paused) { // Our internal Phaser.Timer this.events.update(this.now);