@@ -216,68 +216,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
216
216
return true ;
217
217
} ,
218
218
219
- _arrayMakeObjectsPerformSelector : function ( array , callbackType ) {
220
- if ( ! array || array . length === 0 )
221
- return ;
222
-
223
- var i , len = array . length , node ;
224
- var nodeCallbackType = cc . Node . _stateCallbackType ;
225
- switch ( callbackType ) {
226
- case nodeCallbackType . onEnter :
227
- for ( i = 0 ; i < len ; i ++ ) {
228
- node = array [ i ] ;
229
- if ( node )
230
- node . onEnter ( ) ;
231
- }
232
- break ;
233
- case nodeCallbackType . onExit :
234
- for ( i = 0 ; i < len ; i ++ ) {
235
- node = array [ i ] ;
236
- if ( node )
237
- node . onExit ( ) ;
238
- }
239
- break ;
240
- case nodeCallbackType . onEnterTransitionDidFinish :
241
- for ( i = 0 ; i < len ; i ++ ) {
242
- node = array [ i ] ;
243
- if ( node )
244
- node . onEnterTransitionDidFinish ( ) ;
245
- }
246
- break ;
247
- case nodeCallbackType . cleanup :
248
- for ( i = 0 ; i < len ; i ++ ) {
249
- node = array [ i ] ;
250
- if ( node )
251
- node . cleanup ( ) ;
252
- }
253
- break ;
254
- case nodeCallbackType . updateTransform :
255
- for ( i = 0 ; i < len ; i ++ ) {
256
- node = array [ i ] ;
257
- if ( node )
258
- node . updateTransform ( ) ;
259
- }
260
- break ;
261
- case nodeCallbackType . onExitTransitionDidStart :
262
- for ( i = 0 ; i < len ; i ++ ) {
263
- node = array [ i ] ;
264
- if ( node )
265
- node . onExitTransitionDidStart ( ) ;
266
- }
267
- break ;
268
- case nodeCallbackType . sortAllChildren :
269
- for ( i = 0 ; i < len ; i ++ ) {
270
- node = array [ i ] ;
271
- if ( node )
272
- node . sortAllChildren ( ) ;
273
- }
274
- break ;
275
- default :
276
- cc . assert ( 0 , cc . _LogInfos . Node__arrayMakeObjectsPerformSelector ) ;
277
- break ;
278
- }
279
- } ,
280
-
281
219
/**
282
220
* <p>Properties configuration function </br>
283
221
* All properties in attrs will be set to the node, </br>
@@ -1177,9 +1115,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1177
1115
1178
1116
// event
1179
1117
cc . eventManager . removeListeners ( this ) ;
1180
-
1181
- // timers
1182
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . cleanup ) ;
1183
1118
} ,
1184
1119
1185
1120
// composition: GET
@@ -1264,10 +1199,10 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1264
1199
child . setOrderOfArrival ( cc . s_globalOrderOfArrival ++ ) ;
1265
1200
1266
1201
if ( this . _running ) {
1267
- child . onEnter ( ) ;
1202
+ child . _performRecursive ( cc . Node . _stateCallbackType . onEnter ) ;
1268
1203
// prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
1269
1204
if ( this . _isTransitionFinished )
1270
- child . onEnterTransitionDidFinish ( ) ;
1205
+ child . _performRecursive ( cc . Node . _stateCallbackType . onEnterTransitionDidFinish ) ;
1271
1206
}
1272
1207
child . _renderCmd . setDirtyFlag ( cc . Node . _dirtyFlags . transformDirty ) ;
1273
1208
if ( this . _cascadeColorEnabled )
@@ -1370,13 +1305,13 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1370
1305
var node = __children [ i ] ;
1371
1306
if ( node ) {
1372
1307
if ( this . _running ) {
1373
- node . onExitTransitionDidStart ( ) ;
1374
- node . onExit ( ) ;
1308
+ node . _performRecursive ( cc . Node . _stateCallbackType . onExitTransitionDidStart ) ;
1309
+ node . _performRecursive ( cc . Node . _stateCallbackType . onExit ) ;
1375
1310
}
1376
1311
1377
1312
// If you don't do cleanup, the node's actions will not get removed and the
1378
1313
if ( cleanup )
1379
- node . cleanup ( ) ;
1314
+ node . _performRecursive ( cc . Node . _stateCallbackType . cleanup ) ;
1380
1315
1381
1316
// set parent nil at the end
1382
1317
node . parent = null ;
@@ -1393,13 +1328,13 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1393
1328
// -1st do onExit
1394
1329
// -2nd cleanup
1395
1330
if ( this . _running ) {
1396
- child . onExitTransitionDidStart ( ) ;
1397
- child . onExit ( ) ;
1331
+ child . _performRecursive ( cc . Node . _stateCallbackType . onExitTransitionDidStart ) ;
1332
+ child . _performRecursive ( cc . Node . _stateCallbackType . onExit ) ;
1398
1333
}
1399
1334
1400
1335
// If you don't do cleanup, the child's actions will not get removed and the
1401
1336
if ( doCleanup )
1402
- child . cleanup ( ) ;
1337
+ child . _performRecursive ( cc . Node . _stateCallbackType . cleanup ) ;
1403
1338
1404
1339
// set parent nil at the end
1405
1340
child . parent = null ;
@@ -1501,10 +1436,72 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1501
1436
onEnter : function ( ) {
1502
1437
this . _isTransitionFinished = false ;
1503
1438
this . _running = true ; //should be running before resumeSchedule
1504
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . onEnter ) ;
1505
1439
this . resume ( ) ;
1506
1440
} ,
1507
1441
1442
+ _performRecursive : function ( callbackType ) {
1443
+ var nodeCallbackType = cc . Node . _stateCallbackType ;
1444
+ if ( callbackType >= nodeCallbackType . max ) {
1445
+ return ;
1446
+ }
1447
+
1448
+ var index = 0 ;
1449
+ var children , child , curr , i , len ;
1450
+ var stack = cc . Node . _performStacks [ cc . Node . _performing ] ;
1451
+ if ( ! stack ) {
1452
+ stack = [ ] ;
1453
+ cc . Node . _performStacks . push ( stack ) ;
1454
+ }
1455
+ stack . length = 0 ;
1456
+ cc . Node . _performing ++ ;
1457
+ curr = stack [ 0 ] = this ;
1458
+ while ( curr ) {
1459
+ // Walk through children
1460
+ children = curr . _children ;
1461
+ if ( children && children . length > 0 ) {
1462
+ for ( i = 0 , len = children . length ; i < len ; ++ i ) {
1463
+ child = children [ i ] ;
1464
+ stack . push ( child ) ;
1465
+ }
1466
+ }
1467
+ children = curr . _protectedChildren ;
1468
+ if ( children && children . length > 0 ) {
1469
+ for ( i = 0 , len = children . length ; i < len ; ++ i ) {
1470
+ child = children [ i ] ;
1471
+ stack . push ( child ) ;
1472
+ }
1473
+ }
1474
+
1475
+ index ++ ;
1476
+ curr = stack [ index ] ;
1477
+ }
1478
+ for ( i = stack . length - 1 ; i >= 0 ; -- i ) {
1479
+ curr = stack [ i ] ;
1480
+ stack [ i ] = null ;
1481
+ if ( ! curr ) continue ;
1482
+
1483
+ // Perform actual action
1484
+ switch ( callbackType ) {
1485
+ case nodeCallbackType . onEnter :
1486
+ curr . onEnter ( ) ;
1487
+ break ;
1488
+ case nodeCallbackType . onExit :
1489
+ curr . onExit ( ) ;
1490
+ break ;
1491
+ case nodeCallbackType . onEnterTransitionDidFinish :
1492
+ curr . onEnterTransitionDidFinish ( ) ;
1493
+ break ;
1494
+ case nodeCallbackType . cleanup :
1495
+ curr . cleanup ( ) ;
1496
+ break ;
1497
+ case nodeCallbackType . onExitTransitionDidStart :
1498
+ curr . onExitTransitionDidStart ( ) ;
1499
+ break ;
1500
+ }
1501
+ }
1502
+ cc . Node . _performing -- ;
1503
+ } ,
1504
+
1508
1505
/**
1509
1506
* <p>
1510
1507
* Event callback that is invoked when the CCNode enters in the 'stage'. <br/>
@@ -1515,7 +1512,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1515
1512
*/
1516
1513
onEnterTransitionDidFinish : function ( ) {
1517
1514
this . _isTransitionFinished = true ;
1518
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . onEnterTransitionDidFinish ) ;
1519
1515
} ,
1520
1516
1521
1517
/**
@@ -1525,7 +1521,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1525
1521
* @function
1526
1522
*/
1527
1523
onExitTransitionDidStart : function ( ) {
1528
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . onExitTransitionDidStart ) ;
1529
1524
} ,
1530
1525
1531
1526
/**
@@ -1540,7 +1535,6 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
1540
1535
onExit : function ( ) {
1541
1536
this . _running = false ;
1542
1537
this . pause ( ) ;
1543
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . onExit ) ;
1544
1538
this . removeAllComponents ( ) ;
1545
1539
} ,
1546
1540
@@ -2011,8 +2005,12 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
2011
2005
* @function
2012
2006
*/
2013
2007
updateTransform : function ( ) {
2014
- // Recursively iterate over children
2015
- this . _arrayMakeObjectsPerformSelector ( this . _children , cc . Node . _stateCallbackType . updateTransform ) ;
2008
+ var children = this . _children , node ;
2009
+ for ( var i = 0 ; i < children . length ; i ++ ) {
2010
+ varnode = children [ i ] ;
2011
+ if ( node )
2012
+ node . updateTransform ( ) ;
2013
+ }
2016
2014
} ,
2017
2015
2018
2016
/**
@@ -2541,7 +2539,16 @@ cc.Node.create = function () {
2541
2539
return new cc . Node ( ) ;
2542
2540
} ;
2543
2541
2544
- cc . Node . _stateCallbackType = { onEnter : 1 , onExit : 2 , cleanup : 3 , onEnterTransitionDidFinish : 4 , updateTransform : 5 , onExitTransitionDidStart : 6 , sortAllChildren : 7 } ;
2542
+ cc . Node . _stateCallbackType = {
2543
+ onEnter : 1 ,
2544
+ onExit : 2 ,
2545
+ cleanup : 3 ,
2546
+ onEnterTransitionDidFinish : 4 ,
2547
+ onExitTransitionDidStart : 5 ,
2548
+ max : 6
2549
+ } ;
2550
+ cc . Node . _performStacks = [ [ ] ] ;
2551
+ cc . Node . _performing = 0 ;
2545
2552
2546
2553
cc . assert ( cc . isFunction ( cc . _tmp . PrototypeCCNode ) , cc . _LogInfos . MissingFile , "BaseNodesPropertyDefine.js" ) ;
2547
2554
cc . _tmp . PrototypeCCNode ( ) ;
0 commit comments