2016-11-29 15:25:14 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
var EventDispatcher = require('../events/EventDispatcher');
|
2016-11-29 15:25:14 +00:00
|
|
|
var GameObjectFactory = require('./systems/GameObjectFactory');
|
2017-01-25 17:10:19 +00:00
|
|
|
var GameObjectCreator = require('./systems/GameObjectCreator');
|
2016-11-30 17:16:45 +00:00
|
|
|
var Loader = require('./systems/Loader');
|
2016-11-29 15:25:14 +00:00
|
|
|
var UpdateManager = require('./systems/UpdateManager');
|
2016-12-07 02:40:07 +00:00
|
|
|
var Component = require('../components');
|
2017-01-30 23:58:29 +00:00
|
|
|
// var Camera = require('../camera/Camera');
|
2017-01-25 17:10:19 +00:00
|
|
|
var Settings = require('./Settings');
|
2017-01-26 04:06:10 +00:00
|
|
|
var RTree = require('../structs/RTree');
|
2017-02-07 15:47:27 +00:00
|
|
|
var Camera = require('../camera/Camera-2')
|
2016-11-29 15:25:14 +00:00
|
|
|
|
|
|
|
var Systems = function (state, config)
|
|
|
|
{
|
|
|
|
this.state = state;
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
this.game = null;
|
|
|
|
|
2016-11-29 15:25:14 +00:00
|
|
|
this.config = config;
|
|
|
|
|
2017-02-06 23:59:15 +00:00
|
|
|
this.settings = Settings.create(config);
|
2016-12-06 16:49:29 +00:00
|
|
|
|
2017-02-07 18:44:26 +00:00
|
|
|
this.x = this.settings.x;
|
|
|
|
this.y = this.settings.y;
|
|
|
|
|
|
|
|
this.mask = null;
|
|
|
|
this.canvas;
|
|
|
|
this.context;
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
// CORE SYSTEMS / PROPERTIES
|
|
|
|
|
2017-01-30 16:56:04 +00:00
|
|
|
this.cache;
|
2017-01-26 04:06:10 +00:00
|
|
|
this.textures;
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
|
2016-11-29 15:25:14 +00:00
|
|
|
this.add;
|
|
|
|
this.make;
|
|
|
|
this.load;
|
2017-01-25 17:10:19 +00:00
|
|
|
this.events;
|
2016-11-29 15:25:14 +00:00
|
|
|
this.updates;
|
2017-01-26 04:06:10 +00:00
|
|
|
this.tree;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
// State properties
|
2017-02-07 18:44:26 +00:00
|
|
|
this.cameras;
|
2016-11-29 15:25:14 +00:00
|
|
|
this.children;
|
|
|
|
this.color;
|
|
|
|
this.data;
|
|
|
|
this.fbo;
|
|
|
|
this.time;
|
2017-01-30 23:58:29 +00:00
|
|
|
this.transform;
|
2016-11-29 15:25:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Systems.prototype.constructor = Systems;
|
|
|
|
|
|
|
|
Systems.prototype = {
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
init: function (game)
|
2016-11-29 15:25:14 +00:00
|
|
|
{
|
|
|
|
console.log('State.Systems.init');
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
this.game = game;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-02-06 23:59:15 +00:00
|
|
|
Settings.init(this.settings, this.game.config);
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2017-01-30 16:56:04 +00:00
|
|
|
this.cache = this.game.cache;
|
2017-01-26 04:06:10 +00:00
|
|
|
this.textures = this.game.textures;
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
// State specific managers (Factory, Tweens, Loader, Physics, etc)
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-26 04:06:10 +00:00
|
|
|
this.tree = RTree(16);
|
2017-01-25 17:10:19 +00:00
|
|
|
this.events = new EventDispatcher();
|
2016-11-29 15:25:14 +00:00
|
|
|
this.add = new GameObjectFactory(this.state);
|
2017-01-25 17:10:19 +00:00
|
|
|
this.make = GameObjectCreator(this.state);
|
2016-11-29 15:25:14 +00:00
|
|
|
this.updates = new UpdateManager(this.state);
|
2016-11-30 17:16:45 +00:00
|
|
|
this.load = new Loader(this.state);
|
2016-11-29 15:25:14 +00:00
|
|
|
|
|
|
|
// State specific properties (transform, data, children, etc)
|
2017-01-25 17:10:19 +00:00
|
|
|
|
2017-01-30 23:58:29 +00:00
|
|
|
// this.camera = new Camera(this.state, 0, 0, this.settings.width, this.settings.height);
|
2016-12-07 02:40:07 +00:00
|
|
|
this.children = new Component.Children(this.state);
|
|
|
|
this.color = new Component.Color(this.state);
|
|
|
|
this.data = new Component.Data(this.state);
|
2017-01-30 23:58:29 +00:00
|
|
|
this.transform = new Component.Transform(this.state);
|
2017-02-07 16:12:20 +00:00
|
|
|
this.cameras = [];
|
|
|
|
this.cameras[0] = new Camera(0, 0, this.game.config.width, this.game.config.height);
|
2017-01-25 17:10:19 +00:00
|
|
|
this.inject();
|
|
|
|
},
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
inject: function ()
|
|
|
|
{
|
|
|
|
// Defaults properties injected into the State
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-31 14:55:15 +00:00
|
|
|
this.state.game = this.game;
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
this.state.events = this.events;
|
2016-11-29 15:25:14 +00:00
|
|
|
this.state.add = this.add;
|
2016-11-30 17:16:45 +00:00
|
|
|
this.state.load = this.load;
|
2016-12-07 02:40:07 +00:00
|
|
|
this.state.children = this.children;
|
|
|
|
this.state.color = this.color;
|
|
|
|
this.state.data = this.data;
|
2017-01-26 04:06:10 +00:00
|
|
|
this.state.settings = this.settings;
|
2017-01-25 17:10:19 +00:00
|
|
|
|
2017-01-30 23:58:29 +00:00
|
|
|
// this.state.camera = this.camera;
|
2017-01-31 00:56:13 +00:00
|
|
|
this.state.transform = this.transform;
|
2017-01-26 04:06:10 +00:00
|
|
|
|
|
|
|
this.state.state = this.game.state;
|
2017-01-30 16:56:04 +00:00
|
|
|
this.state.cache = this.game.cache;
|
2017-01-26 04:06:10 +00:00
|
|
|
this.state.textures = this.game.textures;
|
2017-02-07 15:47:27 +00:00
|
|
|
|
2017-02-07 16:12:20 +00:00
|
|
|
for (var i = 0, l = this.cameras.length; i < l; ++i)
|
|
|
|
{
|
|
|
|
this.cameras[i].setState(this.state);
|
|
|
|
}
|
2016-11-29 15:25:14 +00:00
|
|
|
},
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
// Called just once per frame, regardless of speed
|
2016-11-29 15:25:14 +00:00
|
|
|
begin: function (timestamp, frameDelta)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
// Potentially called multiple times per frame (on super-fast systems)
|
2016-11-29 15:25:14 +00:00
|
|
|
update: function (timestep, physicsStep)
|
|
|
|
{
|
2017-01-25 17:10:19 +00:00
|
|
|
for (var c = 0; c < this.children.list.length; c++)
|
|
|
|
{
|
|
|
|
var child = this.children.list[c];
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-31 17:04:31 +00:00
|
|
|
// if (child.exists)
|
|
|
|
// {
|
2017-01-25 17:10:19 +00:00
|
|
|
child.update(timestep);
|
2017-01-31 17:04:31 +00:00
|
|
|
// }
|
2017-01-25 17:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.state.update(timestep, physicsStep);
|
2016-11-29 15:25:14 +00:00
|
|
|
},
|
|
|
|
|
2017-01-26 04:06:10 +00:00
|
|
|
render: function (interpolation, renderer)
|
2017-01-30 23:58:29 +00:00
|
|
|
{
|
2017-02-07 16:12:20 +00:00
|
|
|
var state = this.state;
|
2017-01-31 23:06:13 +00:00
|
|
|
var transform = this.transform;
|
2017-02-07 16:12:20 +00:00
|
|
|
var cameras = this.cameras;
|
|
|
|
for (var i = 0, l = cameras.length; i < l; ++i)
|
|
|
|
{
|
|
|
|
var camera = cameras[i];
|
|
|
|
camera.preRender();
|
|
|
|
state.camera = camera;
|
|
|
|
renderer.render(state, transform.flatRenderArray, interpolation, camera);
|
2017-02-07 18:44:26 +00:00
|
|
|
//state.render(interpolation);
|
2017-02-07 16:12:20 +00:00
|
|
|
camera.postRender();
|
|
|
|
}
|
2017-02-07 18:44:26 +00:00
|
|
|
}
|
2017-01-25 17:10:19 +00:00
|
|
|
|
|
|
|
|
2016-11-29 15:25:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Systems;
|