30
30
* @example
31
31
* var element = new cc.HashElement();
32
32
*/
33
- cc . HashElement = cc . Class . extend ( /** @lends cc.HashElement# */ {
34
- actions :null ,
35
- target :null , //ccobject
36
- actionIndex :0 ,
37
- currentAction :null , //CCAction
38
- currentActionSalvaged :false ,
39
- paused :false ,
40
- /**
41
- * Constructor
42
- */
43
- ctor :function ( ) {
44
- this . actions = [ ] ;
45
- this . target = null ;
46
- this . actionIndex = 0 ;
47
- this . currentAction = null ; //CCAction
48
- this . currentActionSalvaged = false ;
49
- this . paused = false ;
50
- }
51
- } ) ;
33
+ cc . HashElement = function ( ) {
34
+ this . actions = [ ] ;
35
+ this . target = null ;
36
+ this . actionIndex = 0 ;
37
+ this . currentAction = null ; //CCAction
38
+ this . paused = false ;
39
+ } ;
52
40
53
41
/**
54
42
* cc.ActionManager is a class that can manage actions.<br/>
@@ -64,10 +52,6 @@ cc.HashElement = cc.Class.extend(/** @lends cc.HashElement# */{
64
52
* var mng = new cc.ActionManager();
65
53
*/
66
54
cc . ActionManager = cc . Class . extend ( /** @lends cc.ActionManager# */ {
67
- _hashTargets :null ,
68
- _arrayTargets :null ,
69
- _currentTarget :null ,
70
- _currentTargetSalvaged :false ,
71
55
_elementPool : [ ] ,
72
56
73
57
_searchElementByTarget :function ( arr , target ) {
@@ -82,7 +66,6 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
82
66
this . _hashTargets = { } ;
83
67
this . _arrayTargets = [ ] ;
84
68
this . _currentTarget = null ;
85
- this . _currentTargetSalvaged = false ;
86
69
} ,
87
70
88
71
_getElement : function ( target , paused ) {
@@ -99,8 +82,8 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
99
82
element . actions . length = 0 ;
100
83
element . actionIndex = 0 ;
101
84
element . currentAction = null ;
102
- element . currentActionSalvaged = false ;
103
85
element . paused = false ;
86
+ element . target = null ;
104
87
this . _elementPool . push ( element ) ;
105
88
} ,
106
89
@@ -156,15 +139,8 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
156
139
return ;
157
140
var element = this . _hashTargets [ target . __instanceId ] ;
158
141
if ( element ) {
159
- if ( element . actions . indexOf ( element . currentAction ) !== - 1 && ! ( element . currentActionSalvaged ) )
160
- element . currentActionSalvaged = true ;
161
-
162
142
element . actions . length = 0 ;
163
- if ( this . _currentTarget === element && ! forceDelete ) {
164
- this . _currentTargetSalvaged = true ;
165
- } else {
166
- this . _deleteHashElement ( element ) ;
167
- }
143
+ this . _deleteHashElement ( element ) ;
168
144
}
169
145
} ,
170
146
/** Removes an action given an action reference.
@@ -181,6 +157,9 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
181
157
for ( var i = 0 ; i < element . actions . length ; i ++ ) {
182
158
if ( element . actions [ i ] === action ) {
183
159
element . actions . splice ( i , 1 ) ;
160
+ // update actionIndex in case we are in tick. looping over the actions
161
+ if ( element . actionIndex >= i )
162
+ element . actionIndex -- ;
184
163
break ;
185
164
}
186
165
}
@@ -291,10 +270,10 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
291
270
* @param {Array } targetsToResume
292
271
*/
293
272
resumeTargets :function ( targetsToResume ) {
294
- if ( ! targetsToResume )
273
+ if ( ! targetsToResume )
295
274
return ;
296
275
297
- for ( var i = 0 ; i < targetsToResume . length ; i ++ ) {
276
+ for ( var i = 0 ; i < targetsToResume . length ; i ++ ) {
298
277
if ( targetsToResume [ i ] )
299
278
this . resumeTarget ( targetsToResume [ i ] ) ;
300
279
}
@@ -311,21 +290,14 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
311
290
_removeActionAtIndex :function ( index , element ) {
312
291
var action = element . actions [ index ] ;
313
292
314
- if ( ( action === element . currentAction ) && ( ! element . currentActionSalvaged ) )
315
- element . currentActionSalvaged = true ;
316
-
317
293
element . actions . splice ( index , 1 ) ;
318
294
319
295
// update actionIndex in case we are in tick. looping over the actions
320
296
if ( element . actionIndex >= index )
321
297
element . actionIndex -- ;
322
298
323
299
if ( element . actions . length === 0 ) {
324
- if ( this . _currentTarget === element ) {
325
- this . _currentTargetSalvaged = true ;
326
- } else {
327
- this . _deleteHashElement ( element ) ;
328
- }
300
+ this . _deleteHashElement ( element ) ;
329
301
}
330
302
} ,
331
303
@@ -356,25 +328,17 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
356
328
for ( var elt = 0 ; elt < locTargets . length ; elt ++ ) {
357
329
this . _currentTarget = locTargets [ elt ] ;
358
330
locCurrTarget = this . _currentTarget ;
359
- //this._currentTargetSalvaged = false;
360
- if ( ! locCurrTarget . paused ) {
331
+ if ( ! locCurrTarget . paused && locCurrTarget . actions ) {
361
332
// The 'actions' CCMutableArray may change while inside this loop.
362
- for ( locCurrTarget . actionIndex = 0 ;
363
- locCurrTarget . actionIndex < ( locCurrTarget . actions ? locCurrTarget . actions . length : 0 ) ;
364
- locCurrTarget . actionIndex ++ ) {
333
+ for ( locCurrTarget . actionIndex = 0 ; locCurrTarget . actionIndex < locCurrTarget . actions . length ; locCurrTarget . actionIndex ++ ) {
365
334
locCurrTarget . currentAction = locCurrTarget . actions [ locCurrTarget . actionIndex ] ;
366
335
if ( ! locCurrTarget . currentAction )
367
336
continue ;
368
337
369
- locCurrTarget . currentActionSalvaged = false ;
370
338
//use for speed
371
339
locCurrTarget . currentAction . step ( dt * ( locCurrTarget . currentAction . _speedMethod ? locCurrTarget . currentAction . _speed : 1 ) ) ;
372
- if ( locCurrTarget . currentActionSalvaged ) {
373
- // The currentAction told the node to remove it. To prevent the action from
374
- // accidentally deallocating itself before finishing its step, we retained
375
- // it. Now that step is done, it's safe to release it.
376
- locCurrTarget . currentAction = null ; //release
377
- } else if ( locCurrTarget . currentAction . isDone ( ) ) {
340
+
341
+ if ( locCurrTarget . currentAction . isDone ( ) ) {
378
342
locCurrTarget . currentAction . stop ( ) ;
379
343
var action = locCurrTarget . currentAction ;
380
344
// Make currentAction nil to prevent removeAction from salvaging it.
@@ -385,12 +349,8 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
385
349
locCurrTarget . currentAction = null ;
386
350
}
387
351
}
388
-
389
- // elt, at this moment, is still valid
390
- // so it is safe to ask this here (issue #490)
391
-
392
352
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
393
- if ( this . _currentTargetSalvaged && locCurrTarget . actions . length === 0 ) {
353
+ if ( locCurrTarget . actions . length === 0 ) {
394
354
this . _deleteHashElement ( locCurrTarget ) && elt -- ;
395
355
}
396
356
}
0 commit comments