From 5904512ac66b92d3f25127563694334878811cd1 Mon Sep 17 00:00:00 2001 From: dualface Date: Mon, 4 Feb 2013 12:41:24 +0800 Subject: [PATCH 1/3] add CCFileUtils Lua support --- cocos2dx/platform/CCFileUtils.cpp | 21 +++++++++++++++++++ cocos2dx/platform/CCFileUtils.h | 15 +++++++++++++ .../LuaCocos2d.cpp.REMOVED.git-id | 2 +- tools/tolua++/CCFileUtils.pkg | 15 +++++++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp index 927f5669f2..1efcceaba4 100644 --- a/cocos2dx/platform/CCFileUtils.cpp +++ b/cocos2dx/platform/CCFileUtils.cpp @@ -559,6 +559,11 @@ void CCFileUtils::setSearchResolutionsOrder(const std::vector& sear } } +void CCFileUtils::addSearchResolutionsOrder(const char* order) +{ + m_searchResolutionsOrderArray.push_back(order); +} + const std::vector& CCFileUtils::getSearchResolutionsOrder() { return m_searchResolutionsOrderArray; @@ -601,6 +606,22 @@ void CCFileUtils::setSearchPaths(const std::vector& searchPaths) } } +void CCFileUtils::addSearchPath(const char* path_) +{ + std::string strPrefix; + std::string path(path_); + if (!isAbsolutePath(path)) + { // Not an absolute path + strPrefix = m_strDefaultResRootPath; + } + path = strPrefix + path; + if (path.length() > 0 && path[path.length()-1] != '/') + { + path += "/"; + } + m_searchPathArray.push_back(path); +} + void CCFileUtils::setFilenameLookupDictionary(CCDictionary* pFilenameLookupDict) { CC_SAFE_RELEASE(m_pFilenameLookupDict); diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index 5650686d9f..e5e905bf52 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -210,6 +210,14 @@ public: * @since v2.1 */ virtual void setSearchResolutionsOrder(const std::vector& searchResolutionsOrder); + + /** + * Append search order of the resources. + * + * @see setSearchResolutionsOrder(), fullPathForFilename(). + * @since v2.1 + */ + virtual void addSearchResolutionsOrder(const char* order); /** * Gets the array that contains the search order of the resources. @@ -238,6 +246,13 @@ public: */ virtual void setSearchPaths(const std::vector& searchPaths); + /** + * Add search path. + * + * @since v2.1 + */ + void addSearchPath(const char* path); + /** * Gets the array of search paths. * diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index 995852f7b8..0873884426 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -e9c1a806c486b8420ea0bfd4fd99acf5a3a983ca \ No newline at end of file +191c26cba3c327bda5db6f92d8fe63330155c461 \ No newline at end of file diff --git a/tools/tolua++/CCFileUtils.pkg b/tools/tolua++/CCFileUtils.pkg index 0b537146b5..791a206ad5 100644 --- a/tools/tolua++/CCFileUtils.pkg +++ b/tools/tolua++/CCFileUtils.pkg @@ -2,7 +2,18 @@ class CCFileUtils { static CCFileUtils* sharedFileUtils(); - std::string getWriteablePath(); - const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile); + static void purgeFileUtils(); + + void purgeCachedEntries(); + std::string fullPathForFilename(const char *pszFileName); + void loadFilenameLookupDictionaryFromFile(const char* filename); + const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile); + void addSearchResolutionsOrder(const char* order); + void addSearchPath(const char* path); + + std::string getWriteablePath(); + + void setPopupNotify(bool bNotify); + bool isPopupNotify(); }; From 610aeb28cfea063e13f3949b62ac6010d0614faf Mon Sep 17 00:00:00 2001 From: Tom Lee Date: Mon, 4 Feb 2013 01:04:54 -0800 Subject: [PATCH 2/3] Don't call release() if initWith* fails --- cocos2dx/textures/CCTexture2D.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index bb88672934..d2a052544c 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -253,7 +253,6 @@ bool CCTexture2D::initWithImage(CCImage *uiImage) if (uiImage == NULL) { CCLOG("cocos2d: CCTexture2D. Can't create Texture. UIImage is nil"); - this->release(); return false; } @@ -266,7 +265,6 @@ bool CCTexture2D::initWithImage(CCImage *uiImage) if (imageWidth > maxTextureSize || imageHeight > maxTextureSize) { CCLOG("cocos2d: WARNING: Image (%u x %u) is bigger than the supported %u x %u", imageWidth, imageHeight, maxTextureSize, maxTextureSize); - this->release(); return NULL; } @@ -526,7 +524,6 @@ bool CCTexture2D::initWithPVRTCData(const void *data, int level, int bpp, bool h if( !(CCConfiguration::sharedConfiguration()->supportsPVRTC()) ) { CCLOG("cocos2d: WARNING: PVRTC images is not supported."); - this->release(); return false; } From 4023fcc0948dc1aa37d1c8aa55ccf72b94d77eed Mon Sep 17 00:00:00 2001 From: Tom Lee Date: Mon, 4 Feb 2013 01:38:22 -0800 Subject: [PATCH 3/3] Return false instead of NULL --- cocos2dx/textures/CCTexture2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index d2a052544c..c1a34bc876 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -265,7 +265,7 @@ bool CCTexture2D::initWithImage(CCImage *uiImage) if (imageWidth > maxTextureSize || imageHeight > maxTextureSize) { CCLOG("cocos2d: WARNING: Image (%u x %u) is bigger than the supported %u x %u", imageWidth, imageHeight, maxTextureSize, maxTextureSize); - return NULL; + return false; } // always load premultiplied images