55 */
66
77var Class = require ( '../utils/Class' ) ;
8+ var ProcessQueue = require ( '../structs/ProcessQueue' ) ;
89var PluginCache = require ( '../plugins/PluginCache' ) ;
910var SceneEvents = require ( '../scene/events' ) ;
1011
@@ -17,6 +18,7 @@ var SceneEvents = require('../scene/events');
1718 * Some or all of these Game Objects may also be part of the Scene's [Display List]{@link Phaser.GameObjects.DisplayList}, for Rendering.
1819 *
1920 * @class UpdateList
21+ * @extends Phaser.Structs.ProcessQueue
2022 * @memberof Phaser.GameObjects
2123 * @constructor
2224 * @since 3.0.0
@@ -25,10 +27,14 @@ var SceneEvents = require('../scene/events');
2527 */
2628var UpdateList = new Class ( {
2729
30+ Extends : ProcessQueue ,
31+
2832 initialize :
2933
3034 function UpdateList ( scene )
3135 {
36+ ProcessQueue . call ( this ) ;
37+
3238 /**
3339 * The Scene that the Update List belongs to.
3440 *
@@ -47,38 +53,8 @@ var UpdateList = new Class({
4753 */
4854 this . systems = scene . sys ;
4955
50- /**
51- * The list of Game Objects.
52- *
53- * @name Phaser.GameObjects.UpdateList#_list
54- * @type {array }
55- * @private
56- * @default []
57- * @since 3.0.0
58- */
59- this . _list = [ ] ;
60-
61- /**
62- * Game Objects that are pending insertion into the list.
63- *
64- * @name Phaser.GameObjects.UpdateList#_pendingInsertion
65- * @type {array }
66- * @private
67- * @default []
68- * @since 3.0.0
69- */
70- this . _pendingInsertion = [ ] ;
71-
72- /**
73- * Game Objects that are pending removal from the list.
74- *
75- * @name Phaser.GameObjects.UpdateList#_pendingRemoval
76- * @type {array }
77- * @private
78- * @default []
79- * @since 3.0.0
80- */
81- this . _pendingRemoval = [ ] ;
56+ // this._addEvent = 'add';
57+ // this.removeEvent = 'remove';
8258
8359 scene . sys . events . once ( SceneEvents . BOOT , this . boot , this ) ;
8460 scene . sys . events . on ( SceneEvents . START , this . start , this ) ;
@@ -110,90 +86,25 @@ var UpdateList = new Class({
11086 {
11187 var eventEmitter = this . systems . events ;
11288
113- eventEmitter . on ( SceneEvents . PRE_UPDATE , this . preUpdate , this ) ;
114- eventEmitter . on ( SceneEvents . UPDATE , this . update , this ) ;
89+ eventEmitter . on ( SceneEvents . PRE_UPDATE , this . update , this ) ;
90+ eventEmitter . on ( SceneEvents . UPDATE , this . sceneUpdate , this ) ;
11591 eventEmitter . once ( SceneEvents . SHUTDOWN , this . shutdown , this ) ;
11692 } ,
11793
118- /**
119- * Add a Game Object to the Update List.
120- *
121- * @method Phaser.GameObjects.UpdateList#add
122- * @since 3.0.0
123- *
124- * @param {Phaser.GameObjects.GameObject } child - The Game Object to add.
125- *
126- * @return {Phaser.GameObjects.GameObject } The added Game Object.
127- */
128- add : function ( child )
129- {
130- // Is child already in this list?
131-
132- if ( this . _list . indexOf ( child ) === - 1 && this . _pendingInsertion . indexOf ( child ) === - 1 )
133- {
134- this . _pendingInsertion . push ( child ) ;
135- }
136-
137- return child ;
138- } ,
139-
140- /**
141- * The pre-update step.
142- *
143- * Handles Game Objects that are pending insertion to and removal from the list.
144- *
145- * @method Phaser.GameObjects.UpdateList#preUpdate
146- * @since 3.0.0
147- */
148- preUpdate : function ( )
149- {
150- var toRemove = this . _pendingRemoval . length ;
151- var toInsert = this . _pendingInsertion . length ;
152-
153- if ( toRemove === 0 && toInsert === 0 )
154- {
155- // Quick bail
156- return ;
157- }
158-
159- var i ;
160- var gameObject ;
161-
162- // Delete old gameObjects
163- for ( i = 0 ; i < toRemove ; i ++ )
164- {
165- gameObject = this . _pendingRemoval [ i ] ;
166-
167- var index = this . _list . indexOf ( gameObject ) ;
168-
169- if ( index > - 1 )
170- {
171- this . _list . splice ( index , 1 ) ;
172- }
173- }
174-
175- // Move pending to active
176- this . _list = this . _list . concat ( this . _pendingInsertion . splice ( 0 ) ) ;
177-
178- // Clear the lists
179- this . _pendingRemoval . length = 0 ;
180- this . _pendingInsertion . length = 0 ;
181- } ,
182-
18394 /**
18495 * The update step.
18596 *
18697 * Pre-updates every active Game Object in the list.
18798 *
188- * @method Phaser.GameObjects.UpdateList#update
189- * @since 3.0 .0
99+ * @method Phaser.GameObjects.UpdateList#sceneUpdate
100+ * @since 3.20 .0
190101 *
191102 * @param {number } time - The current timestamp.
192103 * @param {number } delta - The delta time elapsed since the last frame.
193104 */
194- update : function ( time , delta )
105+ sceneUpdate : function ( time , delta )
195106 {
196- var list = this . _list ;
107+ var list = this . _active ;
197108 var length = list . length ;
198109
199110 for ( var i = 0 ; i < length ; i ++ )
@@ -207,79 +118,42 @@ var UpdateList = new Class({
207118 }
208119 } ,
209120
210- /**
211- * Remove a Game Object from the list.
212- *
213- * @method Phaser.GameObjects.UpdateList#remove
214- * @since 3.0.0
215- *
216- * @param {Phaser.GameObjects.GameObject } child - The Game Object to remove from the list.
217- *
218- * @return {Phaser.GameObjects.GameObject } The removed Game Object.
219- */
220- remove : function ( child )
221- {
222- if ( this . _list . indexOf ( child ) !== - 1 && this . _pendingRemoval . indexOf ( child ) === - 1 )
223- {
224- this . _pendingRemoval . push ( child ) ;
225- }
226-
227- return child ;
228- } ,
229-
230- /**
231- * Remove all Game Objects from the list.
232- *
233- * @method Phaser.GameObjects.UpdateList#removeAll
234- * @since 3.0.0
235- *
236- * @return {Phaser.GameObjects.UpdateList } This UpdateList.
237- */
238- removeAll : function ( )
239- {
240- var i = this . _list . length ;
241-
242- while ( i -- )
243- {
244- this . remove ( this . _list [ i ] ) ;
245- }
246-
247- return this ;
248- } ,
249-
250121 /**
251122 * The Scene that owns this plugin is shutting down.
123+ *
252124 * We need to kill and reset all internal properties as well as stop listening to Scene events.
253125 *
254126 * @method Phaser.GameObjects.UpdateList#shutdown
255127 * @since 3.0.0
256128 */
257129 shutdown : function ( )
258130 {
259- var i = this . _list . length ;
131+ var i = this . _active . length ;
260132
261133 while ( i -- )
262134 {
263- this . _list [ i ] . destroy ( true ) ;
135+ this . _active [ i ] . destroy ( true ) ;
264136 }
265137
266- i = this . _pendingRemoval . length ;
138+ i = this . _pending . length ;
267139
268140 while ( i -- )
269141 {
270- this . _pendingRemoval [ i ] . destroy ( true ) ;
142+ this . _pending [ i ] . destroy ( true ) ;
271143 }
272144
273- i = this . _pendingInsertion . length ;
145+ i = this . _destroy . length ;
274146
275147 while ( i -- )
276148 {
277- this . _pendingInsertion [ i ] . destroy ( true ) ;
149+ this . _destroy [ i ] . destroy ( true ) ;
278150 }
279151
280- this . _list . length = 0 ;
281- this . _pendingRemoval . length = 0 ;
282- this . _pendingInsertion . length = 0 ;
152+ this . _toProcess = 0 ;
153+
154+ this . _pending = [ ] ;
155+ this . _active = [ ] ;
156+ this . _destroy = [ ] ;
283157
284158 var eventEmitter = this . systems . events ;
285159
@@ -290,6 +164,7 @@ var UpdateList = new Class({
290164
291165 /**
292166 * The Scene that owns this plugin is being destroyed.
167+ *
293168 * We need to shutdown and then kill off all external references.
294169 *
295170 * @method Phaser.GameObjects.UpdateList#destroy
@@ -303,23 +178,6 @@ var UpdateList = new Class({
303178
304179 this . scene = null ;
305180 this . systems = null ;
306- } ,
307-
308- /**
309- * The length of the list.
310- *
311- * @name Phaser.GameObjects.UpdateList#length
312- * @type {integer }
313- * @readonly
314- * @since 3.10.0
315- */
316- length : {
317-
318- get : function ( )
319- {
320- return this . _list . length ;
321- }
322-
323181 }
324182
325183} ) ;
0 commit comments