diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp index 6a408e324b..e7b073779b 100644 --- a/cocos2dx/platform/CCFileUtils.cpp +++ b/cocos2dx/platform/CCFileUtils.cpp @@ -333,18 +333,10 @@ NS_CC_BEGIN #endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */ -static std::map s_fullPathCache; - CCFileUtils* CCFileUtils::s_sharedFileUtils = NULL; void CCFileUtils::purgeFileUtils() { - if (s_sharedFileUtils != NULL) - { - s_sharedFileUtils->purgeCachedEntries(); - CC_SAFE_RELEASE(s_sharedFileUtils->m_pFilenameLookupDict); - } - CC_SAFE_DELETE(s_sharedFileUtils); } @@ -355,7 +347,7 @@ CCFileUtils::CCFileUtils() CCFileUtils::~CCFileUtils() { - + CC_SAFE_RELEASE(m_pFilenameLookupDict); } bool CCFileUtils::init() @@ -367,7 +359,7 @@ bool CCFileUtils::init() void CCFileUtils::purgeCachedEntries() { - s_fullPathCache.clear(); + m_fullPathCache.clear(); } unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize) @@ -502,8 +494,8 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName) } // Already Cached ? - std::map::iterator cacheIter = s_fullPathCache.find(pszFileName); - if (cacheIter != s_fullPathCache.end()) + std::map::iterator cacheIter = m_fullPathCache.find(pszFileName); + if (cacheIter != m_fullPathCache.end()) { //CCLOG("Return full path from cache: %s", cacheIter->second.c_str()); return cacheIter->second; @@ -526,7 +518,7 @@ std::string CCFileUtils::fullPathForFilename(const char* pszFileName) if (fullpath.length() > 0) { // Using the filename passed in as key. - s_fullPathCache.insert(std::pair(pszFileName, fullpath)); + m_fullPathCache.insert(std::pair(pszFileName, fullpath)); //CCLOG("Returning path: %s", fullpath.c_str()); return fullpath; } diff --git a/cocos2dx/platform/CCFileUtils.h b/cocos2dx/platform/CCFileUtils.h index 876c0db1cf..c034f8b030 100644 --- a/cocos2dx/platform/CCFileUtils.h +++ b/cocos2dx/platform/CCFileUtils.h @@ -26,6 +26,7 @@ THE SOFTWARE. #include #include +#include #include "CCPlatformMacros.h" #include "ccTypes.h" #include "ccTypeInfo.h" @@ -258,6 +259,8 @@ public: /** * Checks whether the path is an absolute path. + * @note On Android, if the parameter passed in is relative to "assets/", this method will treat it as an absolute path. + * Also on Blackberry, path starts with "app/native/Resources/" is treated as an absolute path. * * @param strPath The path that needs to be checked. */ @@ -342,10 +345,16 @@ protected: */ std::string m_strDefaultResRootPath; + /** + * The full path cache. When files are found, it will be added into this cache. It could improve the performance of file search. + */ + std::map m_fullPathCache; + /** * The singleton pointer of CCFileUtils. */ static CCFileUtils* s_sharedFileUtils; + }; // end of platform group