forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystems.js
More file actions
263 lines (204 loc) · 6.08 KB
/
Copy pathSystems.js
File metadata and controls
263 lines (204 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
var CameraManager = require('../plugins/CameraManager');
var Class = require('../utils/Class');
var Clock = require('../time/Clock');
var Data = require('../plugins/Data');
var DisplayList = require('../plugins/DisplayList');
var EventDispatcher = require('../events/EventDispatcher');
var GameObjectCreator = require('../plugins/GameObjectCreator');
var GameObjectFactory = require('../plugins/GameObjectFactory');
var Loader = require('../plugins/Loader');
var PoolManager = require('../plugins/PoolManager');
var Settings = require('./Settings');
var StableSort = require('../utils/array/StableSort');
var StateManager = require('../plugins/StateManager');
var TweenManager = require('../tween/TweenManager');
var UpdateList = require('../plugins/UpdateList');
var Systems = new Class({
initialize:
function Systems (state, config)
{
this.state = state;
this.config = config;
this.settings = Settings.create(config);
this.sortChildrenFlag = false;
// Set by the GlobalStateManager
this.mask = null;
this.canvas;
this.context;
// CORE (GLOBAL) SYSTEMS / PROPERTIES
this.game;
this.anims;
this.cache;
this.input;
this.registry;
this.textures;
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
this.add;
this.cameras;
this.events;
this.load;
this.make;
this.pool;
this.stateManager;
this.time;
this.tweens;
// State properties
this.updateList;
this.displayList;
this.data;
},
init: function (game)
{
var state = this.state;
this.game = game;
// Game (Global) level managers
this.anims = game.anims;
this.cache = game.cache;
this.input = game.input;
this.registry = game.registry;
this.textures = game.textures;
// State specific properties (transform, data, children, etc)
this.updateList = new UpdateList(state);
this.displayList = new DisplayList(state);
this.data = new Data(state);
// State specific managers (Factory, Tweens, Loader, Physics, etc)
this.add = new GameObjectFactory(state);
this.cameras = new CameraManager(state);
this.events = new EventDispatcher();
this.load = new Loader(state);
this.make = new GameObjectCreator(state);
this.pool = new PoolManager(state);
this.stateManager = new StateManager(state, game);
this.time = new Clock(state);
this.tweens = new TweenManager(state);
this.inject();
},
inject: function ()
{
var map = this.settings.map;
for (var key in map)
{
if (key === 'sys')
{
continue;
}
this.state[map[key]] = this[key];
}
},
step: function (time, delta)
{
// Are there any pending StateManager actions?
this.stateManager.update();
if (!this.settings.active)
{
return;
}
this.pool.begin(time);
this.updateList.begin(time);
this.time.begin(time);
this.tweens.begin(time);
this.pool.update(time, delta);
this.updateList.update(time, delta);
this.time.update(time, delta);
this.tweens.update(time, delta);
this.cameras.update(time, delta);
this.state.update.call(this.state, time, delta);
},
render: function (interpolation, renderer)
{
if (!this.settings.visible)
{
return;
}
if (this.sortChildrenFlag)
{
StableSort.inplace(this.displayList.list, this.sortZ);
this.sortChildrenFlag = false;
}
this.cameras.render(renderer, this.displayList, interpolation);
},
// Force a sort of the display list next render
depthSort: function ()
{
this.sortChildrenFlag = true;
},
sortZ: function (childA, childB)
{
return childA._z - childB._z;
},
// A paused State still renders, it just doesn't run ANY of its update handlers or systems
pause: function ()
{
// Was paused by the GlobalStateManager
this.settings.active = false;
if (this.state.pause)
{
this.state.pause.call(this.state);
}
},
resume: function ()
{
// Was resumed by the GlobalStateManager
this.settings.active = true;
if (this.state.resume)
{
this.state.resume.call(this.state);
}
},
sleep: function ()
{
// Was sent to sleep by the GlobalStateManager
this.settings.active = false;
this.settings.visible = false;
if (this.state.sleep)
{
this.state.sleep.call(this.state);
}
},
wake: function ()
{
// Was woken up by the GlobalStateManager
this.settings.active = true;
this.settings.visible = true;
if (this.state.wake)
{
this.state.wake.call(this.state);
}
},
start: function (data)
{
// Was started by the GlobalStateManager
this.settings.data = data;
this.settings.active = true;
this.settings.visible = true;
},
shutdown: function ()
{
// Was stopped by the GlobalStateManager
this.settings.active = false;
this.settings.visible = false;
this.pool.shutdown();
this.displayList.shutdown();
this.updateList.shutdown();
this.time.shutdown();
this.tweens.shutdown();
if (this.state.shutdown)
{
this.state.shutdown.call(this.state);
}
},
// Game level nuke
destroy: function ()
{
// TODO
this.pool.destroy();
this.time.destroy();
this.tweens.destroy();
// etc
if (this.state.destroy)
{
this.state.destroy.call(this.state);
}
}
});
module.exports = Systems;