RAF now calls StateManager.step directly.

Game no longer has RNG property.
This commit is contained in:
photonstorm 2017-01-25 12:02:18 +00:00
parent 5f2d4473f3
commit 5c495bbdf8
6 changed files with 39 additions and 52 deletions

View file

@ -272,7 +272,7 @@ When the DOM Content Loaded event happens, the Game calls Game.boot. This sets-u
Every time RAF ticks it calls the following:
1. Calls `Game.update`, which ...
1. --removed--
2. Calls `StateManager.step`, which ...
3. Iterates through all _active_ States, and ...
4. Calls `State.sys.mainloop.step`, which ...
@ -297,8 +297,6 @@ Every time RAF ticks it calls the following:
In a tree form it maps to the following:
```
+ Game.update
|
+ StateManager.step (iterates all active States)
|
+- State.sys.mainloop.step (updates delta values)

View file

@ -13,7 +13,6 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
var DOMContentLoaded = require('../dom/DOMContentLoaded');
var CreateRenderer = require('./CreateRenderer');
var RandomDataGenerator = require('../math/random-data-generator/RandomDataGenerator');
var StateManager = require('../state/StateManager');
var TextureManager = require('../textures/TextureManager');
@ -32,7 +31,7 @@ var Game = function (config)
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @protected
*/
this.raf = new RequestAnimationFrame(this);
this.raf = new RequestAnimationFrame();
/**
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
@ -59,9 +58,6 @@ var Game = function (config)
*/
this.device = Device;
// Move this somewhere else? Math perhaps? Doesn't need to be a Game level system.
this.rnd;
// Wait for the DOM Ready event, then call boot.
DOMContentLoaded(this.boot.bind(this));
@ -79,9 +75,6 @@ Game.prototype = {
this.config.preBoot();
// Probably move within Math
this.rnd = new RandomDataGenerator(this.config.seed);
DebugHeader(this);
CreateRenderer(this);
@ -94,13 +87,7 @@ Game.prototype = {
this.config.postBoot();
this.raf.start();
},
// timestamp = DOMHighResTimeStamp
update: function (timestamp)
{
this.state.step(timestamp);
this.raf.start(this.state.step.bind(this.state), this.config.forceSetTimeOut);
}
};

View file

@ -23,8 +23,6 @@ var Transform = function (gameObject, x, y, scaleX, scaleY)
this.state = (gameObject.state) ? gameObject.state : gameObject.parent.state;
this.game = this.state.game;
// a = scale X
// b = shear Y
// c = shear X

View file

@ -4,27 +4,25 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var NOOP = require('../utils/NOOP');
/**
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
*
* @class Phaser.RequestAnimationFrame
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {boolean} [forceSetTimeOut=false] - Tell Phaser to use setTimeOut even if raf is available.
*/
function RequestAnimationFrame (game)
var RequestAnimationFrame = function ()
{
/**
* @property {Phaser.Game} game - The currently running game.
*/
this.game = game;
/**
* @property {boolean} isRunning - true if RequestAnimationFrame is running, otherwise false.
* @default
*/
this.isRunning = false;
this.callback = NOOP;
this.tick = 0;
/**
@ -46,45 +44,50 @@ function RequestAnimationFrame (game)
_this.timeOutID = window.requestAnimationFrame(step);
_this.game.update(timestamp);
_this.callback(timestamp);
};
var stepTimeout = function ()
{
_this.tick = Date.now();
var d = Date.now();
// _this.game.update(_this.tick);
_this.tick = d;
// _this.timeOutID = window.setTimeout(stepTimeout, _this.game.time.timeToCall);
_this.timeOutID = window.setTimeout(stepTimeout, _this.timeToCall);
_this.callback(d);
};
this.step = step;
this.stepTimeout = stepTimeout;
};
RequestAnimationFrame.prototype.constructor = RequestAnimationFrame;
RequestAnimationFrame.prototype = {
/**
* Starts the requestAnimationFrame running or setTimeout if unavailable in browser
* @method Phaser.RequestAnimationFrame#start
*/
this.start = function ()
start: function (callback, forceSetTimeOut)
{
this.callback = callback;
this.isSetTimeOut = forceSetTimeOut;
this.isRunning = true;
if (this.game.config.forceSetTimeOut)
{
this.isSetTimeOut = true;
var _this = this;
this.timeOutID = window.setTimeout(stepTimeout, 0);
}
else
{
this.isSetTimeOut = false;
this.timeOutID = window.requestAnimationFrame(step);
}
};
this.timeOutID = (forceSetTimeOut) ? window.setTimeout(_this.stepTimeout, 0) : window.requestAnimationFrame(_this.step);
},
/**
* Stops the requestAnimationFrame from running.
* @method Phaser.RequestAnimationFrame#stop
*/
this.stop = function ()
stop: function ()
{
this.isRunning = false;
@ -96,17 +99,15 @@ function RequestAnimationFrame (game)
{
window.cancelAnimationFrame(this.timeOutID);
}
};
},
this.destroy = function ()
destroy: function ()
{
this.stop();
this.game = undefined;
};
this.callback = NOOP;
}
}
RequestAnimationFrame.prototype.constructor = RequestAnimationFrame;
};
module.exports = RequestAnimationFrame;

View file

@ -73,6 +73,8 @@ WebGLRenderer.prototype = {
init: function ()
{
console.log('WebGLRenderer.init');
this.gl = this.view.getContext('webgl', this.config.WebGLContextOptions) || this.view.getContext('experimental-webgl', this.config.WebGLContextOptions);
if (!this.gl)

View file

@ -450,6 +450,7 @@ StateManager.prototype = {
// See if we can reduce this down to just update and render
// timestamp = DOMHighResTimeStamp
step: function (timestamp)
{
for (var i = 0; i < this.active.length; i++)