From 1c91e73a8cfb7a3c52ef92a30c9ef51146d6e939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Wed, 7 Aug 2013 14:07:01 +0900 Subject: [PATCH 01/19] added jsb support for AssetsMAnager --- extensions/AssetsManager/AssetsManager.cpp | 40 ++++++++++++++++++++++ extensions/AssetsManager/AssetsManager.h | 20 ++++++++--- extensions/cocos-ext.h | 2 ++ tools/tojs/cocos2dx_extension.ini | 5 +-- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index ac0ca37dac..e4bc2e721d 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -88,6 +88,10 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers AssetsManager::~AssetsManager() { + if (_delegate) + { + _delegate->release(); + } if (_schedule) { _schedule->release(); @@ -479,7 +483,17 @@ void AssetsManager::deleteVersion() void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate) { + if (_delegate) + { + _delegate->release(); + } + _delegate = delegate; + + if (_delegate) + { + _delegate->retain(); + } } void AssetsManager::setConnectionTimeout(unsigned int timeout) @@ -604,4 +618,30 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg) if (manager) manager->_delegate->onSuccess(); } +AssetsManager* AssetsManager::create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback ) +{ + class DelegateProtocolImpl : public AssetsManagerDelegateProtocol + { + public : + DelegateProtocolImpl(ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback) + : errorCallback(errorCallback), progressCallback(progressCallback), successCallback(successCallback) + {} + + virtual void onError(AssetsManager::ErrorCode errorCode) { errorCallback(int(errorCode)); } + virtual void onProgress(int percent) { progressCallback(percent); } + virtual void onSuccess() { successCallback(); } + + private : + ErrorCallback errorCallback; + ProgressCallback progressCallback; + SuccessCallback successCallback; + }; + + auto* manager = new AssetsManager(packageUrl,versionFileUrl,storagePath); + auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback); + delegate->autorelease(); + manager->setDelegate(delegate); + return manager; +} + NS_CC_EXT_END; diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index b150e073e0..c9603f0188 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -26,7 +26,7 @@ #define __AssetsManager__ #include -#include + #include #include "cocos2d.h" @@ -41,7 +41,7 @@ class AssetsManagerDelegateProtocol; * The updated package should be a zip file. And there should be a file named * version in the server, which contains version code. */ -class AssetsManager +class AssetsManager : public Node { public: enum class ErrorCode @@ -77,6 +77,14 @@ public: virtual ~AssetsManager(); + typedef std::function ErrorCallback; + typedef std::function ProgressCallback; + typedef std::function SuccessCallback; + + /* @brief To access within scripting environment + */ + static AssetsManager* create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback ); + /* @brief Check out if there is a new version resource. * You may use this method before updating, then let user determine whether * he wants to update resources. @@ -172,6 +180,7 @@ private: std::list *_messageQueue; std::mutex _messageQueueMutex; }; + private: //! The path to store downloaded resources. @@ -185,16 +194,17 @@ private: std::string _downloadedVersion; - CURL *_curl; + void *_curl; + Helper *_schedule; unsigned int _connectionTimeout; - AssetsManagerDelegateProtocol *_delegate; // weak reference + AssetsManagerDelegateProtocol *_delegate; bool _isDownloading; }; -class AssetsManagerDelegateProtocol +class AssetsManagerDelegateProtocol : public Object { public: /* @brief Call back function for error diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index 716f269065..13f5d25ee5 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -56,4 +56,6 @@ #include "CCDeprecated-ext.h" +#include "AssetsManager/AssetsManager.h" + #endif /* __COCOS2D_EXT_H__ */ diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index 6a31b61f3c..6c812165bc 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions +cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common @@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control$ ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ +classes = AssetsManager.* CCBReader.* CCBAnimationManager.* Scale9Sprite Control$ ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -43,6 +43,7 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType], EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], TableView::[create (g|s)etDataSource$ (g|s)etDelegate], + AssetsManager::[setDelegate], Control::[removeHandleOfControlEvent addHandleOfControlEvent] rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager], From 3fc48ecf15a0c0e4e3f9db37acf54fc4c58a2923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Wed, 7 Aug 2013 14:36:26 +0900 Subject: [PATCH 02/19] purgeStoragePath added --- extensions/AssetsManager/AssetsManager.cpp | 33 ++++++++++++++++++++++ extensions/AssetsManager/AssetsManager.h | 5 ++++ 2 files changed, 38 insertions(+) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index e4bc2e721d..f1ac337744 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -34,8 +34,10 @@ #include #include #include +#include #endif + #include "support/zip_support/unzip.h" using namespace cocos2d; @@ -644,4 +646,35 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version return manager; } +void AssetsManager::purgeStoragePath() +{ + // Delete recorded version codes. + deleteVersion(); + + // Remove downloaded files +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) + string command = "rm -r "; + // Path may include space. + command += "\"" + _storagePath + "\""; + system(command.c_str()); + DIR *pDir = NULL; + + pDir = opendir (_storagePath.c_str()); + if (! pDir) + { + mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + } +#else + string command = "rd /s /q "; + // Path may include space. + command += "\"" + _storagePath + "\""; + system(command.c_str()); + + if ((GetFileAttributesA(_storagePath.c_str())) == INVALID_FILE_ATTRIBUTES) + { + CreateDirectoryA(_storagePath.c_str(), 0); + } +#endif +} + NS_CC_EXT_END; diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index c9603f0188..e7dcb4a88d 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -146,6 +146,11 @@ public: /* downloadAndUncompress is the entry of a new thread */ friend int assetsManagerProgressFunc(void *, double, double, double, double); + + /** @brief Initialize storage path. + */ + void purgeStoragePath(); + protected: bool downLoad(); From 31a3fd65c104c70c5efbf9859c6a6f62063221a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Thu, 8 Aug 2013 17:29:29 +0900 Subject: [PATCH 03/19] key with hash to support multiple assetsManager --- extensions/AssetsManager/AssetsManager.cpp | 69 +++++++++++++++------- extensions/AssetsManager/AssetsManager.h | 11 +++- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index f1ac337744..8060f86445 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -108,6 +108,26 @@ void AssetsManager::checkStoragePath() } } +// Multiple key names +static std::string key_with_hash( const char* prefix, const std::string& url ) +{ + char buf[256]; + sprintf(buf,"%s%zd",prefix,std::hash()(url)); + return buf; +} + +// hashed version +std::string AssetsManager::key_of_version() const +{ + return key_with_hash(KEY_OF_VERSION,_packageUrl); +} + +// hashed version +std::string AssetsManager::key_of_downloaded_version() const +{ + return key_with_hash(KEY_OF_DOWNLOADED_VERSION,_packageUrl); +} + static size_t getVersionCode(void *ptr, size_t size, size_t nmemb, void *userdata) { string *version = (string*)userdata; @@ -146,7 +166,7 @@ bool AssetsManager::checkUpdate() return false; } - string recordedVersion = UserDefault::getInstance()->getStringForKey(KEY_OF_VERSION); + string recordedVersion = UserDefault::getInstance()->getStringForKey(key_of_version().c_str()); if (recordedVersion == _version) { sendErrorMessage(ErrorCode::NO_NEW_VERSION); @@ -218,7 +238,7 @@ void AssetsManager::update() } // Is package already downloaded? - _downloadedVersion = UserDefault::getInstance()->getStringForKey(KEY_OF_DOWNLOADED_VERSION); + _downloadedVersion = UserDefault::getInstance()->getStringForKey(key_of_downloaded_version().c_str()); auto t = std::thread(&AssetsManager::downloadAndUncompress, this); t.detach(); @@ -475,12 +495,12 @@ void AssetsManager::setVersionFileUrl(const char *versionFileUrl) string AssetsManager::getVersion() { - return UserDefault::getInstance()->getStringForKey(KEY_OF_VERSION); + return UserDefault::getInstance()->getStringForKey(key_of_version().c_str()); } void AssetsManager::deleteVersion() { - UserDefault::getInstance()->setStringForKey(KEY_OF_VERSION, ""); + UserDefault::getInstance()->setStringForKey(key_of_version().c_str(), ""); } void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate) @@ -565,7 +585,7 @@ void AssetsManager::Helper::update(float dt) break; case ASSETSMANAGER_MESSAGE_RECORD_DOWNLOADED_VERSION: - UserDefault::getInstance()->setStringForKey(KEY_OF_DOWNLOADED_VERSION, + UserDefault::getInstance()->setStringForKey(((AssetsManager*)msg->obj)->key_of_downloaded_version().c_str(), ((AssetsManager*)msg->obj)->_version.c_str()); UserDefault::getInstance()->flush(); @@ -601,10 +621,10 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg) AssetsManager* manager = (AssetsManager*)msg->obj; // Record new version code. - UserDefault::getInstance()->setStringForKey(KEY_OF_VERSION, manager->_version.c_str()); + UserDefault::getInstance()->setStringForKey(manager->key_of_version().c_str(), manager->_version.c_str()); // Unrecord downloaded version code. - UserDefault::getInstance()->setStringForKey(KEY_OF_DOWNLOADED_VERSION, ""); + UserDefault::getInstance()->setStringForKey(manager->key_of_downloaded_version().c_str(), ""); UserDefault::getInstance()->flush(); // Set resource search path. @@ -646,7 +666,26 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version return manager; } -void AssetsManager::purgeStoragePath() +void AssetsManager::createStoragePath() +{ + // Remove downloaded files +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) + DIR *pDir = NULL; + + pDir = opendir (_storagePath.c_str()); + if (! pDir) + { + mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + } +#else + if ((GetFileAttributesA(_storagePath.c_str())) == INVALID_FILE_ATTRIBUTES) + { + CreateDirectoryA(_storagePath.c_str(), 0); + } +#endif +} + +void AssetsManager::destroyStoragePath() { // Delete recorded version codes. deleteVersion(); @@ -656,24 +695,12 @@ void AssetsManager::purgeStoragePath() string command = "rm -r "; // Path may include space. command += "\"" + _storagePath + "\""; - system(command.c_str()); - DIR *pDir = NULL; - - pDir = opendir (_storagePath.c_str()); - if (! pDir) - { - mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); - } + system(command.c_str()); #else string command = "rd /s /q "; // Path may include space. command += "\"" + _storagePath + "\""; system(command.c_str()); - - if ((GetFileAttributesA(_storagePath.c_str())) == INVALID_FILE_ATTRIBUTES) - { - CreateDirectoryA(_storagePath.c_str(), 0); - } #endif } diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index e7dcb4a88d..a1e81302c1 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -147,9 +147,13 @@ public: */ friend int assetsManagerProgressFunc(void *, double, double, double, double); - /** @brief Initialize storage path. + /** @brief Initializes storage path. */ - void purgeStoragePath(); + void createStoragePath(); + + /** @brief Destroys storage path. + */ + void destroyStoragePath(); protected: @@ -207,6 +211,9 @@ private: AssetsManagerDelegateProtocol *_delegate; bool _isDownloading; + + std::string key_of_version() const; + std::string key_of_downloaded_version() const; }; class AssetsManagerDelegateProtocol : public Object From eda9846e6f7aaee1e7adeac2aeb94fa6293253ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Thu, 8 Aug 2013 18:36:56 +0900 Subject: [PATCH 04/19] DelegateProtocol is weak-referenced again --- extensions/AssetsManager/AssetsManager.cpp | 21 ++++++--------------- extensions/AssetsManager/AssetsManager.h | 3 ++- tools/tojs/cocos2dx_extension.ini | 1 + 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 8060f86445..04d1fde900 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -83,6 +83,7 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers , _connectionTimeout(0) , _delegate(NULL) , _isDownloading(false) +, _shouldDeleteDelegateWhenExit(false) { checkStoragePath(); _schedule = new Helper(); @@ -90,14 +91,14 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers AssetsManager::~AssetsManager() { - if (_delegate) - { - _delegate->release(); - } if (_schedule) { _schedule->release(); } + if (_shouldDeleteDelegateWhenExit) + { + delete _delegate; + } } void AssetsManager::checkStoragePath() @@ -505,17 +506,7 @@ void AssetsManager::deleteVersion() void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate) { - if (_delegate) - { - _delegate->release(); - } - _delegate = delegate; - - if (_delegate) - { - _delegate->retain(); - } } void AssetsManager::setConnectionTimeout(unsigned int timeout) @@ -661,8 +652,8 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version auto* manager = new AssetsManager(packageUrl,versionFileUrl,storagePath); auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback); - delegate->autorelease(); manager->setDelegate(delegate); + manager->_shouldDeleteDelegateWhenExit = true; return manager; } diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index a1e81302c1..8e0bcd859a 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -211,12 +211,13 @@ private: AssetsManagerDelegateProtocol *_delegate; bool _isDownloading; + bool _shouldDeleteDelegateWhenExit; std::string key_of_version() const; std::string key_of_downloaded_version() const; }; -class AssetsManagerDelegateProtocol : public Object +class AssetsManagerDelegateProtocol { public: /* @brief Call back function for error diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index 6c812165bc..d620fb6753 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -44,6 +44,7 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], TableView::[create (g|s)etDataSource$ (g|s)etDelegate], AssetsManager::[setDelegate], + AssetsManagerDelegateProtocol::[*], Control::[removeHandleOfControlEvent addHandleOfControlEvent] rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager], From d202a6fa241416ac5b155c9cfd31aee298064ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Fri, 9 Aug 2013 14:39:40 +0900 Subject: [PATCH 05/19] applied cocos2d-x coding style --- extensions/AssetsManager/AssetsManager.cpp | 24 +++++++++++----------- extensions/AssetsManager/AssetsManager.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 04d1fde900..15acacb49e 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -118,13 +118,13 @@ static std::string key_with_hash( const char* prefix, const std::string& url ) } // hashed version -std::string AssetsManager::key_of_version() const +std::string AssetsManager::keyOfVersion() const { return key_with_hash(KEY_OF_VERSION,_packageUrl); } // hashed version -std::string AssetsManager::key_of_downloaded_version() const +std::string AssetsManager::keyOfDownloadedVersion() const { return key_with_hash(KEY_OF_DOWNLOADED_VERSION,_packageUrl); } @@ -167,7 +167,7 @@ bool AssetsManager::checkUpdate() return false; } - string recordedVersion = UserDefault::getInstance()->getStringForKey(key_of_version().c_str()); + string recordedVersion = UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str()); if (recordedVersion == _version) { sendErrorMessage(ErrorCode::NO_NEW_VERSION); @@ -239,7 +239,7 @@ void AssetsManager::update() } // Is package already downloaded? - _downloadedVersion = UserDefault::getInstance()->getStringForKey(key_of_downloaded_version().c_str()); + _downloadedVersion = UserDefault::getInstance()->getStringForKey(keyOfDownloadedVersion().c_str()); auto t = std::thread(&AssetsManager::downloadAndUncompress, this); t.detach(); @@ -496,12 +496,12 @@ void AssetsManager::setVersionFileUrl(const char *versionFileUrl) string AssetsManager::getVersion() { - return UserDefault::getInstance()->getStringForKey(key_of_version().c_str()); + return UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str()); } void AssetsManager::deleteVersion() { - UserDefault::getInstance()->setStringForKey(key_of_version().c_str(), ""); + UserDefault::getInstance()->setStringForKey(keyOfVersion().c_str(), ""); } void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate) @@ -576,7 +576,7 @@ void AssetsManager::Helper::update(float dt) break; case ASSETSMANAGER_MESSAGE_RECORD_DOWNLOADED_VERSION: - UserDefault::getInstance()->setStringForKey(((AssetsManager*)msg->obj)->key_of_downloaded_version().c_str(), + UserDefault::getInstance()->setStringForKey(((AssetsManager*)msg->obj)->keyOfDownloadedVersion().c_str(), ((AssetsManager*)msg->obj)->_version.c_str()); UserDefault::getInstance()->flush(); @@ -612,10 +612,10 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg) AssetsManager* manager = (AssetsManager*)msg->obj; // Record new version code. - UserDefault::getInstance()->setStringForKey(manager->key_of_version().c_str(), manager->_version.c_str()); + UserDefault::getInstance()->setStringForKey(manager->keyOfVersion().c_str(), manager->_version.c_str()); // Unrecord downloaded version code. - UserDefault::getInstance()->setStringForKey(manager->key_of_downloaded_version().c_str(), ""); + UserDefault::getInstance()->setStringForKey(manager->keyOfDownloadedVersion().c_str(), ""); UserDefault::getInstance()->flush(); // Set resource search path. @@ -661,10 +661,10 @@ void AssetsManager::createStoragePath() { // Remove downloaded files #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) - DIR *pDir = NULL; + DIR *dir = NULL; - pDir = opendir (_storagePath.c_str()); - if (! pDir) + dir = opendir (_storagePath.c_str()); + if (!dir) { mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); } diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index 8e0bcd859a..6229ba8934 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -213,8 +213,8 @@ private: bool _isDownloading; bool _shouldDeleteDelegateWhenExit; - std::string key_of_version() const; - std::string key_of_downloaded_version() const; + std::string keyOfVersion() const; + std::string keyOfDownloadedVersion() const; }; class AssetsManagerDelegateProtocol From 200a1ec8312d25917f85e430eb6a9717dbaa3e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Fri, 16 Aug 2013 19:03:27 +0900 Subject: [PATCH 06/19] style edited --- extensions/AssetsManager/AssetsManager.cpp | 1 + .../AssetsManagerTest/Classes/AppDelegate.cpp | 26 ++++++------------- .../AssetsManagerTest/Classes/AppDelegate.h | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 15acacb49e..61b9081121 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -654,6 +654,7 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback); manager->setDelegate(delegate); manager->_shouldDeleteDelegateWhenExit = true; + manager->autorelease(); return manager; } diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp index bcb045c351..4768e7d038 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp @@ -85,8 +85,6 @@ UpdateLayer::UpdateLayer() UpdateLayer::~UpdateLayer() { - AssetsManager *pAssetsManager = getAssetsManager(); - CC_SAFE_DELETE(pAssetsManager); } void UpdateLayer::update(cocos2d::Object *pSender) @@ -141,6 +139,14 @@ bool UpdateLayer::init() { Layer::init(); + /** Creates assets manager */ + pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip", + "https://raw.github.com/minggo/AssetsManagerTest/master/version", + pathToSave.c_str()); + pAssetsManager->setDelegate(this); + pAssetsManager->setConnectionTimeout(3); + addChild(pAssetsManager); + createDownloadedDir(); Size size = Director::getInstance()->getWinSize(); @@ -164,22 +170,6 @@ bool UpdateLayer::init() return true; } -AssetsManager* UpdateLayer::getAssetsManager() -{ - static AssetsManager *pAssetsManager = NULL; - - if (! pAssetsManager) - { - pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip", - "https://raw.github.com/minggo/AssetsManagerTest/master/version", - pathToSave.c_str()); - pAssetsManager->setDelegate(this); - pAssetsManager->setConnectionTimeout(3); - } - - return pAssetsManager; -} - void UpdateLayer::createDownloadedDir() { pathToSave = FileUtils::getInstance()->getWritablePath(); diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h index a6518be098..7fcf54741d 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h @@ -60,7 +60,7 @@ public: virtual void onSuccess(); private: - cocos2d::extension::AssetsManager* getAssetsManager(); + cocos2d::extension::AssetsManager* pAssetsManager; void createDownloadedDir(); cocos2d::MenuItemFont *pItemEnter; From 95c6c66d58875354a022f0e9b56c04a886da8e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=89=E1=85=A5=E1=86=BC=E1=84=82=E1=85=A1=E1=86=A8?= =?UTF-8?q?=E1=84=92=E1=85=A9?= Date: Fri, 6 Sep 2013 16:10:11 +0900 Subject: [PATCH 07/19] * obey naming convention * hide unnecessary methods from public. --- extensions/AssetsManager/AssetsManager.cpp | 6 +++--- extensions/AssetsManager/AssetsManager.h | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 61b9081121..b1b909bce2 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -110,7 +110,7 @@ void AssetsManager::checkStoragePath() } // Multiple key names -static std::string key_with_hash( const char* prefix, const std::string& url ) +static std::string keyWithHash( const char* prefix, const std::string& url ) { char buf[256]; sprintf(buf,"%s%zd",prefix,std::hash()(url)); @@ -120,13 +120,13 @@ static std::string key_with_hash( const char* prefix, const std::string& url ) // hashed version std::string AssetsManager::keyOfVersion() const { - return key_with_hash(KEY_OF_VERSION,_packageUrl); + return keyWithHash(KEY_OF_VERSION,_packageUrl); } // hashed version std::string AssetsManager::keyOfDownloadedVersion() const { - return key_with_hash(KEY_OF_DOWNLOADED_VERSION,_packageUrl); + return keyWithHash(KEY_OF_DOWNLOADED_VERSION,_packageUrl); } static size_t getVersionCode(void *ptr, size_t size, size_t nmemb, void *userdata) diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index 6229ba8934..1a5993e364 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -147,15 +147,6 @@ public: */ friend int assetsManagerProgressFunc(void *, double, double, double, double); - /** @brief Initializes storage path. - */ - void createStoragePath(); - - /** @brief Destroys storage path. - */ - void destroyStoragePath(); - - protected: bool downLoad(); void checkStoragePath(); @@ -190,6 +181,14 @@ private: std::mutex _messageQueueMutex; }; +private: + /** @brief Initializes storage path. + */ + void createStoragePath(); + + /** @brief Destroys storage path. + */ + void destroyStoragePath(); private: //! The path to store downloaded resources. From a4ca30b9c33dc2f38ed5421d0ebc43073bd6a406 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 9 Sep 2013 02:55:48 +0000 Subject: [PATCH 08/19] [AUTO] : updating submodule reference to latest autogenerated bindings --- scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/auto-generated b/scripting/auto-generated index f966a8fc67..e57e43aaf1 160000 --- a/scripting/auto-generated +++ b/scripting/auto-generated @@ -1 +1 @@ -Subproject commit f966a8fc67e1a388b167c8b56279ff3e444b3351 +Subproject commit e57e43aaf1aea16ecefad50de1c7db8c401468a5 From 3a4c9f9fb0eacf69f499cc552eecbd511c90091e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=89=E1=85=A5=E1=86=BC=E1=84=82=E1=85=A1=E1=86=A8?= =?UTF-8?q?=E1=84=92=E1=85=A9?= Date: Mon, 9 Sep 2013 17:07:32 +0900 Subject: [PATCH 09/19] men leak fixed (life-cycle management was hand downed to scene-graph) --- samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp index 4768e7d038..52e45d963d 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp @@ -146,6 +146,7 @@ bool UpdateLayer::init() pAssetsManager->setDelegate(this); pAssetsManager->setConnectionTimeout(3); addChild(pAssetsManager); + pAssetsManager->release(); createDownloadedDir(); From d763de3d3cce41d071a08d126faab57f03e31c0a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 9 Sep 2013 17:49:13 +0800 Subject: [PATCH 11/19] new shader test code --- .../Classes/ShaderTest/ShaderTest2.cpp | 535 ++++++++++++++++++ .../TestCpp/Classes/ShaderTest/ShaderTest2.h | 88 +++ samples/Cpp/TestCpp/Classes/controller.cpp | 1 + samples/Cpp/TestCpp/Classes/tests.h | 1 + .../project.pbxproj.REMOVED.git-id | 2 +- 5 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp create mode 100644 samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp new file mode 100644 index 0000000000..ce0043c355 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -0,0 +1,535 @@ +#include "ShaderTest2.h" +#include "ShaderTest.h" +#include "../testResource.h" +#include "cocos2d.h" + +namespace ShaderTest2 +{ + static std::function createFunctions[] = + { + CL(NormalSpriteTest), + CL(GreyScaleSpriteTest), + CL(BlurSpriteTest), + CL(NoiseSpriteTest), + CL(EdgeDetectionSpriteTest), + CL(BloomSpriteTest), + CL(CelShadingSpriteTest), + CL(FlameTest3) + }; + + static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]); + + static int sceneIdx=-1; + Layer* createTest(int index) + { + auto layer = (createFunctions[index])();; + + if (layer) + { + layer->autorelease(); + } + + return layer; + } + + Layer* nextAction(); + Layer* backAction(); + Layer* restartAction(); + + Layer* nextAction() + { + sceneIdx++; + sceneIdx = sceneIdx % TEST_CASE_COUNT; + + return createTest(sceneIdx); + } + + Layer* backAction() + { + sceneIdx--; + if( sceneIdx < 0 ) + sceneIdx = TEST_CASE_COUNT -1; + + return createTest(sceneIdx); + } + + Layer* restartAction() + { + return createTest(sceneIdx); + } + +} + +ShaderTestDemo2::ShaderTestDemo2() +{ + +} + +void ShaderTestDemo2::backCallback(Object* sender) +{ + auto s = new ShaderTestScene2(); + s->addChild( ShaderTest2::backAction() ); + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestDemo2::nextCallback(Object* sender) +{ + auto s = new ShaderTestScene2();//CCScene::create(); + s->addChild( ShaderTest2::nextAction() ); + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestDemo2::restartCallback(Object* sender) +{ + auto s = new ShaderTestScene2(); + s->addChild(ShaderTest2::restartAction()); + + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestScene2::runThisTest() +{ + auto layer = ShaderTest2::nextAction(); + addChild(layer); + Director::getInstance()->replaceScene(this); +} + +template +class ShaderSpriteCreator +{ +public: + static spriteType* createSprite(const char* pszFileName) + { + spriteType* pRet = new spriteType(); + if (pRet && pRet->initWithFile(pszFileName)) + { + pRet->autorelease(); + } + else + { + CC_SAFE_DELETE(pRet); + } + return pRet; + } +}; + +class ShaderSprite : public Sprite +{ +public: + ShaderSprite(); + ~ShaderSprite(); + + bool initWithTexture(Texture2D* texture, const Rect& rect); + void draw(); + void initProgram(); + void listenBackToForeground(Object *obj); + +protected: + virtual void buildCustomUniforms() = 0; + virtual void setCustomUniforms() = 0; +protected: + std::string _fragSourceFile; + +}; + +ShaderSprite::ShaderSprite() +{ +} + +ShaderSprite::~ShaderSprite() +{ + NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +} + +void ShaderSprite::listenBackToForeground(Object *obj) +{ + setShaderProgram(NULL); + initProgram(); +} + +bool ShaderSprite::initWithTexture(Texture2D* texture, const Rect& rect) +{ + if( Sprite::initWithTexture(texture, rect) ) + { + NotificationCenter::getInstance()->addObserver(this, + callfuncO_selector(ShaderSprite::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); + + this->initProgram(); + + return true; + } + + return false; +} + +void ShaderSprite::initProgram() +{ + GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( + FileUtils::getInstance()->fullPathForFilename(_fragSourceFile.c_str()).c_str())->getCString(); + auto pProgram = new GLProgram(); + pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); + setShaderProgram(pProgram); + pProgram->release(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->link(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->updateUniforms(); + + CHECK_GL_ERROR_DEBUG(); + + buildCustomUniforms(); + + CHECK_GL_ERROR_DEBUG(); +} + +void ShaderSprite::draw() +{ + GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); + BlendFunc blend = getBlendFunc(); + GL::blendFunc(blend.src, blend.dst); + + getShaderProgram()->use(); + getShaderProgram()->setUniformsForBuiltins(); + setCustomUniforms(); + + GL::bindTexture2D( getTexture()->getName()); + + // + // Attributes + // +#define kQuadSize sizeof(_quad.bl) + long offset = (long)&_quad; + + // vertex + int diff = offsetof( V3F_C4B_T2F, vertices); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); + + // texCoods + diff = offsetof( V3F_C4B_T2F, texCoords); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); + + // color + diff = offsetof( V3F_C4B_T2F, colors); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); + + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + CC_INCREMENT_GL_DRAWS(1); +} + +class NormalSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + NormalSprite(); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +NormalSprite::NormalSprite() +{ + _fragSourceFile = "Shaders/example_normal.fsh"; +} + +void NormalSprite::buildCustomUniforms() +{ + +} + +void NormalSprite::setCustomUniforms() +{ + +} + +class GreyScaleSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + GreyScaleSprite(); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +GreyScaleSprite::GreyScaleSprite() +{ + _fragSourceFile = "Shaders/example_greyScale.fsh"; +} + +void GreyScaleSprite::buildCustomUniforms() +{ + +} + +void GreyScaleSprite::setCustomUniforms() +{ + +} + +class BlurSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + BlurSprite(); + void setBlurSize(float f); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +protected: + Point blur_; + GLfloat sub_[4]; + + GLuint blurLocation; + GLuint subLocation; +}; + +BlurSprite::BlurSprite() +{ + _fragSourceFile = "Shaders/example_Blur.fsh"; +} + +void BlurSprite::buildCustomUniforms() +{ + auto s = getTexture()->getContentSizeInPixels(); + + blur_ = Point(1/s.width, 1/s.height); + sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0; + + subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); + blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); +} + +void BlurSprite::setCustomUniforms() +{ + + getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); + getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); +} + +void BlurSprite::setBlurSize(float f) +{ + auto s = getTexture()->getContentSizeInPixels(); + + blur_ = Point(1/s.width, 1/s.height); + blur_ = blur_ * f; +} + +class NoiseSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + NoiseSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +NoiseSprite::NoiseSprite() +{ + _fragSourceFile = "Shaders/example_Noisy.fsh"; +} + +void NoiseSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void NoiseSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class EdgeDetectionSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + EdgeDetectionSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +EdgeDetectionSprite::EdgeDetectionSprite() +{ + _fragSourceFile = "Shaders/example_edgeDetection.fsh"; +} + +void EdgeDetectionSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void EdgeDetectionSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class BloomSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + BloomSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +BloomSprite::BloomSprite() +{ + _fragSourceFile = "Shaders/example_bloom.fsh"; +} + +void BloomSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void BloomSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class CelShadingSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + CelShadingSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +CelShadingSprite::CelShadingSprite() +{ + _fragSourceFile = "Shaders/example_celShading.fsh"; +} + +void CelShadingSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void CelShadingSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +NormalSpriteTest::NormalSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + NormalSprite* sprite = NormalSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } + +} + +GreyScaleSpriteTest::GreyScaleSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + GreyScaleSprite* sprite = GreyScaleSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } + +} + +BlurSpriteTest::BlurSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + BlurSprite* sprite = BlurSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setBlurSize(1.5); + addChild(sprite); + } + +} + +NoiseSpriteTest::NoiseSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + NoiseSprite* sprite = NoiseSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +EdgeDetectionSpriteTest::EdgeDetectionSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + EdgeDetectionSprite* sprite = EdgeDetectionSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +BloomSpriteTest::BloomSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + BloomSprite* sprite = BloomSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +CelShadingSpriteTest::CelShadingSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h new file mode 100644 index 0000000000..b284540075 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -0,0 +1,88 @@ +#ifndef _SHADER_TEST2_H_ +#define _SHADER_TEST2_H_ +#include "../testBasic.h" +#include "cocos-ext.h" +#include "../BaseTest.h" + +USING_NS_CC_EXT; + +class ShaderTestDemo2 : public BaseTest +{ +public: + ShaderTestDemo2(void); + virtual std::string title() { return "New Shader Test!";} + void restartCallback(Object* sender); + void nextCallback(Object* sender); + void backCallback(Object* sender); + + CREATE_FUNC(ShaderTestDemo2); +}; + +class ShaderTestScene2 : public TestScene +{ +public: + virtual void runThisTest(); +}; + + + +class NormalSpriteTest : public ShaderTestDemo2 +{ +public: + NormalSpriteTest(); + + virtual std::string subtitle() {return "NormalSpriteTest";} +}; + +class GreyScaleSpriteTest : public ShaderTestDemo2 +{ +public: + GreyScaleSpriteTest(); + + virtual std::string subtitle() {return "GreyScaleSpriteTest";} +}; + +class BlurSpriteTest : public ShaderTestDemo2 +{ +public: + BlurSpriteTest(); + + virtual std::string subtitle() {return "BlurSpriteTest";} +}; + +class NoiseSpriteTest : public ShaderTestDemo2 +{ +public: + NoiseSpriteTest(); + virtual std::string subtitle() {return "NoiseSpriteTest";} +}; + +class EdgeDetectionSpriteTest : public ShaderTestDemo2 +{ +public: + EdgeDetectionSpriteTest(); + virtual std::string subtitle() {return "EdgeDetectionSpriteTest";} +}; + +class BloomSpriteTest : public ShaderTestDemo2 +{ +public: + BloomSpriteTest(); + virtual std::string subtitle() {return "BloomSpriteTest";} +}; + +class CelShadingSpriteTest : public ShaderTestDemo2 +{ +public: + CelShadingSpriteTest(); + virtual std::string subtitle() {return "CelShadingSpriteTest";} +}; + +class FlameTest3 : public ShaderTestDemo2 +{ +public: + FlameTest3() {} + virtual std::string subtitle() {return "FlameTest3";} +}; + +#endif \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 26971f6452..cd2f4e02b0 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -70,6 +70,7 @@ struct { { "SceneTest", [](){return new SceneTestScene();} }, { "SchedulerTest", [](){return new SchedulerTestScene(); } }, { "ShaderTest", []() { return new ShaderTestScene(); } }, + { "NewShaderTest", []() { return new ShaderTestScene2(); } }, { "SpineTest", []() { return new SpineTestScene(); } }, { "SpriteTest", [](){return new SpriteTestScene(); } }, { "TextInputTest", [](){return new TextInputTestScene(); } }, diff --git a/samples/Cpp/TestCpp/Classes/tests.h b/samples/Cpp/TestCpp/Classes/tests.h index ea26d0223c..7bf7893a75 100644 --- a/samples/Cpp/TestCpp/Classes/tests.h +++ b/samples/Cpp/TestCpp/Classes/tests.h @@ -52,6 +52,7 @@ #include "TextureCacheTest/TextureCacheTest.h" #include "NodeTest/NodeTest.h" #include "ShaderTest/ShaderTest.h" +#include "ShaderTest/ShaderTest2.h" #include "ExtensionsTest/ExtensionsTest.h" #include "MutiTouchTest/MutiTouchTest.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 42c17a6004..6e2a278b84 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -d36d2542f8c085962b01d856a008b085589e62e6 \ No newline at end of file +03e60de189259aa934135a3492ddbe49112cda61 \ No newline at end of file From 8a86a883d0901250c7f469c8857c1009063c0cc0 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 9 Sep 2013 21:33:01 +0800 Subject: [PATCH 12/19] issue #2782: update mac version, update test case title --- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp | 1 - samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h | 2 +- samples/Cpp/TestCpp/Classes/controller.cpp | 2 +- samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index ce0043c355..df59d624bc 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -532,4 +532,3 @@ CelShadingSpriteTest::CelShadingSpriteTest() addChild(sprite); } } - diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h index b284540075..af41389ff8 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -10,7 +10,7 @@ class ShaderTestDemo2 : public BaseTest { public: ShaderTestDemo2(void); - virtual std::string title() { return "New Shader Test!";} + virtual std::string title() { return "Shader Sprite!";} void restartCallback(Object* sender); void nextCallback(Object* sender); void backCallback(Object* sender); diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index cd2f4e02b0..7bb555beef 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -70,7 +70,7 @@ struct { { "SceneTest", [](){return new SceneTestScene();} }, { "SchedulerTest", [](){return new SchedulerTestScene(); } }, { "ShaderTest", []() { return new ShaderTestScene(); } }, - { "NewShaderTest", []() { return new ShaderTestScene2(); } }, + { "ShaderTestSprite", []() { return new ShaderTestScene2(); } }, { "SpineTest", []() { return new SpineTestScene(); } }, { "SpriteTest", [](){return new SpriteTestScene(); } }, { "TextInputTest", [](){return new TextInputTestScene(); } }, diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index b0a731cd10..c40efdcb3c 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -fe014a4c9bc5fb6471d516b0e288b0287708c53c \ No newline at end of file +9ee8407529629a345665ab3dccf235c1e7acff22 \ No newline at end of file From 31e3faaa4f7e9bc6b52fb22c1917aa576c5f3425 Mon Sep 17 00:00:00 2001 From: Nako Sung Date: Mon, 9 Sep 2013 22:38:37 +0900 Subject: [PATCH 13/19] Update AppDelegate.cpp --- samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp index 6f747004dc..8dadda36ac 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp @@ -92,7 +92,7 @@ void UpdateLayer::update(cocos2d::Object *pSender) pProgressLabel->setString(""); // update resources - getAssetsManager()->update(); + pAssetsManager->update(); isUpdateItemClicked = true; } @@ -114,7 +114,7 @@ void UpdateLayer::reset(cocos2d::Object *pSender) system(command.c_str()); #endif // Delete recorded version codes. - getAssetsManager()->deleteVersion(); + pAssetsManager->deleteVersion(); createDownloadedDir(); } From f2fc710f868a25dcc0424cb9c61c7713a3f8632b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 09:32:03 +0800 Subject: [PATCH 14/19] issue #2782: shadertestSprite android make file --- samples/Cpp/TestCpp/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index 68106673cd..6d4374c254 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -101,6 +101,7 @@ Classes/RotateWorldTest/RotateWorldTest.cpp \ Classes/SceneTest/SceneTest.cpp \ Classes/SchedulerTest/SchedulerTest.cpp \ Classes/ShaderTest/ShaderTest.cpp \ +Classes/ShaderTest/ShaderTest2.cpp \ Classes/SpineTest/SpineTest.cpp \ Classes/SpriteTest/SpriteTest.cpp \ Classes/TextInputTest/TextInputTest.cpp \ From 5801e9118ce29c1ce2d839dcaaab481581b1add3 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 09:38:12 +0800 Subject: [PATCH 15/19] issue #2782: remove a blank test case --- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp | 3 +-- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index df59d624bc..b386ff3500 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -13,8 +13,7 @@ namespace ShaderTest2 CL(NoiseSpriteTest), CL(EdgeDetectionSpriteTest), CL(BloomSpriteTest), - CL(CelShadingSpriteTest), - CL(FlameTest3) + CL(CelShadingSpriteTest) }; static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h index af41389ff8..99efb38240 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -78,11 +78,4 @@ public: virtual std::string subtitle() {return "CelShadingSpriteTest";} }; -class FlameTest3 : public ShaderTestDemo2 -{ -public: - FlameTest3() {} - virtual std::string subtitle() {return "FlameTest3";} -}; - #endif \ No newline at end of file From 410125feba1987a3d251e8cf5e1662982ff38318 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 10 Sep 2013 10:06:06 +0800 Subject: [PATCH 16/19] [skip ci] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2448e5be13..6d767e6f5c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -560,6 +560,7 @@ Developers: Nako Sung (nakosung) Fixing a bug that wrong logic when pass an empty std::vector to WebSocket::init. Exposing cc.RemoveSelf to JS. + exposed AssetsManager to javascript and added multiple-assetsManager support dotsquid Fixed the crash caused by improper deletion of VBOs and VAO in ParticleSystemQuad. From 54c5e63916231be6db443e7d857bdf3976de3a15 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 10 Sep 2013 02:07:54 +0000 Subject: [PATCH 17/19] [AUTO] : updating submodule reference to latest autogenerated bindings --- scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/auto-generated b/scripting/auto-generated index e57e43aaf1..d94972074f 160000 --- a/scripting/auto-generated +++ b/scripting/auto-generated @@ -1 +1 @@ -Subproject commit e57e43aaf1aea16ecefad50de1c7db8c401468a5 +Subproject commit d94972074fcba0d2595b974d52d721e1eaee5da5 From 2912260b3a026cbb278fcd047e3d78100d7cab93 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 11:00:57 +0800 Subject: [PATCH 18/19] issue #2782: shadertestSprite linux and windows version --- samples/Cpp/TestCpp/proj.linux/Makefile | 1 + samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 2 ++ samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/samples/Cpp/TestCpp/proj.linux/Makefile b/samples/Cpp/TestCpp/proj.linux/Makefile index e3b33bb427..8dd200ca1d 100644 --- a/samples/Cpp/TestCpp/proj.linux/Makefile +++ b/samples/Cpp/TestCpp/proj.linux/Makefile @@ -85,6 +85,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/SceneTest/SceneTest.cpp \ ../Classes/SchedulerTest/SchedulerTest.cpp \ ../Classes/ShaderTest/ShaderTest.cpp \ + ../Classes/ShaderTest/ShaderTest2.cpp \ ../Classes/SpriteTest/SpriteTest.cpp \ ../Classes/TextInputTest/TextInputTest.cpp \ ../Classes/Texture2dTest/Texture2dTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index d954e1eb21..3bea274854 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -158,6 +158,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + @@ -268,6 +269,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index 0580a13014..7c817c403b 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -558,6 +558,9 @@ Classes\PerformanceTest + + Classes\ShaderTest + @@ -1058,5 +1061,8 @@ Classes\LabelTest + + Classes\ShaderTest + \ No newline at end of file From 8e35e7cc273885fef432bb6926512b08cc12a4d2 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 11:45:38 +0800 Subject: [PATCH 19/19] issue #2782: shadertestSprite change test case textures and add normal sprite for comparison --- .../Classes/ShaderTest/ShaderTest2.cpp | 35 ++++++++++++++----- .../Resources/Images/stone.png.REMOVED.git-id | 1 + 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index b386ff3500..694a5b9065 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -469,8 +469,11 @@ GreyScaleSpriteTest::GreyScaleSpriteTest() { auto s = Director::getInstance()->getWinSize(); GreyScaleSprite* sprite = GreyScaleSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -481,9 +484,11 @@ BlurSpriteTest::BlurSpriteTest() { auto s = Director::getInstance()->getWinSize(); BlurSprite* sprite = BlurSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); - sprite->setBlurSize(1.5); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -494,8 +499,11 @@ NoiseSpriteTest::NoiseSpriteTest() { auto s = Director::getInstance()->getWinSize(); NoiseSprite* sprite = NoiseSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -505,8 +513,11 @@ EdgeDetectionSpriteTest::EdgeDetectionSpriteTest() { auto s = Director::getInstance()->getWinSize(); EdgeDetectionSprite* sprite = EdgeDetectionSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -515,9 +526,12 @@ BloomSpriteTest::BloomSpriteTest() if (ShaderTestDemo2::init()) { auto s = Director::getInstance()->getWinSize(); - BloomSprite* sprite = BloomSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + BloomSprite* sprite = BloomSprite::createSprite("Images/stone.png"); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/stone.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -526,8 +540,11 @@ CelShadingSpriteTest::CelShadingSpriteTest() if (ShaderTestDemo2::init()) { auto s = Director::getInstance()->getWinSize(); - CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/stone.png"); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/stone.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } diff --git a/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id new file mode 100644 index 0000000000..eadaf4c7a1 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id @@ -0,0 +1 @@ +b42f9d96ee0eba96dc53ef311c3b9b273f4456b8 \ No newline at end of file