From e3795c0223948703707593e64587430d56aac61a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 28 Dec 2014 11:55:06 +0800 Subject: [PATCH 1/9] Added restart game feature --- cocos/base/CCDirector.cpp | 84 +++++++++++++++++++ cocos/base/CCDirector.h | 7 ++ cocos/base/CCScriptSupport.h | 3 +- .../lua-bindings/manual/CCLuaEngine.cpp | 7 ++ 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 87feec6c82..3d0a7f0dc1 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -61,6 +61,10 @@ THE SOFTWARE. #include "platform/CCApplication.h" //#include "platform/CCGLViewImpl.h" +#if CC_ENABLE_SCRIPT_BINDING +#include "CCScriptSupport.h" +#endif + /** Position of the FPS @@ -126,6 +130,9 @@ bool Director::init(void) // purge ? _purgeDirectorInNextLoop = false; + + // restart ? + _restartDirectorInNextLoop = false; _winSizeInPoints = Size::ZERO; @@ -1017,6 +1024,78 @@ void Director::purgeDirector() release(); } +void Director::restart() +{ + _restartDirectorInNextLoop = true; +} + +void Director::restartDirector() +{ + // cleanup scheduler + getScheduler()->unscheduleAll(); + // Disable event dispatching + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(false); + } + + if (_runningScene) + { + _runningScene->onExit(); + _runningScene->cleanup(); + _runningScene->release(); + } + + _runningScene = nullptr; + _nextScene = nullptr; + + // remove all objects, but don't release it. + // runWithScene might be executed after 'end'. + _scenesStack.clear(); + + stopAnimation(); + + CC_SAFE_RELEASE_NULL(_FPSLabel); + CC_SAFE_RELEASE_NULL(_drawnBatchesLabel); + CC_SAFE_RELEASE_NULL(_drawnVerticesLabel); + + // purge bitmap cache + FontFNT::purgeCachedData(); + + FontFreeType::shutdownFreeType(); + + // purge all managed caches + AnimationCache::destroyInstance(); + SpriteFrameCache::destroyInstance(); + GLProgramCache::destroyInstance(); + GLProgramStateCache::destroyInstance(); + std::vector searchPaths; + FileUtils::getInstance()->setSearchPaths(searchPaths); + FileUtils::getInstance()->purgeCachedEntries(); + + // cocos2d-x specific data structures + UserDefault::destroyInstance(); + + GL::invalidateStateCache(); + + //destroyTextureCache(); + _textureCache->removeAllTextures(); + + // Disable event dispatching + if (_eventDispatcher) + { + _eventDispatcher->setEnabled(true); + } + + // release the objects + PoolManager::getInstance()->getCurrentPool()->clear(); + +#if CC_ENABLE_SCRIPT_BINDING + ScriptEvent scriptEvent(kRestartGame, NULL); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); +#endif +} + void Director::setNextScene() { bool runningIsTransition = dynamic_cast(_runningScene) != nullptr; @@ -1304,6 +1383,11 @@ void DisplayLinkDirector::mainLoop() _purgeDirectorInNextLoop = false; purgeDirector(); } + else if (_restartDirectorInNextLoop) + { + _restartDirectorInNextLoop = false; + restartDirector(); + } else if (! _invalid) { drawScene(); diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index 644722629d..442037a0b6 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -287,6 +287,10 @@ public: The "delta time" will be 0 (as if the game wasn't paused) */ void resume(); + + /** Restart the director + */ + void restart(); /** Stops the animation. Nothing will be drawn. The main loop won't be triggered anymore. If you don't want to pause your animation call [pause] instead. @@ -399,6 +403,9 @@ protected: void purgeDirector(); bool _purgeDirectorInNextLoop; // this flag will be set to true in end() + void restartDirector(); + bool _restartDirectorInNextLoop; // this flag will be set to true in restart() + void setNextScene(); void showStats(); diff --git a/cocos/base/CCScriptSupport.h b/cocos/base/CCScriptSupport.h index da896a9f07..4506d44233 100644 --- a/cocos/base/CCScriptSupport.h +++ b/cocos/base/CCScriptSupport.h @@ -211,7 +211,8 @@ enum ScriptEventType kAccelerometerEvent, kControlEvent, kCommonEvent, - kComponentEvent + kComponentEvent, + kRestartGame }; struct BasicScriptData diff --git a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp index 6a114d5b40..914ef385db 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp @@ -256,6 +256,13 @@ int LuaEngine::sendEvent(ScriptEvent* evt) return handlerControlEvent(evt->data); } break; + case kRestartGame: + { + // TODO: Clean up the LUA VM + //cleanup(); + CCApplication::getInstance()->applicationDidFinishLaunching(); + return 0; + } default: break; } From 1e32d0fb803fc823f924426e094861c20354ffa1 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 28 Dec 2014 11:55:31 +0800 Subject: [PATCH 2/9] Added getSearchPaths API in Manifest --- extensions/assets-manager/Manifest.cpp | 15 +++++++++++++++ extensions/assets-manager/Manifest.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/extensions/assets-manager/Manifest.cpp b/extensions/assets-manager/Manifest.cpp index b4cd96c211..fb0d97acec 100644 --- a/extensions/assets-manager/Manifest.cpp +++ b/extensions/assets-manager/Manifest.cpp @@ -234,6 +234,21 @@ void Manifest::genResumeAssetsList(Downloader::DownloadUnits *units) const } } +std::vector Manifest::getSearchPaths() +{ + std::vector searchPaths; + searchPaths.push_back(_manifestRoot); + + for (int i = (int)_searchPaths.size()-1; i >= 0; i--) + { + std::string path = _searchPaths[i]; + if (path.size() > 0 && path[path.size() - 1] != '/') + path.append("/"); + path = _manifestRoot + path; + searchPaths.push_back(path); + } + return searchPaths; +} void Manifest::prependSearchPaths() { diff --git a/extensions/assets-manager/Manifest.h b/extensions/assets-manager/Manifest.h index 8a2bcfbcf6..f807cabb5a 100644 --- a/extensions/assets-manager/Manifest.h +++ b/extensions/assets-manager/Manifest.h @@ -95,6 +95,10 @@ public: */ const std::string& getVersion() const; + /** @brief Get the search paths list related to the Manifest. + */ + std::vector getSearchPaths(); + protected: /** @brief Constructor for Manifest class From 75436db5832a6c8de9414c9c2fe2dec68a6ad463 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 29 Dec 2014 05:51:45 +0000 Subject: [PATCH 3/9] [AUTO]: updating luabinding automatically --- cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp index 0ae72a45e9..5169b8f894 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp @@ -7135,7 +7135,7 @@ int lua_cocos2dx_ui_Button_getTitleColor(lua_State* tolua_S) tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Button_getTitleColor'", nullptr); return 0; } - const cocos2d::Color3B& ret = cobj->getTitleColor(); + cocos2d::Color3B ret = cobj->getTitleColor(); color3b_to_luaval(tolua_S, ret); return 1; } From 1502d32aac10d75bc9cad927627a1ca427873f4f Mon Sep 17 00:00:00 2001 From: Thomas Hou Date: Mon, 29 Dec 2014 16:24:31 +0800 Subject: [PATCH 4/9] use std math library M_PI instead of pi. --- tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 8c5c65e0dc..fd076c5d48 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1991,7 +1991,7 @@ void QuaternionTest::addNewSpriteWithCoords(Vec2 p) void QuaternionTest::update(float delta) { _accAngle += delta * _arcSpeed; - const float pi = 3.1415926f; + const float pi = M_PI; if (_accAngle >= 2 * pi) _accAngle -= 2 * pi; From cfa9f039eca9c1c326b3298eec88fea0aa6b85ea Mon Sep 17 00:00:00 2001 From: Thomas Hou Date: Mon, 29 Dec 2014 16:43:48 +0800 Subject: [PATCH 5/9] change light direct for good look. --- tests/cpp-tests/Resources/Sprite3DTest/toon.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Resources/Sprite3DTest/toon.frag b/tests/cpp-tests/Resources/Sprite3DTest/toon.frag index 1c95b8fbfd..aa412d1adf 100644 --- a/tests/cpp-tests/Resources/Sprite3DTest/toon.frag +++ b/tests/cpp-tests/Resources/Sprite3DTest/toon.frag @@ -7,7 +7,7 @@ uniform vec4 u_color; varying vec3 v_normal; void main(void) { - vec3 light_direction = vec3(1,-1,0); + vec3 light_direction = vec3(1,-1,-1); light_direction = normalize(light_direction); vec3 light_color = vec3(1,1,1); vec3 normal = normalize(v_normal); From d3783cba951c39277d53c76f1a1fb00476305161 Mon Sep 17 00:00:00 2001 From: pipu Date: Mon, 29 Dec 2014 17:04:23 +0800 Subject: [PATCH 6/9] Modify warning code. --- .../cocostudio/FlatBuffersSerialize.cpp | 10 +-- .../ArmatureNodeReader/ArmatureNodeReader.cpp | 6 +- .../ListViewReader/ListViewReader.cpp | 70 +++++++++---------- .../ProjectNodeReader/ProjectNodeReader.cpp | 10 +-- .../cocostudio/WidgetReader/WidgetReader.cpp | 2 +- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 8397e5668c..a780c70bf4 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -1218,19 +1218,19 @@ Offset FlatBuffersSerialize::createProjectNodeOptionsForSimu if (name == "FileData") { - const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); + const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute(); - while (attribute) + while (attributeFileData) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeFileData->Name(); + std::string value = attributeFileData->Value(); if (name == "Path") { filename = value; } - attribute = attribute->Next(); + attributeFileData = attributeFileData->Next(); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp index 89a016417e..0a4bc3ed07 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.cpp @@ -151,9 +151,9 @@ cocos2d::Node* ArmatureNodeReader::createNodeWithFlatBuffers(const flatbuffers: std::string ArmatureNodeReader::getArmatureName(const std::string& exporJsonPath) { //FileUtils.getFileData(exporJsonPath, "r", size) // need read armature name in exportJsonPath - int end = exporJsonPath.find_last_of("."); - int start = exporJsonPath.find_last_of("\\") + 1; - int start1 = exporJsonPath.find_last_of("/") + 1; + size_t end = exporJsonPath.find_last_of("."); + size_t start = exporJsonPath.find_last_of("\\") + 1; + size_t start1 = exporJsonPath.find_last_of("/") + 1; if (start < start1) start = start1; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index 4272f4b14a..e43ade4575 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -185,11 +185,11 @@ namespace cocostudio if (name == "InnerNodeSize") { - auto attribute = child->FirstAttribute(); - while (attribute) + auto attributeInnerNodeSize = child->FirstAttribute(); + while (attributeInnerNodeSize) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeInnerNodeSize->Name(); + std::string value = attributeInnerNodeSize->Value(); if (name == "Width") { @@ -200,17 +200,17 @@ namespace cocostudio innerSize.height = atof(value.c_str()); } - attribute = attribute->Next(); + attributeInnerNodeSize = attributeInnerNodeSize->Next(); } } else if (name == "Size" && backGroundScale9Enabled) { - auto attribute = child->FirstAttribute(); + auto attributeSize = child->FirstAttribute(); - while (attribute) + while (attributeSize) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeSize->Name(); + std::string value = attributeSize->Value(); if (name == "X") { @@ -221,17 +221,17 @@ namespace cocostudio scale9Size.height = atof(value.c_str()); } - attribute = attribute->Next(); + attributeSize = attributeSize->Next(); } } else if (name == "SingleColor") { - auto attribute = child->FirstAttribute(); + auto attributeSingleColor = child->FirstAttribute(); - while (attribute) + while (attributeSingleColor) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeSingleColor->Name(); + std::string value = attributeSingleColor->Value(); if (name == "R") { @@ -246,17 +246,17 @@ namespace cocostudio bgColor.b = atoi(value.c_str()); } - attribute = attribute->Next(); + attributeSingleColor = attributeSingleColor->Next(); } } else if (name == "EndColor") { - auto attribute = child->FirstAttribute(); + auto attributeEndColor = child->FirstAttribute(); - while (attribute) + while (attributeEndColor) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeEndColor->Name(); + std::string value = attributeEndColor->Value(); if (name == "R") { @@ -271,17 +271,17 @@ namespace cocostudio bgEndColor.b = atoi(value.c_str()); } - attribute = attribute->Next(); + attributeEndColor = attributeEndColor->Next(); } } else if (name == "FirstColor") { - auto attribute = child->FirstAttribute(); + auto attributeFirstColor = child->FirstAttribute(); - while (attribute) + while (attributeFirstColor) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeFirstColor->Name(); + std::string value = attributeFirstColor->Value(); if (name == "R") { @@ -296,16 +296,16 @@ namespace cocostudio bgStartColor.b = atoi(value.c_str()); } - attribute = attribute->Next(); + attributeFirstColor = attributeFirstColor->Next(); } } else if (name == "ColorVector") { - auto attribute = child->FirstAttribute(); - while (attribute) + auto attributeColorVector = child->FirstAttribute(); + while (attributeColorVector) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeColorVector->Name(); + std::string value = attributeColorVector->Value(); if (name == "ScaleX") { @@ -316,7 +316,7 @@ namespace cocostudio colorVector.y = atof(value.c_str()); } - attribute = attribute->Next(); + attributeColorVector = attributeColorVector->Next(); } } else if (name == "FileData") @@ -324,12 +324,12 @@ namespace cocostudio std::string texture; std::string texturePng; - auto attribute = child->FirstAttribute(); + auto attributeFileData = child->FirstAttribute(); - while (attribute) + while (attributeFileData) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeFileData->Name(); + std::string value = attributeFileData->Value(); if (name == "Path") { @@ -345,7 +345,7 @@ namespace cocostudio texture = value; } - attribute = attribute->Next(); + attributeFileData = attributeFileData->Next(); } if (resourceType == 1) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp index 23ff6f16b5..810f4d1f26 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp @@ -98,12 +98,12 @@ namespace cocostudio if (name == "FileData") { - const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); + const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute(); - while (attribute) + while (attributeFileData) { - name = attribute->Name(); - std::string value = attribute->Value(); + name = attributeFileData->Name(); + std::string value = attributeFileData->Value(); if (name == "Path") { @@ -112,7 +112,7 @@ namespace cocostudio filename = convert; } - attribute = attribute->Next(); + attributeFileData = attributeFileData->Next(); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 7e462d7033..211a0e918f 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -779,7 +779,7 @@ namespace cocostudio //assume versionString is like "2.0.6.0" if (versionString.length() > 0) { - int p1, p2, p3, v1, v2, v3; + size_t p1, p2, p3, v1, v2, v3; p1 = p2 = p3 = v1 = v2 = v3 = 0; p1 = versionString.find('.'); if (p1 > 0) From 2348e5c2473aee048243a28b061a97644a677cab Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 29 Dec 2014 18:45:55 +0800 Subject: [PATCH 7/9] optimize rendering code --- cocos/renderer/CCRenderer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index 6479b54d08..3d91197989 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -595,8 +595,7 @@ void Renderer::fillQuads(const QuadCommand *cmd) for(ssize_t i=0; i< cmd->getQuadCount() * 4; ++i) { - V3F_C4B_T2F *q = &_quadVerts[i + _numberQuads * 4]; - Vec3 *vec1 = (Vec3*)&q->vertices; + Vec3 *vec1 = (Vec3*)&(_quadVerts[i + _numberQuads * 4].vertices); modelView.transformPoint(vec1); } From ffd7c30c8739381891785fb380aa8917b82a6f8e Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 30 Dec 2014 10:09:56 +0800 Subject: [PATCH 8/9] Polish restart implementation --- cocos/base/CCDirector.cpp | 95 +++++-------------- cocos/base/CCDirector.h | 2 + .../lua-bindings/manual/CCLuaEngine.cpp | 7 -- extensions/assets-manager/Manifest.h | 2 +- 4 files changed, 28 insertions(+), 78 deletions(-) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 3d0a7f0dc1..06418e1e39 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -947,17 +947,22 @@ void Director::end() _purgeDirectorInNextLoop = true; } -void Director::purgeDirector() +void Director::restart() +{ + _restartDirectorInNextLoop = true; +} + +void Director::reset() { // cleanup scheduler getScheduler()->unscheduleAll(); - // Disable event dispatching + // Remove all events if (_eventDispatcher) { - _eventDispatcher->setEnabled(false); + _eventDispatcher->removeAllEventListeners(); } - + if (_runningScene) { _runningScene->onExit(); @@ -967,22 +972,22 @@ void Director::purgeDirector() _runningScene = nullptr; _nextScene = nullptr; - + // remove all objects, but don't release it. // runWithScene might be executed after 'end'. _scenesStack.clear(); - + stopAnimation(); - + CC_SAFE_RELEASE_NULL(_FPSLabel); CC_SAFE_RELEASE_NULL(_drawnBatchesLabel); CC_SAFE_RELEASE_NULL(_drawnVerticesLabel); - + // purge bitmap cache FontFNT::purgeCachedData(); - + FontFreeType::shutdownFreeType(); - + // purge all managed caches #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) @@ -1003,13 +1008,18 @@ void Director::purgeDirector() GLProgramStateCache::destroyInstance(); FileUtils::destroyInstance(); AsyncTaskPool::destoryInstance(); - + // cocos2d-x specific data structures UserDefault::destroyInstance(); GL::invalidateStateCache(); destroyTextureCache(); +} + +void Director::purgeDirector() +{ + reset(); CHECK_GL_ERROR_DEBUG(); @@ -1024,72 +1034,17 @@ void Director::purgeDirector() release(); } -void Director::restart() -{ - _restartDirectorInNextLoop = true; -} - void Director::restartDirector() { - // cleanup scheduler - getScheduler()->unscheduleAll(); - // Disable event dispatching - if (_eventDispatcher) - { - _eventDispatcher->setEnabled(false); - } + reset(); - if (_runningScene) - { - _runningScene->onExit(); - _runningScene->cleanup(); - _runningScene->release(); - } - - _runningScene = nullptr; - _nextScene = nullptr; - - // remove all objects, but don't release it. - // runWithScene might be executed after 'end'. - _scenesStack.clear(); - - stopAnimation(); - - CC_SAFE_RELEASE_NULL(_FPSLabel); - CC_SAFE_RELEASE_NULL(_drawnBatchesLabel); - CC_SAFE_RELEASE_NULL(_drawnVerticesLabel); - - // purge bitmap cache - FontFNT::purgeCachedData(); - - FontFreeType::shutdownFreeType(); - - // purge all managed caches - AnimationCache::destroyInstance(); - SpriteFrameCache::destroyInstance(); - GLProgramCache::destroyInstance(); - GLProgramStateCache::destroyInstance(); - std::vector searchPaths; - FileUtils::getInstance()->setSearchPaths(searchPaths); - FileUtils::getInstance()->purgeCachedEntries(); - - // cocos2d-x specific data structures - UserDefault::destroyInstance(); - - GL::invalidateStateCache(); - - //destroyTextureCache(); - _textureCache->removeAllTextures(); - - // Disable event dispatching - if (_eventDispatcher) - { - _eventDispatcher->setEnabled(true); - } + // Texture cache need to be reinitialized + initTextureCache(); // release the objects PoolManager::getInstance()->getCurrentPool()->clear(); + // Real restart in script level #if CC_ENABLE_SCRIPT_BINDING ScriptEvent scriptEvent(kRestartGame, NULL); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index 442037a0b6..93c209c4d0 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -400,6 +400,8 @@ public: void resetMatrixStack(); protected: + void reset(); + void purgeDirector(); bool _purgeDirectorInNextLoop; // this flag will be set to true in end() diff --git a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp index 914ef385db..6a114d5b40 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp @@ -256,13 +256,6 @@ int LuaEngine::sendEvent(ScriptEvent* evt) return handlerControlEvent(evt->data); } break; - case kRestartGame: - { - // TODO: Clean up the LUA VM - //cleanup(); - CCApplication::getInstance()->applicationDidFinishLaunching(); - return 0; - } default: break; } diff --git a/extensions/assets-manager/Manifest.h b/extensions/assets-manager/Manifest.h index f807cabb5a..34700040a2 100644 --- a/extensions/assets-manager/Manifest.h +++ b/extensions/assets-manager/Manifest.h @@ -97,7 +97,7 @@ public: /** @brief Get the search paths list related to the Manifest. */ - std::vector getSearchPaths(); + std::vector getSearchPaths() const; protected: From 5755cc69e9b6ae8b1e2e5fd00bc07fd97560d80f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 30 Dec 2014 10:11:30 +0800 Subject: [PATCH 9/9] Fix a small compilation issue --- extensions/assets-manager/Manifest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/assets-manager/Manifest.cpp b/extensions/assets-manager/Manifest.cpp index fb0d97acec..90f57327d5 100644 --- a/extensions/assets-manager/Manifest.cpp +++ b/extensions/assets-manager/Manifest.cpp @@ -234,7 +234,7 @@ void Manifest::genResumeAssetsList(Downloader::DownloadUnits *units) const } } -std::vector Manifest::getSearchPaths() +std::vector Manifest::getSearchPaths() const { std::vector searchPaths; searchPaths.push_back(_manifestRoot);