Game.forceSingleUpdate will force just a single logic update, regardless of the delta timer values. You can use this in extremely heavy CPU situations where you know you're about to flood the CPU but don't want Phaser to get stuck in a spiral.

This commit is contained in:
photonstorm 2014-11-11 05:51:47 +00:00
parent 0504fa7969
commit bf70df2658
2 changed files with 15 additions and 1 deletions

View file

@ -105,6 +105,7 @@ Version 2.2.0 - "Bethal" - in development
* Time.slowMotion allows you to push the game into a slow motion mode. The default value is 1.0. 2.0 would be half speed, and so on.
* Time.timeCap is no longer used and now deprecated. All timing is now handled by the fixed time-step code we've introduced.
* Time.now can no longer be relied upon to contain a timestamp value. If the browser supports requestAnimationFrame then `Time.now` will contain the high resolution timer value that rAf generates. Otherwise it will contain the value of Date.now. If you require the actual time value (in milliseconds) then please use `Time.time` instead. Note that all Phaser sub-systems that used to rely on `Time.now` have been updated, so if you have any code that extends these please be sure to check it.
* Game.forceSingleUpdate will force just a single logic update, regardless of the delta timer values. You can use this in extremely heavy CPU situations where you know you're about to flood the CPU but don't want Phaser to get stuck in a spiral.
* Tilemap.createFromTiles will convert all tiles matching the given tile index (or an array of indexes) into Sprites. You can optionally then replace these tiles if you wish. This is perfect for games when you want to turn specific tiles into Sprites for extra control. The Sprites have an optional properties object which they can be populated with.
### Updates

View file

@ -311,6 +311,11 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
*/
this.fpsProblemNotifier = new Phaser.Signal();
/**
* @property {boolean} forceSingleUpdate - Should the game loop force a logic update, regardless of the delta timer? Set to true if you know you need this. You can toggle it on the fly.
*/
this.forceSingleUpdate = false;
/**
* @property {number} _nextNotification - the soonest game.time.time value that the next fpsProblemNotifier can be dispatched
* @private
@ -697,7 +702,7 @@ Phaser.Game.prototype = {
this.time.update(time);
// if the logic time is spiralling upwards, skip a frame entirely
if (this._spiralling > 1)
if (this._spiralling > 1 && !this.forceSingleUpdate)
{
// cause an event to warn the program that this CPU can't keep up with the current desiredFps rate
if (this.time.time > this._nextFpsNotification)
@ -712,6 +717,8 @@ Phaser.Game.prototype = {
// reset the _deltaTime accumulator which will cause all pending dropped frames to be permanently skipped
this._deltaTime = 0;
this._spiralling = 0;
var slowStep = this.time.slowMotion * 1000.0 / this.time.desiredFps;
}
else
{
@ -722,6 +729,7 @@ Phaser.Game.prototype = {
this._deltaTime += Math.max(Math.min(1000, this.time.elapsed), 0);
// call the game update logic multiple times if necessary to "catch up" with dropped frames
// unless forceSingleUpdate is true
var count = 0;
while (this._deltaTime >= slowStep)
@ -729,6 +737,11 @@ Phaser.Game.prototype = {
this._deltaTime -= slowStep;
this.updateLogic(1.0 / this.time.desiredFps);
count++;
if (this.forceSingleUpdate && count === 1)
{
break;
}
}
// detect spiralling (if the catch-up loop isn't fast enough, the number of iterations will increase constantly)