2018-01-16 15:06:47 +00:00
|
|
|
// var CameraManager = require('../../camera/local/CameraManager');
|
2017-08-18 00:42:14 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Clock = require('../../time/Clock');
|
2018-01-10 16:29:37 +00:00
|
|
|
var Data = require('../../data/Data');
|
|
|
|
var DataStore = require('../../data/DataStore');
|
2017-07-04 12:58:45 +00:00
|
|
|
var DisplayList = require('../plugins/DisplayList');
|
2018-01-12 17:09:09 +00:00
|
|
|
var EventEmitter = require('eventemitter3');
|
2017-07-04 00:59:31 +00:00
|
|
|
var GameObjectCreator = require('../plugins/GameObjectCreator');
|
|
|
|
var GameObjectFactory = require('../plugins/GameObjectFactory');
|
2018-01-16 16:14:21 +00:00
|
|
|
var InputManager = require('../../input/InputPlugin');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Loader = require('../plugins/Loader');
|
2017-08-15 22:36:46 +00:00
|
|
|
var PhysicsManager = require('../plugins/PhysicsManager');
|
|
|
|
var SceneManager = require('../plugins/SceneManager');
|
2017-01-25 17:10:19 +00:00
|
|
|
var Settings = require('./Settings');
|
2017-10-12 14:14:34 +00:00
|
|
|
var TweenManager = require('../../tweens/manager/TweenManager');
|
2017-07-04 15:44:16 +00:00
|
|
|
var UpdateList = require('../plugins/UpdateList');
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
var TestPlugin = require('../../plugins/TestPlugin');
|
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 02:08:22 +00:00
|
|
|
// Set by the GlobalSceneManager - 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-12 17:09:09 +00:00
|
|
|
// Global Systems - these are global managers (belonging to Game)
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2017-07-04 12:58:45 +00:00
|
|
|
this.anims;
|
|
|
|
this.cache;
|
|
|
|
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-12 17:09:09 +00:00
|
|
|
// These are core Scene plugins, needed by lots of the global systems (and each other)
|
|
|
|
|
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-12 17:09:09 +00:00
|
|
|
this.sceneManager;
|
|
|
|
this.time;
|
|
|
|
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-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
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
// Global Systems - these are global managers (belonging to Game)
|
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;
|
2018-01-11 14:48:43 +00:00
|
|
|
this.sound = game.sound;
|
2017-07-04 00:59:31 +00:00
|
|
|
this.textures = game.textures;
|
2017-01-26 04:06:10 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
// These are core Scene plugins, needed by lots of the global systems (and each other)
|
2018-01-10 16:29:37 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
this.events = new EventEmitter();
|
2018-01-16 02:08:22 +00:00
|
|
|
|
|
|
|
game.plugins.install(scene, [ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make' ]);
|
2018-01-12 17:09:09 +00:00
|
|
|
|
|
|
|
// Optional Scene plugins - not referenced by core systems, can be overridden with user code
|
2017-04-04 22:59:02 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
// game.plugins.install(scene, [ , 'test' ]);
|
|
|
|
|
2017-09-08 01:41:00 +00:00
|
|
|
this.data = new Data(scene);
|
2017-09-08 00:59:53 +00:00
|
|
|
this.dataStore = new DataStore(scene);
|
2017-08-15 22:36:46 +00:00
|
|
|
this.inputManager = new InputManager(scene);
|
2017-07-14 13:30:20 +00:00
|
|
|
this.load = new Loader(scene);
|
2017-08-15 22:36:46 +00:00
|
|
|
this.physicsManager = new PhysicsManager(scene);
|
2017-07-14 13:30:20 +00:00
|
|
|
this.tweens = new TweenManager(scene);
|
2018-01-12 17:09:09 +00:00
|
|
|
|
2017-07-13 23:37:54 +00:00
|
|
|
// Sometimes the managers need access to a system created after them
|
2018-01-16 02:08:22 +00:00
|
|
|
|
|
|
|
this.events.emit('boot', this);
|
|
|
|
|
2017-07-13 23:37:54 +00:00
|
|
|
this.inputManager.boot();
|
2017-08-15 22:36:46 +00:00
|
|
|
this.physicsManager.boot();
|
2017-07-13 23:37:54 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.inject2();
|
|
|
|
},
|
|
|
|
|
|
|
|
inject: function (plugin)
|
|
|
|
{
|
|
|
|
var map = this.settings.map;
|
|
|
|
|
|
|
|
if (plugin.mapping && map.hasOwnProperty(plugin.mapping))
|
|
|
|
{
|
|
|
|
this.scene[plugin.mapping] = plugin;
|
|
|
|
}
|
2017-01-25 17:10:19 +00:00
|
|
|
},
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
inject2: function ()
|
2017-01-25 17:10:19 +00:00
|
|
|
{
|
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?
|
2018-01-16 02:08:22 +00:00
|
|
|
// This plugin is a special case, as it can literally modify this Scene, so we update it directly.
|
2017-07-14 13:30:20 +00:00
|
|
|
this.sceneManager.update();
|
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('preupdate', time, delta);
|
2017-09-26 01:17:31 +00:00
|
|
|
|
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
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('update', time, delta);
|
|
|
|
|
2017-08-15 22:36:46 +00:00
|
|
|
this.physicsManager.update(time, delta);
|
|
|
|
|
2017-05-17 03:37:30 +00:00
|
|
|
this.tweens.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-11-08 17:18:10 +00:00
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('postupdate', time, delta);
|
|
|
|
|
2017-11-08 17:18:10 +00:00
|
|
|
this.physicsManager.postUpdate();
|
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 ()
|
|
|
|
{
|
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
|
|
|
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('shutdown', this);
|
|
|
|
|
|
|
|
// this.displayList.shutdown();
|
|
|
|
// this.updateList.shutdown();
|
|
|
|
// this.time.shutdown();
|
2017-06-30 02:31:31 +00:00
|
|
|
this.tweens.shutdown();
|
2017-11-29 23:36:35 +00:00
|
|
|
this.physicsManager.shutdown();
|
2017-06-30 02:31:31 +00:00
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2017-11-29 23:36:35 +00:00
|
|
|
// TODO: Game level nuke
|
2017-06-30 02:31:31 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-01-16 02:08:22 +00:00
|
|
|
this.events.emit('destroy', this);
|
|
|
|
|
2017-09-14 00:32:10 +00:00
|
|
|
this.add.destroy();
|
2018-01-16 02:08:22 +00:00
|
|
|
// this.time.destroy();
|
2017-06-30 02:31:31 +00:00
|
|
|
this.tweens.destroy();
|
2017-11-29 23:36:35 +00:00
|
|
|
this.physicsManager.destroy();
|
2017-06-30 02:31:31 +00:00
|
|
|
|
|
|
|
// 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;
|