mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
RAF now calls StateManager.step directly.
Game no longer has RNG property.
This commit is contained in:
parent
5f2d4473f3
commit
5c495bbdf8
6 changed files with 39 additions and 52 deletions
|
@ -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:
|
Every time RAF ticks it calls the following:
|
||||||
|
|
||||||
1. Calls `Game.update`, which ...
|
1. --removed--
|
||||||
2. Calls `StateManager.step`, which ...
|
2. Calls `StateManager.step`, which ...
|
||||||
3. Iterates through all _active_ States, and ...
|
3. Iterates through all _active_ States, and ...
|
||||||
4. Calls `State.sys.mainloop.step`, which ...
|
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:
|
In a tree form it maps to the following:
|
||||||
|
|
||||||
```
|
```
|
||||||
+ Game.update
|
|
||||||
|
|
|
||||||
+ StateManager.step (iterates all active States)
|
+ StateManager.step (iterates all active States)
|
||||||
|
|
|
|
||||||
+- State.sys.mainloop.step (updates delta values)
|
+- State.sys.mainloop.step (updates delta values)
|
||||||
|
|
|
@ -13,7 +13,6 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
|
||||||
var DOMContentLoaded = require('../dom/DOMContentLoaded');
|
var DOMContentLoaded = require('../dom/DOMContentLoaded');
|
||||||
|
|
||||||
var CreateRenderer = require('./CreateRenderer');
|
var CreateRenderer = require('./CreateRenderer');
|
||||||
var RandomDataGenerator = require('../math/random-data-generator/RandomDataGenerator');
|
|
||||||
var StateManager = require('../state/StateManager');
|
var StateManager = require('../state/StateManager');
|
||||||
var TextureManager = require('../textures/TextureManager');
|
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
|
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
this.raf = new RequestAnimationFrame(this);
|
this.raf = new RequestAnimationFrame();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
|
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
|
||||||
|
@ -59,9 +58,6 @@ var Game = function (config)
|
||||||
*/
|
*/
|
||||||
this.device = Device;
|
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.
|
// Wait for the DOM Ready event, then call boot.
|
||||||
DOMContentLoaded(this.boot.bind(this));
|
DOMContentLoaded(this.boot.bind(this));
|
||||||
|
|
||||||
|
@ -79,9 +75,6 @@ Game.prototype = {
|
||||||
|
|
||||||
this.config.preBoot();
|
this.config.preBoot();
|
||||||
|
|
||||||
// Probably move within Math
|
|
||||||
this.rnd = new RandomDataGenerator(this.config.seed);
|
|
||||||
|
|
||||||
DebugHeader(this);
|
DebugHeader(this);
|
||||||
|
|
||||||
CreateRenderer(this);
|
CreateRenderer(this);
|
||||||
|
@ -94,13 +87,7 @@ Game.prototype = {
|
||||||
|
|
||||||
this.config.postBoot();
|
this.config.postBoot();
|
||||||
|
|
||||||
this.raf.start();
|
this.raf.start(this.state.step.bind(this.state), this.config.forceSetTimeOut);
|
||||||
},
|
|
||||||
|
|
||||||
// timestamp = DOMHighResTimeStamp
|
|
||||||
update: function (timestamp)
|
|
||||||
{
|
|
||||||
this.state.step(timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,8 +23,6 @@ var Transform = function (gameObject, x, y, scaleX, scaleY)
|
||||||
|
|
||||||
this.state = (gameObject.state) ? gameObject.state : gameObject.parent.state;
|
this.state = (gameObject.state) ? gameObject.state : gameObject.parent.state;
|
||||||
|
|
||||||
this.game = this.state.game;
|
|
||||||
|
|
||||||
// a = scale X
|
// a = scale X
|
||||||
// b = shear Y
|
// b = shear Y
|
||||||
// c = shear X
|
// c = shear X
|
||||||
|
|
|
@ -4,27 +4,25 @@
|
||||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
* @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.
|
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
|
||||||
*
|
*
|
||||||
* @class Phaser.RequestAnimationFrame
|
* @class Phaser.RequestAnimationFrame
|
||||||
* @constructor
|
* @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.
|
* @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.
|
* @property {boolean} isRunning - true if RequestAnimationFrame is running, otherwise false.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
|
this.callback = NOOP;
|
||||||
|
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,45 +44,50 @@ function RequestAnimationFrame (game)
|
||||||
|
|
||||||
_this.timeOutID = window.requestAnimationFrame(step);
|
_this.timeOutID = window.requestAnimationFrame(step);
|
||||||
|
|
||||||
_this.game.update(timestamp);
|
_this.callback(timestamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
var stepTimeout = function ()
|
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
|
* Starts the requestAnimationFrame running or setTimeout if unavailable in browser
|
||||||
* @method Phaser.RequestAnimationFrame#start
|
* @method Phaser.RequestAnimationFrame#start
|
||||||
*/
|
*/
|
||||||
this.start = function ()
|
start: function (callback, forceSetTimeOut)
|
||||||
{
|
{
|
||||||
|
this.callback = callback;
|
||||||
|
|
||||||
|
this.isSetTimeOut = forceSetTimeOut;
|
||||||
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
|
|
||||||
if (this.game.config.forceSetTimeOut)
|
var _this = this;
|
||||||
{
|
|
||||||
this.isSetTimeOut = true;
|
|
||||||
|
|
||||||
this.timeOutID = window.setTimeout(stepTimeout, 0);
|
this.timeOutID = (forceSetTimeOut) ? window.setTimeout(_this.stepTimeout, 0) : window.requestAnimationFrame(_this.step);
|
||||||
}
|
},
|
||||||
else
|
|
||||||
{
|
|
||||||
this.isSetTimeOut = false;
|
|
||||||
|
|
||||||
this.timeOutID = window.requestAnimationFrame(step);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the requestAnimationFrame from running.
|
* Stops the requestAnimationFrame from running.
|
||||||
* @method Phaser.RequestAnimationFrame#stop
|
* @method Phaser.RequestAnimationFrame#stop
|
||||||
*/
|
*/
|
||||||
this.stop = function ()
|
stop: function ()
|
||||||
{
|
{
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
|
@ -96,17 +99,15 @@ function RequestAnimationFrame (game)
|
||||||
{
|
{
|
||||||
window.cancelAnimationFrame(this.timeOutID);
|
window.cancelAnimationFrame(this.timeOutID);
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
|
||||||
this.destroy = function ()
|
destroy: function ()
|
||||||
{
|
{
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
this.game = undefined;
|
this.callback = NOOP;
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
RequestAnimationFrame.prototype.constructor = RequestAnimationFrame;
|
|
||||||
|
|
||||||
module.exports = RequestAnimationFrame;
|
module.exports = RequestAnimationFrame;
|
||||||
|
|
|
@ -73,6 +73,8 @@ WebGLRenderer.prototype = {
|
||||||
|
|
||||||
init: function ()
|
init: function ()
|
||||||
{
|
{
|
||||||
|
console.log('WebGLRenderer.init');
|
||||||
|
|
||||||
this.gl = this.view.getContext('webgl', this.config.WebGLContextOptions) || this.view.getContext('experimental-webgl', this.config.WebGLContextOptions);
|
this.gl = this.view.getContext('webgl', this.config.WebGLContextOptions) || this.view.getContext('experimental-webgl', this.config.WebGLContextOptions);
|
||||||
|
|
||||||
if (!this.gl)
|
if (!this.gl)
|
||||||
|
|
|
@ -450,6 +450,7 @@ StateManager.prototype = {
|
||||||
|
|
||||||
// See if we can reduce this down to just update and render
|
// See if we can reduce this down to just update and render
|
||||||
|
|
||||||
|
// timestamp = DOMHighResTimeStamp
|
||||||
step: function (timestamp)
|
step: function (timestamp)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < this.active.length; i++)
|
for (var i = 0; i < this.active.length; i++)
|
||||||
|
|
Loading…
Reference in a new issue