diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 55f3e9ebc4..bce116b491 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -1037,9 +1037,6 @@ void DisplayLinkDirector::mainLoop() } else if (! _invalid) { - // invoke call back from other thread - ThreadHelper::doCallback(); - drawScene(); // release the objects diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 9853a71d28..55afd2588d 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -34,7 +34,6 @@ THE SOFTWARE. #include "ccMacros.h" #include "CCDirector.h" #include "platform/CCFileUtils.h" -#include "platform/CCThread.h" #include "ccUtils.h" #include "CCScheduler.h" #include "CCString.h" @@ -93,18 +92,6 @@ const char* TextureCache::description() const return String::createWithFormat("", _textures.size() )->getCString(); } -//Dictionary* TextureCache::snapshotTextures() -//{ -// Dictionary* pRet = new Dictionary(); -// DictElement* pElement = NULL; -// CCDICT_FOREACH(_textures, pElement) -// { -// pRet->setObject(pElement->getObject(), pElement->getStrKey()); -// } -// pRet->autorelease(); -// return pRet; -//} - void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector) { Texture2D *texture = NULL; diff --git a/cocos/2d/platform/CCThread.cpp b/cocos/2d/platform/CCThread.cpp index a7dfb54609..0a33d2ddf6 100644 --- a/cocos/2d/platform/CCThread.cpp +++ b/cocos/2d/platform/CCThread.cpp @@ -29,10 +29,6 @@ NS_CC_BEGIN // iOS and Mac already has a Thread.mm #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_MAC) -std::list>* ThreadHelper::_callbackList = new std::list>(); -std::mutex* ThreadHelper::_mutex = new std::mutex; -int ThreadHelper::_callbackNumberPerFrame = 5; - void* ThreadHelper::createAutoreleasePool() { @@ -44,42 +40,6 @@ void ThreadHelper::releaseAutoreleasePool(void* autoreleasePool) } -void ThreadHelper::runOnGLThread(std::function f) -{ - // Insert call back function - _mutex->lock(); - _callbackList->push_back(f); - _mutex->unlock(); -} - -void ThreadHelper::doCallback() -{ - _mutex->lock(); - auto iter = _callbackList->begin(); - int i = 0; - while (iter != _callbackList->end()) - { - auto f = *iter; - f(); - - ++i; - if (i >= _callbackNumberPerFrame) - { - break; - } - else - { - iter = _callbackList->erase(iter); - } - } - _mutex->unlock(); -} - -void ThreadHelper::setCallbackNumberPerFrame(int callbackNumberPerFrame) -{ - _callbackNumberPerFrame = callbackNumberPerFrame; -} - #endif NS_CC_END diff --git a/cocos/2d/platform/CCThread.h b/cocos/2d/platform/CCThread.h index 1443303312..7596d29c02 100644 --- a/cocos/2d/platform/CCThread.h +++ b/cocos/2d/platform/CCThread.h @@ -59,29 +59,6 @@ public: * @lua NA */ static void releaseAutoreleasePool(void *autoreleasePool); - - /** To run a function in gl thread. - * @js NA - * @lua NA - @since v3.0 - */ - static void runOnGLThread(std::function f); - - /** Set how many callback functions being invoked per frame. Default value is 5. - * @js NA - * @lua NA - @since v3.0 - */ - static void setCallbackNumberPerFrame(int callbackNumberPerFrame); - -private: - // This function will be call by Director to call some call back function on gl thread - static void doCallback(); - - static std::list> *_callbackList; - static std::mutex *_mutex; - // How many callback functions invoked per frame - static int _callbackNumberPerFrame; }; // end of platform group diff --git a/cocos/2d/platform/apple/CCThread.mm b/cocos/2d/platform/apple/CCThread.mm index f8c84bb77f..1d060c5028 100644 --- a/cocos/2d/platform/apple/CCThread.mm +++ b/cocos/2d/platform/apple/CCThread.mm @@ -26,10 +26,6 @@ THE SOFTWARE. NS_CC_BEGIN -std::list>* ThreadHelper::_callbackList = new std::list>(); -std::mutex* ThreadHelper::_mutex = new std::mutex; -int ThreadHelper::_callbackNumberPerFrame = 5; - void* ThreadHelper::createAutoreleasePool() { id pool = [[NSAutoreleasePool alloc] init]; @@ -41,40 +37,4 @@ void ThreadHelper::releaseAutoreleasePool(void *autoreleasePool) [(NSAutoreleasePool*)autoreleasePool release]; } -void ThreadHelper::runOnGLThread(std::function f) -{ - // Insert call back function - _mutex->lock(); - _callbackList->push_back(f); - _mutex->unlock(); -} - -void ThreadHelper::doCallback() -{ - _mutex->lock(); - auto iter = _callbackList->begin(); - int i = 0; - while (iter != _callbackList->end()) - { - auto f = *iter; - f(); - - ++i; - if (i >= _callbackNumberPerFrame) - { - break; - } - else - { - iter = _callbackList->erase(iter); - } - } - _mutex->unlock(); -} - -void ThreadHelper::setCallbackNumberPerFrame(int callbackNumberPerFrame) -{ - _callbackNumberPerFrame = callbackNumberPerFrame; -} - NS_CC_END diff --git a/extensions/assets-manager/AssetsManager.cpp b/extensions/assets-manager/AssetsManager.cpp index aefb9fc978..ef4bdc7a5b 100644 --- a/extensions/assets-manager/AssetsManager.cpp +++ b/extensions/assets-manager/AssetsManager.cpp @@ -156,7 +156,7 @@ bool AssetsManager::checkUpdate() if (res != 0) { - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ if (this->_delegate) this->_delegate->onError(ErrorCode::NETWORK); }); @@ -168,7 +168,7 @@ bool AssetsManager::checkUpdate() string recordedVersion = UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str()); if (recordedVersion == _version) { - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ if (this->_delegate) this->_delegate->onError(ErrorCode::NO_NEW_VERSION); }); @@ -191,7 +191,7 @@ void AssetsManager::downloadAndUncompress() { if (! downLoad()) break; - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ UserDefault::getInstance()->setStringForKey(this->keyOfDownloadedVersion().c_str(), this->_version.c_str()); UserDefault::getInstance()->flush(); @@ -201,14 +201,14 @@ void AssetsManager::downloadAndUncompress() // Uncompress zip file. if (! uncompress()) { - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ if (this->_delegate) this->_delegate->onError(ErrorCode::UNCOMPRESS); }); break; } - ThreadHelper::runOnGLThread([&, this] { + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this] { // Record new version code. UserDefault::getInstance()->setStringForKey(this->keyOfVersion().c_str(), this->_version.c_str()); @@ -479,7 +479,7 @@ int assetsManagerProgressFunc(void *ptr, double totalToDownload, double nowDownl if (percent != tmp) { percent = tmp; - ThreadHelper::runOnGLThread([=]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([=]{ auto manager = static_cast(ptr); if (manager->_delegate) manager->_delegate->onProgress(percent); @@ -498,7 +498,7 @@ bool AssetsManager::downLoad() FILE *fp = fopen(outFileName.c_str(), "wb"); if (! fp) { - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ if (this->_delegate) this->_delegate->onError(ErrorCode::CREATE_FILE); }); @@ -518,7 +518,7 @@ bool AssetsManager::downLoad() curl_easy_cleanup(_curl); if (res != 0) { - ThreadHelper::runOnGLThread([&, this]{ + Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ if (this->_delegate) this->_delegate->onError(ErrorCode::NETWORK); });