issue #3025: add getTextureCache() in CCdirector()

This commit is contained in:
Huabing.Xu 2013-11-07 18:52:36 +08:00
parent 14fec5ed62
commit 99546cef46
4 changed files with 50 additions and 19 deletions

View File

@ -145,6 +145,8 @@ bool Director::init(void)
_scheduler->scheduleUpdateForTarget(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
_eventDispatcher = new EventDispatcher();
//init TextureCache
initTextureCache();
// create autorelease pool
PoolManager::sharedPoolManager()->push();
@ -359,6 +361,29 @@ void Director::setOpenGLView(EGLView *pobOpenGLView)
}
}
TextureCache* Director::getTextureCache() const
{
return _textureCache;
}
void Director::initTextureCache()
{
#ifdef EMSCRIPTEN
_textureCache = new TextureCacheEmscripten();
#else
_textureCache = new TextureCache();
#endif // EMSCRIPTEN
}
void Director::destroyTextureCache()
{
if (_textureCache)
{
_textureCache->waitForQuit();
CC_SAFE_RELEASE_NULL(_textureCache);
}
}
void Director::setViewport()
{
if (_openGLView)
@ -693,7 +718,6 @@ void Director::purgeDirector()
DrawPrimitives::free();
AnimationCache::destroyInstance();
SpriteFrameCache::destroyInstance();
TextureCache::destroyInstance();
ShaderCache::destroyInstance();
FileUtils::destroyInstance();
Configuration::destroyInstance();
@ -704,6 +728,8 @@ void Director::purgeDirector()
GL::invalidateStateCache();
destroyTextureCache();
CHECK_GL_ERROR_DEBUG();
// OpenGL view

View File

@ -54,6 +54,7 @@ class Node;
class Scheduler;
class ActionManager;
class EventDispatcher;
class TextureCache;
/**
@brief Class that creates and handles the main Window and manages how
@ -137,6 +138,8 @@ public:
inline EGLView* getOpenGLView() { return _openGLView; }
void setOpenGLView(EGLView *pobOpenGLView);
TextureCache* getTextureCache() const;
inline bool isNextDeltaTimeZero() { return _nextDeltaTimeZero; }
void setNextDeltaTimeZero(bool nextDeltaTimeZero);
@ -381,6 +384,10 @@ protected:
/** calculates delta time since last time it was called */
void calculateDeltaTime();
//textureCache creation or release
void initTextureCache();
void destroyTextureCache();
protected:
/** Scheduler associated with this director
@since v2.0
@ -403,6 +410,9 @@ protected:
/* The EGLView, where everything is rendered */
EGLView *_openGLView;
//texture cache belongs to this director
TextureCache *_textureCache;
double _animationInterval;
double _oldAnimationInterval;

View File

@ -55,15 +55,7 @@ TextureCache* TextureCache::_sharedTextureCache = nullptr;
TextureCache * TextureCache::getInstance()
{
if (!_sharedTextureCache)
{
#ifdef EMSCRIPTEN
_sharedTextureCache = new TextureCacheEmscripten();
#else
_sharedTextureCache = new TextureCache();
#endif // EMSCRIPTEN
}
return _sharedTextureCache;
return Director::getInstance()->getTextureCache();
}
TextureCache::TextureCache()
@ -89,15 +81,6 @@ TextureCache::~TextureCache()
void TextureCache::destroyInstance()
{
if (_sharedTextureCache)
{
// notify sub thread to quick
_sharedTextureCache->_needQuit = true;
_sharedTextureCache->_sleepCondition.notify_one();
if (_sharedTextureCache->_loadingThread) _sharedTextureCache->_loadingThread->join();
CC_SAFE_RELEASE_NULL(_sharedTextureCache);
}
}
const char* TextureCache::description() const
@ -443,6 +426,14 @@ void TextureCache::reloadAllTextures()
#endif
}
void TextureCache::waitForQuit()
{
// notify sub thread to quick
_needQuit = true;
_sleepCondition.notify_one();
if (_loadingThread) _loadingThread->join();
}
void TextureCache::dumpCachedTextureInfo() const
{
unsigned int count = 0;

View File

@ -158,6 +158,10 @@ public:
*/
void dumpCachedTextureInfo() const;
//wait for texture cahe to quit befor destroy instance
//called by director, please do not called outside
void waitForQuit();
private:
void addImageAsyncCallBack(float dt);
void loadImage();