From b0cb7c230a8347ab94e2dc424ff420af6e6fae22 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Dec 2013 14:22:51 +0800 Subject: [PATCH] #issue #2790: Uses Vector for scenesStack in CCDirector. --- cocos/2d/CCDirector.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index bce116b491..cd029d737f 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -110,8 +110,7 @@ bool Director::init(void) _notificationNode = nullptr; - _scenesStack = new Array(); - _scenesStack->initWithCapacity(15); + _scenesStack.reserve(15); // projection delegate if "Custom" projection is used _projectionDelegate = nullptr; @@ -164,7 +163,6 @@ Director::~Director(void) CC_SAFE_RELEASE(_runningScene); CC_SAFE_RELEASE(_notificationNode); - CC_SAFE_RELEASE(_scenesStack); CC_SAFE_RELEASE(_scheduler); CC_SAFE_RELEASE(_actionManager); CC_SAFE_RELEASE(_eventDispatcher); @@ -597,10 +595,10 @@ void Director::replaceScene(Scene *scene) CCASSERT(_runningScene, "Use runWithScene: instead to start the director"); CCASSERT(scene != nullptr, "the scene should not be null"); - unsigned int index = _scenesStack->count(); + int index = _scenesStack.size(); _sendCleanupToScene = true; - _scenesStack->replaceObjectAtIndex(index - 1, scene); + _scenesStack.replace(index - 1, scene); _nextScene = scene; } @@ -611,7 +609,7 @@ void Director::pushScene(Scene *scene) _sendCleanupToScene = false; - _scenesStack->addObject(scene); + _scenesStack.pushBack(scene); _nextScene = scene; } @@ -619,8 +617,8 @@ void Director::popScene(void) { CCASSERT(_runningScene != nullptr, "running scene should not null"); - _scenesStack->removeLastObject(); - unsigned int c = _scenesStack->count(); + _scenesStack.popBack(); + int c = _scenesStack.size(); if (c == 0) { @@ -629,7 +627,7 @@ void Director::popScene(void) else { _sendCleanupToScene = true; - _nextScene = (Scene*)_scenesStack->getObjectAtIndex(c - 1); + _nextScene = _scenesStack.at(c - 1); } } @@ -641,7 +639,7 @@ void Director::popToRootScene(void) void Director::popToSceneStackLevel(int level) { CCASSERT(_runningScene != nullptr, "A running Scene is needed"); - int c = static_cast(_scenesStack->count()); + int c = _scenesStack.size(); // level 0? -> end if (level == 0) @@ -657,7 +655,7 @@ void Director::popToSceneStackLevel(int level) // pop stack until reaching desired level while (c > level) { - Scene *current = (Scene*)_scenesStack->getLastObject(); + auto current = _scenesStack.back(); if (current->isRunning()) { @@ -666,11 +664,11 @@ void Director::popToSceneStackLevel(int level) } current->cleanup(); - _scenesStack->removeLastObject(); + _scenesStack.popBack(); --c; } - _nextScene = (Scene*)_scenesStack->getLastObject(); + _nextScene = _scenesStack.back(); _sendCleanupToScene = false; } @@ -701,7 +699,7 @@ void Director::purgeDirector() // remove all objects, but don't release it. // runWithScene might be executed after 'end'. - _scenesStack->removeAllObjects(); + _scenesStack.clear(); stopAnimation();