From faddbd8e7123eb1a4249879d9acda96a1cea39e0 Mon Sep 17 00:00:00 2001 From: XiaoFeng Date: Thu, 23 Apr 2015 16:50:28 +0800 Subject: [PATCH] Add function to texture cache for studio to check if texture have been already loaded --- cocos/2d/CCSpriteFrameCache.cpp | 12 ++++++++++++ cocos/2d/CCSpriteFrameCache.h | 9 +++++++++ cocos/renderer/CCTextureCache.cpp | 15 +++++++++++++++ cocos/renderer/CCTextureCache.h | 7 +++++++ 4 files changed, 43 insertions(+) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index 00b9eb40af..b7c5ed12ed 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -292,6 +292,18 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist) } } +bool SpriteFrameCache::isSpriteFramesWithFileLoaded(const std::string& plist) +{ + bool result = false; + + if (_loadedFileNames->find(plist) != _loadedFileNames->end()) + { + result = true; + } + + return result; +} + void SpriteFrameCache::addSpriteFrame(SpriteFrame* frame, const std::string& frameName) { _spriteFrames.insert(frameName, frame); diff --git a/cocos/2d/CCSpriteFrameCache.h b/cocos/2d/CCSpriteFrameCache.h index 05cbaee416..7b035c65ac 100644 --- a/cocos/2d/CCSpriteFrameCache.h +++ b/cocos/2d/CCSpriteFrameCache.h @@ -140,6 +140,15 @@ public: */ void addSpriteFrame(SpriteFrame *frame, const std::string& frameName); + /** Check if multiple Sprite Frames from a plist file have been loaded. + * @js NA + * @lua NA + * + * @param plist Plist file name. + * @return True if the file is loaded. + */ + bool isSpriteFramesWithFileLoaded(const std::string& plist); + /** Purges the dictionary of loaded sprite frames. * Call this method if you receive the "Memory Warning". * In the short term: it will free some resources preventing your app from being killed. diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index 239d4278e9..89f66b1ddf 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -403,6 +403,21 @@ Texture2D* TextureCache::addImage(Image *image, const std::string &key) return texture; } +bool TextureCache::isTextureLoaded(const std::string& fileName) +{ + bool result = false; + + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName); + if (fullpath.size() > 0) + { + if (_textures.find(fullpath) != _textures.end()) { + result = true; + } + } + + return result; +} + bool TextureCache::reloadTexture(const std::string& fileName) { Texture2D * texture = nullptr; diff --git a/cocos/renderer/CCTextureCache.h b/cocos/renderer/CCTextureCache.h index ac22103f4a..9ae08cb47c 100644 --- a/cocos/renderer/CCTextureCache.h +++ b/cocos/renderer/CCTextureCache.h @@ -151,6 +151,13 @@ public: Texture2D* getTextureForKey(const std::string& key) const; CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const std::string& key) const { return getTextureForKey(key); } + /** Check if texture file have already been loaded to cache. + * If the file have been loaded before, return true; otherwise return false. + * @param fileName It's the related/absolute path of the file image. + * @return True if the texture file is loaded. + */ + bool isTextureLoaded(const std::string& fileName); + /** Reload texture from the image file. * If the file image hasn't loaded before, load it. * Otherwise the texture will be reloaded from the file image.