Skip to content

Commit

Permalink
Merge branch 'feature/maxUpdates-etc'
Browse files Browse the repository at this point in the history
  • Loading branch information
samme committed Mar 25, 2020
2 parents 421d2d5 + cf3e488 commit a6ed7b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.updatesThisFrame = 1;

/**
* Number of renders expected to occur this animation frame. May be 0 if {@link #dropFrames is on} or {@link #forceSingleRender} is off; otherwise it will be 1.
* @property {integer} updatesThisFrame
* Number of renders expected to occur this animation frame. May be 0 if {@link #dropFrames} is on or {@link #forceSingleRender} is off; otherwise it will be 1.
* @property {integer} rendersThisFrame
* @protected
*/
this.rendersThisFrame = 1;
Expand Down Expand Up @@ -456,22 +456,32 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant

/**
* @property {boolean} forceSingleUpdate - Should the game loop force a logic update, regardless of the delta timer? You can toggle it on the fly.
* @default
*/
this.forceSingleUpdate = true;

/**
* @property {boolean} forceSingleRender - Should the game loop make one render per animation frame, even without a preceding logic update? (During spiraling conditions, {@link #dropFrames} is used instead.)
* @default
*/
this.forceSingleRender = true;

/**
* @property {boolean} dropFrames - When {@link #forceSingleUpdate} is off, skip {@link #updateRender rendering} if logic updates are spiraling upwards.
* @default
*/
this.dropFrames = false;

/**
* @property {number} maxUpdates - When {@link #forceSingleUpdate} is off, the maximum number of logic updates to make per animation frame, if required to catch up.
* @default
*/
this.maxUpdates = 3;

/**
* @property {string} powerPreference - When the WebGL renderer is used, hint to the browser which GPU to use.
* @readonly
* @default
*/
this.powerPreference = 'default';

Expand Down Expand Up @@ -1039,8 +1049,8 @@ Phaser.Game.prototype = {
// step size taking into account the slow motion speed
var slowStep = this.time.slowMotion * 1000.0 / this.time.desiredFps;

// accumulate time until the slowStep threshold is met or exceeded... up to a limit of 3 catch-up frames at slowStep intervals
this._deltaTime += Math.max(Math.min(slowStep * 3, this.time.elapsed), 0);
// accumulate time until the slowStep threshold is met or exceeded... up to a limit of `maxUpdates` (3) catch-up frames at slowStep intervals
this._deltaTime += Math.max(Math.min(slowStep * this.maxUpdates, this.time.elapsed), 0);

// call the game update logic multiple times if necessary to "catch up" with dropped frames
// unless forceSingleUpdate is true
Expand Down Expand Up @@ -1125,7 +1135,7 @@ Phaser.Game.prototype = {
this.pendingStep = true;
}

this.time.countUpdate();
this.time.preUpdate();

this.scale.preUpdate();
this.debug.preUpdate();
Expand Down Expand Up @@ -1183,7 +1193,7 @@ Phaser.Game.prototype = {
return;
}

this.time.countRender();
this.time.preRender();

this.state.preRender(elapsedTime);

Expand Down
16 changes: 9 additions & 7 deletions src/time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Phaser.Time = function (game)
*
* While the game is active, this will be similar to (1000 / {@link #fps}).
*
* _Note:_ This is updated only once per game loop - even if multiple logic update steps are done.
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
* This is updated only once per game loop, even if multiple logic update steps are done.
* Use {@link Phaser.Time#physicsElapsed physicsElapsed} as a basis of game/logic calculations instead.
*
* @property {number} elapsed
* @see Phaser.Time.time
Expand All @@ -93,8 +93,10 @@ Phaser.Time = function (game)
*
* This value is corrected for game pauses and will be "about zero" after a game is resumed.
*
* _Note:_ This is updated once per game loop - even if multiple logic update steps are done.
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
* This is updated at each logic update, possibly more than once per game loop.
* If multiple logic update steps are done, the `elapsedMS` values will differ greatly.
*
* Use {@link Phaser.Time#physicsElapsedMS physicsElapsedMS} as a basis of game/logic calculations instead.
*
* @property {integer} elapsedMS
* @protected
Expand Down Expand Up @@ -562,10 +564,10 @@ Phaser.Time.prototype = {
/**
* Counts one logic update (if advanced timing is enabled).
*
* @method Phaser.Time#countUpdate
* @method Phaser.Time#preUpdate
* @private
*/
countUpdate: function ()
preUpdate: function ()
{

if (this.advancedTiming)
Expand All @@ -581,7 +583,7 @@ Phaser.Time.prototype = {
* @method Phaser.Time#countRender
* @private
*/
countRender: function ()
preRender: function ()
{

if (this.advancedTiming)
Expand Down

0 comments on commit a6ed7b0

Please sign in to comment.