2018-01-16 19:49:13 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-01-18 05:20:57 +00:00
|
|
|
var CoreScenePlugins = require('../CoreScenePlugins');
|
|
|
|
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
|
|
|
|
var GetScenePlugins = require('./GetScenePlugins');
|
|
|
|
var GlobalPlugins = require('../GlobalPlugins');
|
2018-01-17 03:41:58 +00:00
|
|
|
var Settings = require('./Settings');
|
2018-01-10 16:29:37 +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
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
this.game;
|
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.config = config;
|
2018-01-12 17:09:09 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.settings = Settings.create(config);
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2018-01-16 22:28:29 +00:00
|
|
|
// Set by the SceneManager - a reference to the Scene canvas / context
|
2018-01-12 17:09:09 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.canvas;
|
|
|
|
this.context;
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2018-01-18 05:20:57 +00:00
|
|
|
// Global Systems - these are single-instance global managers that belong to Game
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.anims;
|
|
|
|
this.cache;
|
2018-01-18 16:48:25 +00:00
|
|
|
this.plugins;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.registry;
|
2018-01-11 14:48:43 +00:00
|
|
|
this.sound;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.textures;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2018-01-18 05:20:57 +00:00
|
|
|
// Core Plugins - these are non-optional Scene plugins, needed by lots of the other systems
|
2018-01-12 17:09:09 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.add;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.cameras;
|
2017-08-15 22:36:46 +00:00
|
|
|
this.displayList;
|
2017-07-04 12:58:45 +00:00
|
|
|
this.events;
|
2018-01-16 02:08:22 +00:00
|
|
|
this.make;
|
2018-01-18 05:20:57 +00:00
|
|
|
this.scenePlugin;
|
2018-01-12 17:09:09 +00:00
|
|
|
this.updateList;
|
2017-07-04 12:58:45 +00:00
|
|
|
},
|
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-01-25 17:10:19 +00:00
|
|
|
this.game = game;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2018-01-18 16:48:25 +00:00
|
|
|
var pluginManager = game.plugins;
|
2017-02-12 13:19:55 +00:00
|
|
|
|
2018-01-18 16:48:25 +00:00
|
|
|
this.plugins = pluginManager;
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2018-01-18 16:48:25 +00:00
|
|
|
pluginManager.installGlobal(this, GlobalPlugins);
|
2018-01-10 16:29:37 +00:00
|
|
|
|
2018-01-18 16:48:25 +00:00
|
|
|
pluginManager.installLocal(this, CoreScenePlugins);
|
|
|
|
|
|
|
|
pluginManager.installLocal(this, GetScenePlugins(this));
|
|
|
|
|
|
|
|
pluginManager.installLocal(this, GetPhysicsPlugins(this));
|
2018-01-16 02:08:22 +00:00
|
|
|
|
|
|
|
this.events.emit('boot', this);
|
2018-01-18 13:59:32 +00:00
|
|
|
|
|
|
|
this.settings.isBooted = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
install: function (plugin)
|
|
|
|
{
|
|
|
|
if (!Array.isArray(plugin))
|
|
|
|
{
|
|
|
|
plugin = [ plugin ];
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:48:25 +00:00
|
|
|
this.plugins.installLocal(this, plugin);
|
2018-01-16 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
2017-04-27 16:03:19 +00:00
|
|
|
step: function (time, delta)
|
2017-04-27 02:11:56 +00:00
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
this.events.emit('preupdate', time, delta);
|
2017-06-30 03:09:19 +00:00
|
|
|
|
2017-06-30 02:31:31 +00:00
|
|
|
if (!this.settings.active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('update', time, delta);
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.scene.update.call(this.scene, time, delta);
|
2017-11-08 17:18:10 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('postupdate', 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;
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:59:06 +00:00
|
|
|
var displayList = this.displayList;
|
2017-12-15 04:07:32 +00:00
|
|
|
|
2018-01-11 13:59:06 +00:00
|
|
|
displayList.process();
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2018-01-11 13:59:06 +00:00
|
|
|
this.cameras.render(renderer, displayList, interpolation);
|
2017-04-04 22:59:02 +00:00
|
|
|
},
|
|
|
|
|
2017-07-20 11:48:35 +00:00
|
|
|
// Force a sort of the display list on the next render
|
|
|
|
queueDepthSort: function ()
|
2017-07-07 17:13:26 +00:00
|
|
|
{
|
2018-01-11 13:59:06 +00:00
|
|
|
this.displayList.queueDepthSort();
|
2017-07-07 17:13:26 +00:00
|
|
|
},
|
|
|
|
|
2017-07-20 11:48:35 +00:00
|
|
|
// Immediately sorts the display list if the flag is set
|
|
|
|
depthSort: function ()
|
|
|
|
{
|
2018-01-11 13:59:06 +00:00
|
|
|
this.displayList.depthSort();
|
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 ()
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was paused by the SceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = false;
|
|
|
|
|
2018-01-17 03:41:58 +00:00
|
|
|
this.events.emit('pause', this);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resume: function ()
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was resumed by the SceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
|
2018-01-17 03:41:58 +00:00
|
|
|
this.events.emit('resume', this);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sleep: function ()
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was sent to sleep by the SceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = false;
|
|
|
|
this.settings.visible = false;
|
|
|
|
|
2018-01-17 03:41:58 +00:00
|
|
|
this.events.emit('sleep', this);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
wake: function ()
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was woken up by the SceneManager
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
this.settings.visible = true;
|
|
|
|
|
2018-01-17 03:41:58 +00:00
|
|
|
this.events.emit('wake', this);
|
2017-06-30 03:06:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
start: function (data)
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was started by the SceneManager
|
2017-06-30 03:06:53 +00:00
|
|
|
|
|
|
|
this.settings.data = data;
|
|
|
|
|
|
|
|
this.settings.active = true;
|
|
|
|
this.settings.visible = true;
|
2018-01-17 03:41:58 +00:00
|
|
|
|
|
|
|
this.events.emit('start', this);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
// Was stopped by the SceneManager
|
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
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('shutdown', this);
|
2017-06-30 02:31:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('destroy', this);
|
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;
|