Exemplo n.º 1
0
CacheGif::~CacheGif()
{
	if(m_frameData.size() > 0)
	for(std::vector<GifSprieFrame*>::iterator iter = m_frameData.begin(); iter != m_frameData.end(); )
	{
		GifSprieFrame* sprite = *iter;
		++iter;

		uint32_t index = sprite->Index();
		std::string gifFrameName = getGifFrameName(index);

		do 
		{
			SpriteFrame* spriteFrame   = sprite->getSpriteFrame();
			CC_BREAK_IF(spriteFrame == NULL);

			bool spriteFrameInCache = SpriteFrameCache::getInstance()->getSpriteFrameByName(gifFrameName.c_str()) == spriteFrame;
            //1. just GifSprieFrame retain
            //2. CCSpriteFrameCache and GifSprieFrame retain
            //more. other gif CacheGif retain
			if(spriteFrame->getReferenceCount() == 1 || (spriteFrame->getReferenceCount() ==2 && spriteFrameInCache))
			{
				Texture2D* texture = sprite->getSpriteFrame()->getTexture();
                Director::getInstance()->getTextureCache()->removeTexture(texture);
				SpriteFrameCache::getInstance()->removeSpriteFramesFromTexture(texture);

			}
		} while (0);

		delete sprite;
	}
}
Exemplo n.º 2
0
void SpriteFrameCache::removeUnusedSpriteFrames()
{
    bool removed = false;
    std::vector<std::string> toRemoveFrames;
    
    for (auto iter = _spriteFrames.begin(); iter != _spriteFrames.end(); ++iter)
    {
        SpriteFrame* spriteFrame = iter->second;
        if( spriteFrame->getReferenceCount() == 1 )
        {
            toRemoveFrames.push_back(iter->first);
            spriteFrame->getTexture()->removeSpriteFrameCapInset(spriteFrame);
            CCLOG("cocos2d: SpriteFrameCache: removing unused frame: %s", iter->first.c_str());
            removed = true;
        }
    }

    _spriteFrames.erase(toRemoveFrames);

    // FIXME:. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
    if( removed )
    {
        _loadedFileNames->clear();
    }
}