2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
var CameraManager = require('../plugins/CameraManager');
|
2017-07-04 12:58:45 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-06-28 16:17:54 +00:00
|
|
|
var Clock = require('../time/Clock');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Data = require('../plugins/Data');
|
2017-07-04 12:58:45 +00:00
|
|
|
var DisplayList = require('../plugins/DisplayList');
|
|
|
|
var EventDispatcher = require('../events/EventDispatcher');
|
2017-07-04 00:59:31 +00:00
|
|
|
var GameObjectCreator = require('../plugins/GameObjectCreator');
|
|
|
|
var GameObjectFactory = require('../plugins/GameObjectFactory');
|
2017-07-13 14:48:51 +00:00
|
|
|
var InputManager = require('../plugins/InputManager');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Loader = require('../plugins/Loader');
|
2017-07-05 16:17:50 +00:00
|
|
|
var PoolManager = require('../plugins/PoolManager');
|
2017-01-25 17:10:19 +00:00
|
|
|
var Settings = require('./Settings');
|
2017-03-23 19:51:02 +00:00
|
|
|
var StableSort = require('../utils/array/StableSort');
|
2017-07-14 13:30:20 +00:00
|
|
|
var SceneManager = require('../plugins/SceneManager');
|
2017-05-09 19:24:39 +00:00
|
|
|
var TweenManager = require('../tween/TweenManager');
|
2017-07-04 15:44:16 +00:00
|
|
|
var UpdateList = require('../plugins/UpdateList');
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
var Systems = new Class({
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
initialize:
|
2016-12-06 16:49:29 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function Systems (scene, config)
|
2017-07-04 12:58:45 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene = scene;
|
2017-07-04 12:58:45 +00:00
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
this.settings = Settings.create(config);
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.sortChildrenFlag = false;
|
2017-02-07 18:44:26 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Set by the GlobalSceneManager
|
2017-07-04 12:58:45 +00:00
|
|
|
this.mask = null;
|
|
|
|
this.canvas;
|
|
|
|
this.context;
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
// CORE (GLOBAL) SYSTEMS / PROPERTIES
|
2017-01-25 17:10:19 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.game;
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.anims;
|
|
|
|
this.cache;
|
|
|
|
this.registry;
|
|
|
|
this.textures;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Reference to Scene specific managers (Factory, Tweens, Loader, Physics, etc)
|
2017-07-04 12:58:45 +00:00
|
|
|
this.add;
|
|
|
|
this.cameras;
|
|
|
|
this.events;
|
2017-07-13 14:48:51 +00:00
|
|
|
this.inputManager;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.load;
|
|
|
|
this.make;
|
2017-07-05 16:17:50 +00:00
|
|
|
this.pool;
|
2017-07-14 13:30:20 +00:00
|
|
|
this.sceneManager;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.time;
|
|
|
|
this.tweens;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Scene properties
|
2017-07-04 15:44:16 +00:00
|
|
|
this.updateList;
|
|
|
|
this.displayList;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.data;
|
|
|
|
},
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
init: function (game)
|
2016-11-29 15:25:14 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
var scene = this.scene;
|
2017-07-04 00:59:31 +00:00
|
|
|
|
2017-01-25 17:10:19 +00:00
|
|
|
this.game = game;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-06-29 16:02:08 +00:00
|
|
|
// Game (Global) level managers
|
2017-02-12 13:19:55 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
this.anims = game.anims;
|
|
|
|
this.cache = game.cache;
|
|
|
|
this.registry = game.registry;
|
|
|
|
this.textures = game.textures;
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Scene specific properties (transform, data, children, etc)
|
2017-01-25 17:10:19 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.inputManager = new InputManager(scene, game);
|
|
|
|
this.updateList = new UpdateList(scene);
|
|
|
|
this.displayList = new DisplayList(scene);
|
|
|
|
this.data = new Data(scene);
|
2017-02-08 01:07:01 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// Scene specific managers (Factory, Tweens, Loader, Physics, etc)
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.add = new GameObjectFactory(scene);
|
|
|
|
this.cameras = new CameraManager(scene);
|
2017-04-04 22:59:02 +00:00
|
|
|
this.events = new EventDispatcher();
|
2017-07-14 13:30:20 +00:00
|
|
|
this.load = new Loader(scene);
|
|
|
|
this.make = new GameObjectCreator(scene);
|
|
|
|
this.pool = new PoolManager(scene);
|
|
|
|
this.sceneManager = new SceneManager(scene, game);
|
|
|
|
this.time = new Clock(scene);
|
|
|
|
this.tweens = new TweenManager(scene);
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2017-07-13 23:37:54 +00:00
|
|
|
// Sometimes the managers need access to a system created after them
|
|
|
|
this.inputManager.boot();
|
|
|
|
|
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 ()
|
|
|
|
{
|
2017-06-29 23:32:18 +00:00
|
|
|
var map = this.settings.map;
|
|
|
|
|
|
|
|
for (var key in map)
|
|
|
|
{
|
|
|
|
if (key === 'sys')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene[map[key]] = this[key];
|
2017-06-29 23:32:18 +00:00
|
|
|
}
|
2016-11-29 15:25:14 +00:00
|
|
|
},
|
|
|
|
|
2017-04-27 16:03:19 +00:00
|
|
|
step: function (time, delta)
|
2017-04-27 02:11:56 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Are there any pending SceneManager actions?
|
|
|
|
this.sceneManager.update();
|
2017-06-30 03:09:19 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
if (!this.settings.active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-05 16:17:50 +00:00
|
|
|
this.pool.begin(time);
|
|
|
|
this.updateList.begin(time);
|
2017-06-28 16:17:54 +00:00
|
|
|
this.time.begin(time);
|
2017-05-17 03:37:30 +00:00
|
|
|
this.tweens.begin(time);
|
2017-07-13 16:21:37 +00:00
|
|
|
this.inputManager.begin(time);
|
2017-05-09 19:24:39 +00:00
|
|
|
|
2017-07-05 16:17:50 +00:00
|
|
|
this.pool.update(time, delta);
|
2017-07-04 15:44:16 +00:00
|
|
|
this.updateList.update(time, delta);
|
2017-06-28 16:17:54 +00:00
|
|
|
this.time.update(time, delta);
|
2017-05-17 03:37:30 +00:00
|
|
|
this.tweens.update(time, delta);
|
2017-04-27 16:03:19 +00:00
|
|
|
this.cameras.update(time, delta);
|
2017-07-13 16:21:37 +00:00
|
|
|
this.inputManager.update(time, delta);
|
2017-04-27 02:11:56 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.update.call(this.scene, time, delta);
|
2017-04-27 02:11:56 +00:00
|
|
|
},
|
|
|
|
|
2017-01-26 04:06:10 +00:00
|
|
|
render: function (interpolation, renderer)
|
2017-01-30 23:58:29 +00:00
|
|
|
{
|
2017-02-08 01:07:01 +00:00
|
|
|
if (!this.settings.visible)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-04 22:59:02 +00:00
|
|
|
if (this.sortChildrenFlag)
|
|
|
|
{
|
2017-07-04 22:43:13 +00:00
|
|
|
StableSort.inplace(this.displayList.list, this.sortZ);
|
2017-04-04 22:59:02 +00:00
|
|
|
|
|
|
|
this.sortChildrenFlag = false;
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:43:13 +00:00
|
|
|
this.cameras.render(renderer, this.displayList, interpolation);
|
2017-04-04 22:59:02 +00:00
|
|
|
},
|
|
|
|
|
2017-07-07 17:13:26 +00:00
|
|
|
// Force a sort of the display list next render
|
|
|
|
depthSort: function ()
|
|
|
|
{
|
|
|
|
this.sortChildrenFlag = true;
|
|
|
|
},
|
|
|
|
|
2017-04-04 22:59:02 +00:00
|
|
|
sortZ: function (childA, childB)
|
|
|
|
{
|
|
|
|
return childA._z - childB._z;
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
|
2017-06-30 02:31:31 +00:00
|
|
|
pause: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was paused by the GlobalSceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = false;
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.pause)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.pause.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resume: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was resumed by the GlobalSceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.resume)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.resume.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sleep: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was sent to sleep by the GlobalSceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = false;
|
|
|
|
this.settings.visible = false;
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.sleep)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.sleep.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
wake: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was woken up by the GlobalSceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
this.settings.visible = true;
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.wake)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.wake.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function (data)
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was started by the GlobalSceneManager
|
2017-06-30 03:06:53 +00:00
|
|
|
|
|
|
|
this.settings.data = data;
|
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
this.settings.visible = true;
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
// Was stopped by the GlobalSceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = false;
|
2017-06-30 03:06:53 +00:00
|
|
|
this.settings.visible = false;
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2017-07-05 16:17:50 +00:00
|
|
|
this.pool.shutdown();
|
2017-07-04 22:43:13 +00:00
|
|
|
this.displayList.shutdown();
|
|
|
|
this.updateList.shutdown();
|
2017-06-30 02:31:31 +00:00
|
|
|
this.time.shutdown();
|
|
|
|
this.tweens.shutdown();
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.shutdown)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.shutdown.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Game level nuke
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
2017-07-05 16:17:50 +00:00
|
|
|
this.pool.destroy();
|
2017-06-30 02:31:31 +00:00
|
|
|
this.time.destroy();
|
|
|
|
this.tweens.destroy();
|
|
|
|
|
|
|
|
// etc
|
2017-07-14 13:30:20 +00:00
|
|
|
if (this.scene.destroy)
|
2017-06-30 03:06:53 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.destroy.call(this.scene);
|
2017-06-30 03:06:53 +00:00
|
|
|
}
|
2017-02-08 00:08:09 +00:00
|
|
|
}
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
});
|
2017-06-30 02:31:31 +00:00
|
|
|
|
2016-11-29 15:25:14 +00:00
|
|
|
module.exports = Systems;
|