File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Phaser.Structs.ProcessQueue
2+
3+ var Class = require ( '../utils/Class' ) ;
4+
5+ var ProcessQueue = new Class ( {
6+
7+ initialize :
8+
9+ function ProcessQueue ( )
10+ {
11+ this . _pending = [ ] ;
12+ this . _active = [ ] ;
13+ this . _destroy = [ ] ;
14+
15+ this . _toProcess = 0 ;
16+ } ,
17+
18+ add : function ( item )
19+ {
20+ this . _pending . push ( item ) ;
21+
22+ this . _toProcess ++ ;
23+
24+ return this ;
25+ } ,
26+
27+ remove : function ( item )
28+ {
29+ this . _destroy . push ( item ) ;
30+
31+ this . _toProcess ++ ;
32+
33+ return this ;
34+ } ,
35+
36+ update : function ( )
37+ {
38+ if ( this . _toProcess === 0 )
39+ {
40+ // Quick bail
41+ return this . _active ;
42+ }
43+
44+ var list = this . _destroy ;
45+ var active = this . _active ;
46+ var i ;
47+ var item ;
48+
49+ // Clear the 'destroy' list
50+ for ( i = 0 ; i < list . length ; i ++ )
51+ {
52+ item = list [ i ] ;
53+
54+ // Remove from the 'active' array
55+ var idx = active . indexOf ( item ) ;
56+
57+ if ( idx !== - 1 )
58+ {
59+ active . splice ( idx , 1 ) ;
60+ }
61+ }
62+
63+ list . length = 0 ;
64+
65+ // Process the pending addition list
66+ // This stops callbacks and out of sync events from populating the active array mid-way during an update
67+
68+ list = this . _pending ;
69+
70+ for ( i = 0 ; i < list . length ; i ++ )
71+ {
72+ item = list [ i ] ;
73+
74+ this . _active . push ( item ) ;
75+ }
76+
77+ list . length = 0 ;
78+
79+ this . _toProcess = 0 ;
80+
81+ // The owner of this queue can now safely do whatever it needs to with the active list
82+ return this . _active ;
83+ } ,
84+
85+ getActive : function ( )
86+ {
87+ return this . _active ;
88+ } ,
89+
90+ destroy : function ( )
91+ {
92+ this . _pending = [ ] ;
93+ this . _active = [ ] ;
94+ this . _destroy = [ ] ;
95+ }
96+
97+ } ) ;
98+
99+ module . exports = ProcessQueue ;
Original file line number Diff line number Diff line change 22
33module . exports = {
44
5+ List : require ( './List' ) ,
56 Map : require ( './Map' ) ,
7+ ProcessQueue : require ( './ProcessQueue' ) ,
68 RTree : require ( './RTree' ) ,
79 Set : require ( './Set' )
810
You can’t perform that action at this time.
0 commit comments