mirror of https://github.com/axmolengine/axmol.git
offer a thread safe function to read contents of xml file, and the engine use it internal
This commit is contained in:
parent
47b7419a1e
commit
5273819e83
|
@ -141,11 +141,15 @@ CCParticleSystem * CCParticleSystem::particleWithFile(const char *plistFile)
|
|||
}
|
||||
bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||
{
|
||||
bool bRet = false;
|
||||
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(m_sPlistFile.c_str());
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
||||
|
||||
CCAssert( dict != NULL, "Particles: file not found");
|
||||
return this->initWithDictionary(dict);
|
||||
bRet = this->initWithDictionary(dict);
|
||||
dict->release();
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)
|
||||
|
|
|
@ -98,7 +98,9 @@ public:
|
|||
m_pCurDict = new CCDictionary<std::string, CCObject*>();
|
||||
if(! m_pRootDict)
|
||||
{
|
||||
// Because it will call m_pCurDict->release() later, so retain here.
|
||||
m_pRootDict = m_pCurDict;
|
||||
m_pRootDict->retain();
|
||||
}
|
||||
m_tState = SAX_DICT;
|
||||
|
||||
|
@ -120,7 +122,8 @@ public:
|
|||
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
|
||||
pPreDict->setObject(m_pCurDict, m_sCurKey);
|
||||
}
|
||||
m_pCurDict->autorelease();
|
||||
|
||||
m_pCurDict->release();
|
||||
|
||||
// record the dict state
|
||||
m_tStateStack.push(m_tState);
|
||||
|
@ -285,7 +288,15 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
|||
|
||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
CCDictMaker tMaker;
|
||||
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||
ret->autorelease();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||
{
|
||||
CCDictMaker tMaker;
|
||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,12 @@ public:
|
|||
*/
|
||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
||||
|
||||
/*
|
||||
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
||||
invoker should call release().
|
||||
*/
|
||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
||||
|
||||
/**
|
||||
@brief Get the writeable path
|
||||
@return The path that can write/read file
|
||||
|
|
|
@ -197,9 +197,11 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
|||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
||||
{
|
||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||
|
||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||
|
||||
dict->release();
|
||||
}
|
||||
|
||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
||||
|
@ -220,7 +222,7 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char*
|
|||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||
{
|
||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||
|
||||
string texturePath("");
|
||||
|
||||
|
@ -261,6 +263,8 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
|||
{
|
||||
CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
|
||||
}
|
||||
|
||||
dict->release();
|
||||
}
|
||||
|
||||
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
||||
|
@ -316,9 +320,11 @@ void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
|||
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
||||
{
|
||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
||||
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
||||
|
||||
removeSpriteFramesFromDictionary((CCDictionary<std::string, CCSpriteFrame*>*)dict);
|
||||
|
||||
dict->release();
|
||||
}
|
||||
|
||||
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary)
|
||||
|
|
Loading…
Reference in New Issue