From 2892e8be3ffce48605ca968d70709a88ba694fb1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 18 Dec 2013 14:58:17 +0800 Subject: [PATCH 01/26] Refactors Data class, adds FileUtils::getStringFromFile, FileUtils::getDataFromFile and deprecates FileUtils::getFileData. --- cocos/2d/CCFontFreeType.cpp | 9 +- cocos/2d/CCLabelBMFont.cpp | 12 +- cocos/2d/CCUserDefault.cpp | 25 ++- cocos/2d/CCUserDefault.h | 4 +- cocos/2d/CCUserDefault.mm | 36 ++--- cocos/2d/CCUserDefaultAndroid.cpp | 28 ++-- cocos/2d/TGAlib.cpp | 11 +- cocos/2d/ZipUtils.cpp | 38 ++--- cocos/2d/platform/CCFileUtils.cpp | 64 ++++++++ cocos/2d/platform/CCFileUtils.h | 15 +- cocos/2d/platform/CCImageCommon_cpp.h | 26 ++- cocos/2d/platform/CCSAXParser.cpp | 11 +- .../platform/android/CCFileUtilsAndroid.cpp | 153 +++++++++++++++--- .../2d/platform/android/CCFileUtilsAndroid.h | 23 ++- cocos/2d/platform/win32/CCFileUtilsWin32.cpp | 72 +++++++++ cocos/2d/platform/win32/CCFileUtilsWin32.h | 14 +- cocos/base/CCData.cpp | 72 +++++++-- cocos/base/CCData.h | 67 ++++---- cocos/base/CCDataVisitor.cpp | 12 -- cocos/base/CCDataVisitor.h | 3 - cocos/base/CCString.cpp | 9 +- .../editor-support/cocosbuilder/CCBReader.cpp | 15 +- cocos/editor-support/cocosbuilder/CCBReader.h | 4 +- .../cocosbuilder/CCNodeLoader.cpp | 14 +- 24 files changed, 499 insertions(+), 238 deletions(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 2f9de7861a..8c2e6ddeb7 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -102,7 +102,14 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) FT_Face face; ssize_t len = 0; - _ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len); + Data data = FileUtils::getInstance()->getDataFromFile(fontName); + _ttfData = data.getBytes(); + len = data.getSize(); + + // The data needs to be saved in this class, + // to prevent the buffer is freed in the destructor of Data, we should reset the buffer pointer by Data::fastSet. + data.fastSet(nullptr, 0); + if (!_ttfData) return false; diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 5d1716ada8..41581b6cd7 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -184,13 +184,13 @@ std::set* CCBMFontConfiguration::parseConfigFile(const std::string { std::string fullpath = FileUtils::getInstance()->fullPathForFilename(controlFile); - String *contents = String::createWithContentsOfFile(fullpath.c_str()); - - CCASSERT(contents, "CCBMFontConfiguration::parseConfigFile | Open file error."); + std::string contents = FileUtils::getInstance()->getStringFromFile(fullpath); - set *validCharsString = new set(); + CCASSERT(!contents.empty(), "CCBMFontConfiguration::parseConfigFile | Open file error."); + + std::set *validCharsString = new std::set(); - if (!contents) + if (contents.empty()) { CCLOG("cocos2d: Error parsing FNTfile %s", controlFile.c_str()); return NULL; @@ -198,7 +198,7 @@ std::set* CCBMFontConfiguration::parseConfigFile(const std::string // parse spacing / padding std::string line; - std::string strLeft = contents->getCString(); + std::string strLeft(contents); while (strLeft.length() > 0) { size_t pos = strLeft.find('\n'); diff --git a/cocos/2d/CCUserDefault.cpp b/cocos/2d/CCUserDefault.cpp index c01db753bf..0174fb5a26 100644 --- a/cocos/2d/CCUserDefault.cpp +++ b/cocos/2d/CCUserDefault.cpp @@ -57,17 +57,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle { tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; - //CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt"); - ssize_t nSize; - char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize); - //const char* pXmlBuffer = (const char*)data.getBuffer(); - if(NULL == pXmlBuffer) + + std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath()); + + if (xmlBuffer.empty()) { CCLOG("can not read xml file"); break; } - xmlDoc->Parse(pXmlBuffer, nSize); - free(pXmlBuffer); + xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size()); + // get root node *rootNode = xmlDoc->RootElement(); if (NULL == *rootNode) @@ -295,12 +294,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul return ret; } -Data* UserDefault::getDataForKey(const char* pKey) +Data UserDefault::getDataForKey(const char* pKey) { - return getDataForKey(pKey, NULL); + return getDataForKey(pKey, Data::Null); } -Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) +Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) { const char* encodedData = NULL; tinyxml2::XMLElement* rootNode; @@ -313,7 +312,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) encodedData = (const char*)(node->FirstChild()->Value()); } - Data* ret = defaultValue; + Data ret = defaultValue; if (encodedData) { @@ -321,9 +320,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData); if (decodedData) { - ret = Data::create(decodedData, decodedDataLen); - - free(decodedData); + ret.fastSet(decodedData, decodedDataLen); } } diff --git a/cocos/2d/CCUserDefault.h b/cocos/2d/CCUserDefault.h index a18fb00b6a..1ec14f32b3 100644 --- a/cocos/2d/CCUserDefault.h +++ b/cocos/2d/CCUserDefault.h @@ -110,12 +110,12 @@ public: * @js NA * @lua NA */ - Data* getDataForKey(const char* pKey); + Data getDataForKey(const char* pKey); /** * @js NA * @lua NA */ - Data* getDataForKey(const char* pKey, Data* defaultValue); + Data getDataForKey(const char* pKey, const Data& defaultValue); // set value methods diff --git a/cocos/2d/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm index 09cc5aec1c..bf688cb023 100644 --- a/cocos/2d/CCUserDefault.mm +++ b/cocos/2d/CCUserDefault.mm @@ -73,16 +73,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc { tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; - ssize_t size; - char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size); - //const char* pXmlBuffer = (const char*)data.getBuffer(); - if(NULL == pXmlBuffer) + + std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath()); + + if (xmlBuffer.empty()) { NSLog(@"can not read xml file"); break; } - xmlDoc->Parse(pXmlBuffer); - free(pXmlBuffer); + xmlDoc->Parse(xmlBuffer.c_str(), xmlBuffer.size()); + // get root node rootNode = xmlDoc->RootElement(); if (NULL == rootNode) @@ -370,12 +370,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul } } -Data* UserDefault::getDataForKey(const char* pKey) +Data UserDefault::getDataForKey(const char* pKey) { - return getDataForKey(pKey, NULL); + return getDataForKey(pKey, Data::Null); } -Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) +Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) { #ifdef KEEP_COMPATABILITY tinyxml2::XMLDocument* doc = NULL; @@ -389,13 +389,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData); if (decodedData) { - Data *ret = Data::create(decodedData, decodedDataLen); + Data ret; + ret.fastSet(decodedData, decodedDataLen); // set value in NSUserDefaults setDataForKey(pKey, ret); - free(decodedData); - flush(); // delete xmle node @@ -419,17 +418,8 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) } else { - unsigned char *bytes = {0}; - int size = 0; - - if (data.length > 0) { - bytes = (unsigned char*)data.bytes; - size = static_cast(data.length); - } - Data *ret = new Data(bytes, size); - - ret->autorelease(); - + Data ret; + ret.copy((unsigned char*)data.bytes, data.length); return ret; } } diff --git a/cocos/2d/CCUserDefaultAndroid.cpp b/cocos/2d/CCUserDefaultAndroid.cpp index 7a381aa634..07ec506717 100644 --- a/cocos/2d/CCUserDefaultAndroid.cpp +++ b/cocos/2d/CCUserDefaultAndroid.cpp @@ -342,12 +342,12 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul return getStringForKeyJNI(pKey, defaultValue.c_str()); } -Data* UserDefault::getDataForKey(const char* pKey) +Data UserDefault::getDataForKey(const char* pKey) { - return getDataForKey(pKey, NULL); + return getDataForKey(pKey, Data::Null); } -Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) +Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) { #ifdef KEEP_COMPATABILITY tinyxml2::XMLDocument* doc = NULL; @@ -362,12 +362,12 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) int decodedDataLen = base64Decode((unsigned char*)encodedData, (unsigned int)strlen(encodedData), &decodedData); if (decodedData) { - Data *ret = Data::create(decodedData, decodedDataLen); + Data ret; + ret.fastSet(decodedData, decodedDataLen); // set value in NSUserDefaults setDataForKey(pKey, ret); - free(decodedData); flush(); // delete xmle node @@ -385,7 +385,7 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) #endif char * encodedDefaultData = NULL; - unsigned int encodedDefaultDataLen = defaultValue ? base64Encode(defaultValue->getBytes(), defaultValue->getSize(), &encodedDefaultData) : 0; + unsigned int encodedDefaultDataLen = !defaultValue.isNull() ? base64Encode(defaultValue.getBytes(), defaultValue.getSize(), &encodedDefaultData) : 0; string encodedStr = getStringForKeyJNI(pKey, encodedDefaultData); @@ -393,23 +393,19 @@ Data* UserDefault::getDataForKey(const char* pKey, Data* defaultValue) free(encodedDefaultData); CCLOG("ENCODED STRING: --%s--%d", encodedStr.c_str(), encodedStr.length()); - - Data *ret = defaultValue; - + unsigned char * decodedData = NULL; int decodedDataLen = base64Decode((unsigned char*)encodedStr.c_str(), (unsigned int)encodedStr.length(), &decodedData); - CCLOG("AFTER DECoDE. ret %p defaultValue %p", ret, defaultValue); - CCLOG("DECoDED DATA: %s %d", decodedData, decodedDataLen); + CCLOG("DECODED DATA: %s %d", decodedData, decodedDataLen); if (decodedData && decodedDataLen) { - ret = Data::create(decodedData, decodedDataLen); - free(decodedData); + Data ret; + ret.fastSet(decodedData, decodedDataLen); + return ret; } - CCLOG("RETURNED %p!", ret); - - return ret; + return defaultValue; } diff --git a/cocos/2d/TGAlib.cpp b/cocos/2d/TGAlib.cpp index bd6c510e08..74003c2b5d 100644 --- a/cocos/2d/TGAlib.cpp +++ b/cocos/2d/TGAlib.cpp @@ -26,6 +26,7 @@ THE SOFTWARE. #include #include "TGAlib.h" +#include "CCData.h" #include "platform/CCFileUtils.h" NS_CC_BEGIN @@ -272,15 +273,11 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size) // this is the function to call when we want to load an image tImageTGA * tgaLoad(const char *filename) { - ssize_t size = 0; - unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size); + Data data = FileUtils::getInstance()->getDataFromFile(filename); - if (buffer != nullptr) + if (!data.isNull()) { - tImageTGA* data = tgaLoadBuffer(buffer, size); - free(buffer); - - return data; + return tgaLoadBuffer(data.getBytes(), data.getSize()); } return nullptr; diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index 0a6be7e39b..09bbae8585 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -26,6 +26,7 @@ #include #include "ZipUtils.h" +#include "CCData.h" #include "ccMacros.h" #include "platform/CCFileUtils.h" #include "unzip.h" @@ -304,21 +305,15 @@ int ZipUtils::inflateGZipFile(const char *path, unsigned char **out) bool ZipUtils::isCCZFile(const char *path) { // load file into memory - unsigned char* compressed = NULL; + Data compressedData = FileUtils::getInstance()->getDataFromFile(path); - ssize_t fileLen = 0; - compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); - - if(compressed == NULL || fileLen == 0) + if (compressedData.isNull()) { CCLOG("cocos2d: ZipUtils: loading file failed"); return false; } - bool ret = isCCZBuffer(compressed, fileLen); - free(compressed); - - return ret; + return isCCZBuffer(compressedData.getBytes(), compressedData.getSize()); } bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len) @@ -336,20 +331,15 @@ bool ZipUtils::isCCZBuffer(const unsigned char *buffer, ssize_t len) bool ZipUtils::isGZipFile(const char *path) { // load file into memory - unsigned char* compressed = NULL; + Data compressedData = FileUtils::getInstance()->getDataFromFile(path); - ssize_t fileLen = 0; - compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); - - if(NULL == compressed || 0 == fileLen) + if (compressedData.isNull()) { CCLOG("cocos2d: ZipUtils: loading file failed"); return false; } - bool ret = isGZipBuffer(compressed, fileLen); - free(compressed); - return ret; + return isGZipBuffer(compressedData.getBytes(), compressedData.getSize()); } bool ZipUtils::isGZipBuffer(const unsigned char *buffer, ssize_t len) @@ -455,24 +445,18 @@ int ZipUtils::inflateCCZBuffer(const unsigned char *buffer, ssize_t bufferLen, u int ZipUtils::inflateCCZFile(const char *path, unsigned char **out) { - CCAssert(out, ""); - CCAssert(&*out, ""); + CCASSERT(out, "Invalid pointer for buffer!"); // load file into memory - unsigned char* compressed = NULL; + Data compressedData = FileUtils::getInstance()->getDataFromFile(path); - ssize_t fileLen = 0; - compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); - - if(NULL == compressed || 0 == fileLen) + if (compressedData.isNull()) { CCLOG("cocos2d: Error loading CCZ compressed file"); return -1; } - int ret = inflateCCZBuffer(compressed, fileLen, out); - free(compressed); - return ret; + return inflateCCZBuffer(compressedData.getBytes(), compressedData.getSize(), out); } void ZipUtils::setPvrEncryptionKeyPart(int index, unsigned int value) diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index fbe4aa7cb5..2cf688bceb 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -23,6 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "CCFileUtils.h" +#include "CCData.h" #include "ccMacros.h" #include "CCDirector.h" #include "CCSAXParser.h" @@ -492,6 +493,69 @@ void FileUtils::purgeCachedEntries() _fullPathCache.clear(); } +static Data getData(const std::string& filename, bool forString) +{ + CCASSERT(!filename.empty(), "Invalid filename!"); + + Data ret; + unsigned char* buffer = nullptr; + ssize_t size = 0; + const char* mode = nullptr; + if (forString) + mode = "rt"; + else + mode = "rb"; + + do + { + // Read the file from hardware + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename); + FILE *fp = fopen(fullPath.c_str(), mode); + CC_BREAK_IF(!fp); + fseek(fp,0,SEEK_END); + size = ftell(fp); + fseek(fp,0,SEEK_SET); + + if (forString) + { + buffer = (unsigned char*)malloc(sizeof(unsigned char) * (size + 1)); + buffer[size] = '\0'; + } + else + { + buffer = (unsigned char*)malloc(sizeof(unsigned char) * size); + } + + size = fread(buffer, sizeof(unsigned char), size, fp); + fclose(fp); + } while (0); + + if (nullptr == buffer || 0 == size) + { + std::string msg = "Get data from file("; + msg.append(filename).append(") failed!"); + CCLOG("%s", msg.c_str()); + } + else + { + ret.fastSet(buffer, size); + } + + return ret; +} + +std::string FileUtils::getStringFromFile(const std::string& filename) +{ + Data data = getData(filename, true); + std::string ret((const char*)data.getBytes()); + return ret; +} + +Data FileUtils::getDataFromFile(const std::string& filename) +{ + return getData(filename, false); +} + unsigned char* FileUtils::getFileData(const char* filename, const char* mode, ssize_t *size) { unsigned char * buffer = nullptr; diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index e5925e2818..764b229a67 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "CCPlatformMacros.h" #include "ccTypes.h" #include "CCValue.h" +#include "CCData.h" NS_CC_BEGIN @@ -75,6 +76,17 @@ public: */ virtual void purgeCachedEntries(); + /** + * Gets string from a file. + */ + virtual std::string getStringFromFile(const std::string& filename); + + /** + * Creates binary data from a file. + * @return A data object. + */ + virtual Data getDataFromFile(const std::string& filename); + /** * Gets resource file data * @@ -83,8 +95,9 @@ public: * @param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0. * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned. + * @deprecated Please use FileUtils::getDataFromFile or FileUtils::getStringFromFile instead. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size); + CC_DEPRECATED_ATTRIBUTE unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size); /** * Gets resource file data from a zip file. diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index 8cbafd7817..3f4d0bdc35 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -24,6 +24,7 @@ THE SOFTWARE. #include "CCImage.h" +#include "CCData.h" #include #include @@ -420,15 +421,12 @@ bool Image::initWithImageFile(const char * strPath) SDL_FreeSurface(iSurf); #else - ssize_t bufferLen = 0; - unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen); + Data data = FileUtils::getInstance()->getDataFromFile(_filePath); - if (buffer != nullptr && bufferLen > 0) + if (!data.isNull()) { - bRet = initWithImageData(buffer, bufferLen); + bRet = initWithImageData(data.getBytes(), data.getSize()); } - - free(buffer); #endif // EMSCRIPTEN return bRet; @@ -437,19 +435,15 @@ bool Image::initWithImageFile(const char * strPath) bool Image::initWithImageFileThreadSafe(const char *fullpath) { bool ret = false; - ssize_t dataLen = 0; _filePath = fullpath; -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance(); - unsigned char *buffer = fileUitls->getFileDataForAsync(fullpath, "rb", &dataLen); -#else - unsigned char *buffer = FileUtils::getInstance()->getFileData(fullpath, "rb", &dataLen); -#endif - if (buffer != NULL && dataLen > 0) + + Data data = FileUtils::getInstance()->getDataFromFile(fullpath); + + if (!data.isNull()) { - ret = initWithImageData(buffer, dataLen); + ret = initWithImageData(data.getBytes(), data.getSize()); } - free(buffer); + return ret; } diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index ccbd11a9f1..b7464d038b 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -111,16 +111,15 @@ bool SAXParser::parse(const char* pXMLData, size_t uDataLength) return tinyDoc.Accept( &printer ); } -bool SAXParser::parse(const char *pszFile) +bool SAXParser::parse(const char *filename) { bool ret = false; - ssize_t size = 0; - char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size); - if (pBuffer != NULL && size > 0) + Data data = FileUtils::getInstance()->getDataFromFile(filename); + if (!data.isNull()) { - ret = parse(pBuffer, size); + ret = parse((const char*)data.getBytes(), data.getSize()); } - free(pBuffer); + return ret; } diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp index e0ce2a3886..6e9aae8eca 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp @@ -34,13 +34,13 @@ THE SOFTWARE. using namespace std; -AAssetManager* cocos2d::FileUtilsAndroid::assetmanager = NULL; - NS_CC_BEGIN +AAssetManager* FileUtilsAndroid::assetmanager = nullptr; + void FileUtilsAndroid::setassetmanager(AAssetManager* a) { - if (NULL == a) { - LOGD("setassetmanager : received unexpected NULL parameter"); + if (nullptr == a) { + LOGD("setassetmanager : received unexpected nullptr parameter"); return; } @@ -49,13 +49,13 @@ void FileUtilsAndroid::setassetmanager(AAssetManager* a) { FileUtils* FileUtils::getInstance() { - if (s_sharedFileUtils == NULL) + if (s_sharedFileUtils == nullptr) { s_sharedFileUtils = new FileUtilsAndroid(); if(!s_sharedFileUtils->init()) { delete s_sharedFileUtils; - s_sharedFileUtils = NULL; + s_sharedFileUtils = nullptr; CCLOG("ERROR: Could not init CCFileUtilsAndroid"); } } @@ -129,19 +129,126 @@ bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const return false; } +Data FileUtilsAndroid::getData(const std::string& filename, bool forString) +{ + if (filename.empty()) + { + return Data::Null; + } + + unsigned char* data = nullptr; + ssize_t size = 0; + string fullPath = fullPathForFilename(filename); + + if (fullPath[0] != '/') + { + string relativePath = string(); + + size_t position = fullPath.find("assets/"); + if (0 == position) { + // "assets/" is at the beginning of the path and we don't want it + relativePath += fullPath.substr(strlen("assets/")); + } else { + relativePath += fullPath; + } + LOGD("relative path = %s", relativePath.c_str()); + + if (nullptr == FileUtilsAndroid::assetmanager) { + LOGD("... FileUtilsAndroid::assetmanager is nullptr"); + return Data::Null; + } + + // read asset data + AAsset* asset = + AAssetManager_open(FileUtilsAndroid::assetmanager, + relativePath.c_str(), + AASSET_MODE_UNKNOWN); + if (nullptr == asset) { + LOGD("asset is nullptr"); + return Data::Null; + } + + off_t fileSize = AAsset_getLength(asset); + + if (forString) + { + data = (unsigned char*) malloc(fileSize + 1); + data[fileSize] = '\0'; + } + else + { + data = (unsigned char*) malloc(fileSize); + } + + int bytesread = AAsset_read(asset, (void*)data, fileSize); + size = bytesread; + + AAsset_close(asset); + } + else + { + do + { + // read rrom other path than user set it + //CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename); + const char* mode = nullptr; + if (forString) + mode = "rt"; + else + mode = "rb"; + + FILE *fp = fopen(fullPath.c_str(), mode); + CC_BREAK_IF(!fp); + + long fileSize; + fseek(fp,0,SEEK_END); + fileSize = ftell(fp); + fseek(fp,0,SEEK_SET); + if (forString) + { + data = (unsigned char*) malloc(fileSize + 1); + data[fileSize] = '\0'; + } + else + { + data = (unsigned char*) malloc(fileSize); + } + fileSize = fread(data,sizeof(unsigned char), fileSize,fp); + fclose(fp); + + size = fileSize; + } while (0); + } + + Data ret; + if (data == nullptr || size == 0) + { + std::string msg = "Get data from file("; + msg.append(filename).append(") failed!"); + CCLOG("%s", msg.c_str()); + } + else + { + ret.fastSet(data, size); + } + + return ret; +} + +std::string FileUtilsAndroid::getStringFromFile(const std::string& filename) +{ + Data data = getData(filename, true); + std::string ret((const char*)data.getBytes()); + return ret; +} + +Data FileUtilsAndroid::getDataFromFile(const std::string& filename) +{ + return getData(filename, false); +} unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, ssize_t * size) { - return doGetFileData(filename, mode, size, false); -} - -unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, ssize_t * pSize) -{ - return doGetFileData(filename, pszMode, pSize, true); -} - -unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync) -{ unsigned char * data = 0; if ((! filename) || (! mode) || 0 == strlen(filename)) @@ -164,9 +271,9 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* } LOGD("relative path = %s", relativePath.c_str()); - if (NULL == FileUtilsAndroid::assetmanager) { - LOGD("... FileUtilsAndroid::assetmanager is NULL"); - return NULL; + if (nullptr == FileUtilsAndroid::assetmanager) { + LOGD("... FileUtilsAndroid::assetmanager is nullptr"); + return nullptr; } // read asset data @@ -174,9 +281,9 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* AAssetManager_open(FileUtilsAndroid::assetmanager, relativePath.c_str(), AASSET_MODE_UNKNOWN); - if (NULL == asset) { - LOGD("asset is NULL"); - return NULL; + if (nullptr == asset) { + LOGD("asset is nullptr"); + return nullptr; } off_t fileSize = AAsset_getLength(asset); @@ -196,7 +303,7 @@ unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* do { // read rrom other path than user set it - //CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename); + //CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename); FILE *fp = fopen(fullPath.c_str(), mode); CC_BREAK_IF(!fp); diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.h b/cocos/2d/platform/android/CCFileUtilsAndroid.h index 4e3c4c3125..5e1f0b0d0c 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.h +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.h @@ -55,19 +55,28 @@ public: /* override funtions */ bool init(); - virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size); + + /** @deprecated Please use FileUtils::getDataFromFile or FileUtils::getStringFromFile instead. */ + CC_DEPRECATED_ATTRIBUTE unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size); + + /** + * Gets string from a file. + */ + virtual std::string getStringFromFile(const std::string& filename) override; + + /** + * Creates binary data from a file. + * @return A data object. + */ + virtual Data getDataFromFile(const std::string& filename) override; virtual std::string getWritablePath() const; virtual bool isFileExist(const std::string& strFilePath) const; virtual bool isAbsolutePath(const std::string& strPath) const; - /** This function is android specific. It is used for TextureCache::addImageAsync(). - Don't use it in your codes. - */ - unsigned char* getFileDataForAsync(const char* filename, const char* mode, ssize_t * size); - private: - unsigned char* doGetFileData(const char* filename, const char* mode, ssize_t * size, bool forAsync); + Data getData(const std::string& filename, bool forString); + static AAssetManager* assetmanager; }; diff --git a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp index 73e18f59a8..6f79091506 100644 --- a/cocos/2d/platform/win32/CCFileUtilsWin32.cpp +++ b/cocos/2d/platform/win32/CCFileUtilsWin32.cpp @@ -121,6 +121,77 @@ bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const return false; } +static Data getData(const std::string& filename, bool forString) +{ + unsigned char *buffer = nullptr; + CCASSERT(!filename.empty(), "Invalid parameters."); + size_t size = 0; + do + { + // read the file from hardware + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename); + + WCHAR wszBuf[CC_MAX_PATH] = {0}; + MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf)); + + HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL); + CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE); + + size = ::GetFileSize(fileHandle, NULL); + + if (forString) + { + buffer = (unsigned char*) malloc(size + 1); + buffer[size] = '\0'; + } + else + { + buffer = (unsigned char*) malloc(size); + } + DWORD sizeRead = 0; + BOOL successed = FALSE; + successed = ::ReadFile(fileHandle, buffer, *size, &sizeRead, NULL); + ::CloseHandle(fileHandle); + + if (!successed) + { + free(buffer); + buffer = nullptr; + } + } while (0); + + Data ret; + + if (buffer == nullptr || size == 0) + { + std::string msg = "Get data from file("; + // Gets error code. + DWORD errorCode = ::GetLastError(); + char errorCodeBuffer[20] = {0}; + snprintf(errorCodeBuffer, sizeof(errorCodeBuffer), "%d", errorCode); + + msg = msg + filename + ") failed, error code is " + errorCodeBuffer; + CCLOG("%s", msg.c_str()); + } + else + { + ret.fastSet(buffer, size); + } + return ret; +} + +std::string FileUtilsAndroid::getStringFromFile(const std::string& filename) +{ + Data data = getData(filename, true); + std::string ret((const char*)data.getBytes()); + return ret; +} + +Data FileUtilsAndroid::getDataFromFile(const std::string& filename) +{ + return getData(filename, false); +} + unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, ssize_t* size) { unsigned char * pBuffer = NULL; @@ -148,6 +219,7 @@ unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mod if (!successed) { free(pBuffer); + pBuffer = nullptr; } } while (0); diff --git a/cocos/2d/platform/win32/CCFileUtilsWin32.h b/cocos/2d/platform/win32/CCFileUtilsWin32.h index 6eec9dd60e..78680a1c10 100644 --- a/cocos/2d/platform/win32/CCFileUtilsWin32.h +++ b/cocos/2d/platform/win32/CCFileUtilsWin32.h @@ -58,7 +58,18 @@ protected: * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override; + CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override; + + /** + * Gets string from a file. + */ + virtual std::string getStringFromFile(const std::string& filename) override; + + /** + * Creates binary data from a file. + * @return A data object. + */ + virtual Data getDataFromFile(const std::string& filename) override; /** * Gets full path for filename, resolution directory and search path. @@ -81,6 +92,7 @@ protected: * @return The full path of the file, if the file can't be found, it will return an empty string. */ virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) override; + }; // end of platform group diff --git a/cocos/base/CCData.cpp b/cocos/base/CCData.cpp index cd0af3adcf..16d6de9c46 100644 --- a/cocos/base/CCData.cpp +++ b/cocos/base/CCData.cpp @@ -21,31 +21,65 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #include #include "CCData.h" #include "platform/CCCommon.h" NS_CC_BEGIN -Data::Data(unsigned char *pBytes, ssize_t nSize) +const Data Data::Null; + +Data::Data() : +_bytes(nullptr), +_size(0) { - _size = nSize; - _bytes = new unsigned char[_size]; - memcpy(_bytes, pBytes, _size); + CCLOGINFO("In the empty constructor of Data."); } -Data::Data(Data *pData) +Data::Data(Data&& other) { - _size = pData->_size; - _bytes = new unsigned char[_size]; - memcpy(_bytes, pData->_bytes, _size); + CCLOGINFO("In the move constructor of Data."); + move(other); +} + +Data::Data(const Data& other) +{ + CCLOGINFO("In the copy constructor of Data."); + copy(other._bytes, other._size); } Data::~Data() { CCLOGINFO("deallocing Data: %p", this); - CC_SAFE_DELETE_ARRAY(_bytes); + free(_bytes); +} + +Data& Data::operator= (const Data& other) +{ + CCLOGINFO("In the copy assignment of Data."); + copy(other._bytes, other._size); + return *this; +} + +Data& Data::operator= (Data&& other) +{ + CCLOGINFO("In the move assignment of Data."); + move(other); + return *this; +} + +void Data::move(Data& other) +{ + _bytes = other._bytes; + _size = other._size; + + other._bytes = nullptr; + other._size = 0; +} + +bool Data::isNull() const +{ + return (_bytes == nullptr || _size == 0); } unsigned char* Data::getBytes() const @@ -58,4 +92,22 @@ ssize_t Data::getSize() const return _size; } +void Data::copy(unsigned char* bytes, const ssize_t size) +{ + free(_bytes); + _size = size; + if (size > 0) + { + _bytes = (unsigned char*)malloc(sizeof(unsigned char) * _size); + memcpy(_bytes, bytes, _size); + } +} + +void Data::fastSet(unsigned char* bytes, const ssize_t size) +{ + free(_bytes); + _bytes = bytes; + _size = size; +} + NS_CC_END diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index 69313b31bc..3c1dffb32a 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -26,41 +26,24 @@ #define __CCDATA_H__ #include "CCPlatformMacros.h" -#include "CCObject.h" +#include // for ssize_t NS_CC_BEGIN -class CC_DLL Data : public Object +class CC_DLL Data { public: - /** - * @js NA - * @lua NA - */ - Data(unsigned char *pBytes, const ssize_t nSize); - /** - * @js NA - * @lua NA - */ - Data(Data *pData); - /** - * @js NA - * @lua NA - */ + static const Data Null; + + Data(); + Data(const Data& other); + Data(Data&& other); ~Data(); - /** - * @js NA - * @lua NA - */ - static Data* create(unsigned char *pBytes, const ssize_t nSize) - { - Data* pRet = new Data(pBytes, nSize); - if (pRet) - { - pRet->autorelease(); - } - return pRet; - } + + // Assignment operator + Data& operator= (const Data& other); + Data& operator= (Data&& other); + /** * @js NA * @lua NA @@ -72,12 +55,28 @@ public: */ ssize_t getSize() const; - /** override functions - * @js NA - * @lua NA + /** Copies the buffer pointer and its size. + * @note This method will copy the whole buffer. + * Developer should free the pointer after invoking this method. + * @see Data::fastSet */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - + void copy(unsigned char* bytes, const ssize_t size); + + /** Fast set the buffer pointer and its size. + * @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc', + * since in the destructor of Data, the buffer will be deleted by 'free'. + * @note This method will move the ownship of 'bytes'pointer to Data, + * The pointer should not be used outside after it was passed to this method. + * @see Data::copy + */ + void fastSet(unsigned char* bytes, const ssize_t size); + + /** Check whether the data is null. */ + bool isNull() const; + +private: + void move(Data& other); + private: unsigned char* _bytes; ssize_t _size; diff --git a/cocos/base/CCDataVisitor.cpp b/cocos/base/CCDataVisitor.cpp index 6da64524e4..27ead8fbb3 100644 --- a/cocos/base/CCDataVisitor.cpp +++ b/cocos/base/CCDataVisitor.cpp @@ -31,7 +31,6 @@ #include "CCArray.h" #include "CCDictionary.h" #include "CCSet.h" -#include "CCData.h" NS_CC_BEGIN @@ -75,11 +74,6 @@ void DataVisitor::visit(const __Set *value) visitObject(value); } -void DataVisitor::visit(const Data *value) -{ - visitObject(value); -} - // PrettyPrinter PrettyPrinter::PrettyPrinter(int indentLevel/* = 0 */) { @@ -222,12 +216,6 @@ void PrettyPrinter::visit(const __Set *p) _result += "\n"; } -void PrettyPrinter::visit(const Data *p) -{ - //TODO Implement - DataVisitor::visit(p); -} - void PrettyPrinter::setIndentLevel(int indentLevel) { _indentLevel = indentLevel; diff --git a/cocos/base/CCDataVisitor.h b/cocos/base/CCDataVisitor.h index 37e08fc0d4..dda87ffc36 100644 --- a/cocos/base/CCDataVisitor.h +++ b/cocos/base/CCDataVisitor.h @@ -39,7 +39,6 @@ class __String; class __Array; class __Dictionary; class __Set; -class Data; /** * @addtogroup data_structures @@ -80,7 +79,6 @@ public: virtual void visit(const __Array *p); virtual void visit(const __Dictionary *p); virtual void visit(const __Set *p); - virtual void visit(const Data *p); }; @@ -101,7 +99,6 @@ public: virtual void visit(const __Array *p); virtual void visit(const __Dictionary *p); virtual void visit(const __Set *p); - virtual void visit(const Data *p); private: void setIndentLevel(int indentLevel); int _indentLevel; diff --git a/cocos/base/CCString.cpp b/cocos/base/CCString.cpp index 0441dfed65..9e0f4b314f 100644 --- a/cocos/base/CCString.cpp +++ b/cocos/base/CCString.cpp @@ -255,13 +255,8 @@ __String* __String::createWithFormat(const char* format, ...) __String* __String::createWithContentsOfFile(const char* filename) { - ssize_t size = 0; - unsigned char* data = 0; - __String* ret = NULL; - data = FileUtils::getInstance()->getFileData(filename, "rb", &size); - ret = __String::createWithData(data, static_cast(size)); - free(data); - return ret; + std::string str = FileUtils::getInstance()->getStringFromFile(filename); + return __String::create(std::move(str)); } void __String::acceptVisitor(DataVisitor &visitor) diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index ea743318db..35e40153b5 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -110,7 +110,6 @@ CCBReader::CCBReader() CCBReader::~CCBReader() { CC_SAFE_RELEASE_NULL(_owner); - CC_SAFE_RELEASE_NULL(_data); this->_nodeLoaderLibrary->release(); @@ -218,23 +217,17 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, } std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str()); - ssize_t size = 0; - unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size); - Data *data = new Data(pBytes, size); - free(pBytes); - - Node *ret = this->readNodeGraphFromData(data, pOwner, parentSize); + auto dataPtr = std::make_shared(FileUtils::getInstance()->getDataFromFile(strPath)); - data->release(); + Node *ret = this->readNodeGraphFromData(dataPtr, pOwner, parentSize); return ret; } -Node* CCBReader::readNodeGraphFromData(Data *pData, Object *pOwner, const Size &parentSize) +Node* CCBReader::readNodeGraphFromData(std::shared_ptr data, Object *pOwner, const Size &parentSize) { - _data = pData; - CC_SAFE_RETAIN(_data); + _data = data; _bytes =_data->getBytes(); _currentByte = 0; _currentBit = 0; diff --git a/cocos/editor-support/cocosbuilder/CCBReader.h b/cocos/editor-support/cocosbuilder/CCBReader.h index 813efec29a..69306227ed 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.h +++ b/cocos/editor-support/cocosbuilder/CCBReader.h @@ -173,7 +173,7 @@ public: * @js NA * @lua NA */ - cocos2d::Node* readNodeGraphFromData(cocos2d::Data *pData, cocos2d::Object *pOwner, const cocos2d::Size &parentSize); + cocos2d::Node* readNodeGraphFromData(std::shared_ptr data, cocos2d::Object *pOwner, const cocos2d::Size &parentSize); /** @lua NA @@ -360,7 +360,7 @@ private: friend class NodeLoader; private: - cocos2d::Data *_data; + std::shared_ptr _data; unsigned char *_bytes; int _currentByte; int _currentBit; diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index 895aaaf59d..adb7b8d095 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -923,19 +923,16 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader // Load sub file std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str()); - ssize_t size = 0; - unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size); + auto dataPtr = std::make_shared(FileUtils::getInstance()->getDataFromFile(path)); + CCBReader * reader = new CCBReader(pCCBReader); reader->autorelease(); reader->getAnimationManager()->setRootContainerSize(pParent->getContentSize()); - Data *data = new Data(pBytes, size); - free(pBytes); - - data->retain(); - reader->_data = data; - reader->_bytes = data->getBytes(); + + reader->_data = dataPtr; + reader->_bytes = dataPtr->getBytes(); reader->_currentByte = 0; reader->_currentBit = 0; CC_SAFE_RETAIN(pCCBReader->_owner); @@ -951,7 +948,6 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader // reader->_ownerCallbackNodes = pCCBReader->_ownerCallbackNodes; // reader->_ownerCallbackNodes->retain(); - data->release(); Node * ccbFileNode = reader->readFileWithCleanUp(false, pCCBReader->getAnimationManagers()); From 9e05f300f3cc9c27adbcdfe25af445ae92286065 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 20 Dec 2013 21:16:46 +0800 Subject: [PATCH 02/26] [Data Refactor] compilation error fix. --- cocos/2d/CCUserDefault.cpp | 2 +- cocos/2d/CCUserDefault.mm | 2 +- cocos/2d/platform/CCSAXParser.cpp | 2 +- cocos/2d/platform/CCSAXParser.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCUserDefault.cpp b/cocos/2d/CCUserDefault.cpp index 3bfb0d9142..90e721e436 100644 --- a/cocos/2d/CCUserDefault.cpp +++ b/cocos/2d/CCUserDefault.cpp @@ -289,7 +289,7 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul Data UserDefault::getDataForKey(const char* pKey) { - return getDataForKey(pKey, NULL); + return getDataForKey(pKey, Data::Null); } Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) diff --git a/cocos/2d/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm index 4280eb135f..6193113a85 100644 --- a/cocos/2d/CCUserDefault.mm +++ b/cocos/2d/CCUserDefault.mm @@ -365,7 +365,7 @@ string UserDefault::getStringForKey(const char* pKey, const std::string & defaul Data UserDefault::getDataForKey(const char* pKey) { - return getDataForKey(pKey, NULL); + return getDataForKey(pKey, Data::Null); } Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index e66bef90da..0c5282bfe1 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -111,7 +111,7 @@ bool SAXParser::parse(const char* xmlData, size_t dataLength) return tinyDoc.Accept( &printer ); } -bool SAXParser::parse(const char *pszFile) +bool SAXParser::parse(const std::string& filename) { bool ret = false; Data data = FileUtils::getInstance()->getDataFromFile(filename); diff --git a/cocos/2d/platform/CCSAXParser.h b/cocos/2d/platform/CCSAXParser.h index 09d5152563..63665f4ec7 100644 --- a/cocos/2d/platform/CCSAXParser.h +++ b/cocos/2d/platform/CCSAXParser.h @@ -26,7 +26,7 @@ #include "CCPlatformConfig.h" #include "platform/CCCommon.h" -#include "string.h" // for size_t +#include NS_CC_BEGIN @@ -87,7 +87,7 @@ public: * @js NA * @lua NA */ - bool parse(const char *file); + bool parse(const std::string& filename); /** * @js NA * @lua NA From b504d817b527577e76f5637d4bfa3358a802f573 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 20 Dec 2013 21:41:20 +0800 Subject: [PATCH 03/26] Small bug fix in CCData. --- cocos/base/CCData.cpp | 20 +++++++++++++++----- cocos/base/CCData.h | 10 +++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cocos/base/CCData.cpp b/cocos/base/CCData.cpp index 16d6de9c46..689d104886 100644 --- a/cocos/base/CCData.cpp +++ b/cocos/base/CCData.cpp @@ -21,9 +21,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include + #include "CCData.h" #include "platform/CCCommon.h" +#include "ccMacros.h" + +#include NS_CC_BEGIN @@ -51,7 +54,7 @@ Data::Data(const Data& other) Data::~Data() { CCLOGINFO("deallocing Data: %p", this); - free(_bytes); + clear(); } Data& Data::operator= (const Data& other) @@ -94,10 +97,11 @@ ssize_t Data::getSize() const void Data::copy(unsigned char* bytes, const ssize_t size) { - free(_bytes); - _size = size; + clear(); + if (size > 0) { + _size = size; _bytes = (unsigned char*)malloc(sizeof(unsigned char) * _size); memcpy(_bytes, bytes, _size); } @@ -105,9 +109,15 @@ void Data::copy(unsigned char* bytes, const ssize_t size) void Data::fastSet(unsigned char* bytes, const ssize_t size) { - free(_bytes); _bytes = bytes; _size = size; } +void Data::clear() +{ + free(_bytes); + _bytes = nullptr; + _size = 0; +} + NS_CC_END diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index 3c1dffb32a..f2efd16239 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -27,6 +27,7 @@ #include "CCPlatformMacros.h" #include // for ssize_t +#include NS_CC_BEGIN @@ -62,15 +63,18 @@ public: */ void copy(unsigned char* bytes, const ssize_t size); - /** Fast set the buffer pointer and its size. + /** Fast set the buffer pointer and its size. Please use it carefully. * @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc', * since in the destructor of Data, the buffer will be deleted by 'free'. - * @note This method will move the ownship of 'bytes'pointer to Data, - * The pointer should not be used outside after it was passed to this method. + * @note 1. This method will move the ownship of 'bytes'pointer to Data, + * 2. The pointer should not be used outside after it was passed to this method. * @see Data::copy */ void fastSet(unsigned char* bytes, const ssize_t size); + /** Clears data, free buffer and reset data size */ + void clear(); + /** Check whether the data is null. */ bool isNull() const; From 2a7b2c107aefc33231782a4376fbfc5bdd393389 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 20 Dec 2013 21:51:53 +0800 Subject: [PATCH 04/26] Updates CCUserDefaultAndroid.cpp. --- cocos/2d/CCUserDefaultAndroid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCUserDefaultAndroid.cpp b/cocos/2d/CCUserDefaultAndroid.cpp index 2c6226175f..01d41273f5 100644 --- a/cocos/2d/CCUserDefaultAndroid.cpp +++ b/cocos/2d/CCUserDefaultAndroid.cpp @@ -378,7 +378,7 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) #endif char * encodedDefaultData = NULL; - unsigned int encodedDefaultDataLen = defaultValue ? base64Encode(defaultValue->getBytes(), defaultValue->getSize(), &encodedDefaultData) : 0; + unsigned int encodedDefaultDataLen = !defaultValue.isNull() ? base64Encode(defaultValue.getBytes(), defaultValue.getSize(), &encodedDefaultData) : 0; string encodedStr = getStringForKeyJNI(pKey, encodedDefaultData); From ca082080b54e156482e280107938fe71c8a109ce Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 11:47:56 +0800 Subject: [PATCH 05/26] Binds FileUtils::getStringFromFile automatically since we have added this method. --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- .../lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 81cc046366..90b79936dd 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -cb193c00a0514b8292266fba55b5f97cbebb73bd \ No newline at end of file +59fe47a7fc5c48bb723eb916921bb2c0e160430b \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id index f6d3f63b06..7205792837 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -c1e3182aeb1023c573f64314788fbccb8da2de43 \ No newline at end of file +e9fd4e6fbccdc826ee0232dc2ec0286821d1eb09 \ No newline at end of file From 366c4ca9fb68032d81a92dea7157c7bdc61b29ff Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 11:48:22 +0800 Subject: [PATCH 06/26] Updates tools/tojs(tolua)/cocos2dx.ini. --- tools/tojs/cocos2dx.ini | 4 ++-- tools/tolua/cocos2dx.ini | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 9f17145f6a..1824658454 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # 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 = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF EGLViewProtocol EGLView Component __NodeRGBA __LayerRGBA +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF EGLViewProtocol EGLView Component __NodeRGBA __LayerRGBA classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode @@ -104,7 +104,7 @@ skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject . TextureCache::[addPVRTCImage], Timer::[getSelector createWithScriptHandler], *::[copyWith.* onEnter.* onExit.* ^description$ getObjectType onTouch.* onAcc.* onKey.* onRegisterTouchListener], - FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData], + FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData getDataFromFile], Application::[^application.* ^run$], Camera::[getEyeXYZ getCenterXYZ getUpXYZ], ccFontDefinition::[*], diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index bea7b1f326..dbc4bb42a2 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # 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 = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image # 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 @@ -99,7 +99,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS TextureCache::[addPVRTCImage], Timer::[getSelector createWithScriptHandler], *::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate onTouch.* onAcc.* onKey.* onRegisterTouchListener], - FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData], + FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$ getFileData getDataFromFile], Application::[^application.* ^run$], Camera::[getEyeXYZ getCenterXYZ getUpXYZ], ccFontDefinition::[*], From 11423b5851b0933d89c6cacd27d5f8068550031b Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 11:53:39 +0800 Subject: [PATCH 07/26] Changes the type of FontFreeType::_ttfData from `unsigned char*` to `Data`, makes codes more elegant. --- cocos/2d/CCFontFreeType.cpp | 19 +++---------------- cocos/2d/CCFontFreeType.h | 7 ++++--- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 8c2e6ddeb7..77a64bcfd9 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -90,7 +90,6 @@ FT_Library FontFreeType::getFTLibrary() FontFreeType::FontFreeType(bool dynamicGlyphCollection) : _fontRef(nullptr), _letterPadding(5), -_ttfData(nullptr), _dynamicGlyphCollection(dynamicGlyphCollection) { if(_distanceFieldEnabled) @@ -101,20 +100,13 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) { FT_Face face; - ssize_t len = 0; - Data data = FileUtils::getInstance()->getDataFromFile(fontName); - _ttfData = data.getBytes(); - len = data.getSize(); + _ttfData = FileUtils::getInstance()->getDataFromFile(fontName); - // The data needs to be saved in this class, - // to prevent the buffer is freed in the destructor of Data, we should reset the buffer pointer by Data::fastSet. - data.fastSet(nullptr, 0); - - if (!_ttfData) + if (_ttfData.isNull()) return false; // create the face from the data - if (FT_New_Memory_Face(getFTLibrary(), _ttfData, len, 0, &face )) + if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face )) return false; //we want to use unicode @@ -143,11 +135,6 @@ FontFreeType::~FontFreeType() { FT_Done_Face(_fontRef); } - if (_ttfData) - { - free(_ttfData); - _ttfData = nullptr; - } } FontAtlas * FontFreeType::createFontAtlas() diff --git a/cocos/2d/CCFontFreeType.h b/cocos/2d/CCFontFreeType.h index 948ce9a601..7ff7596c20 100644 --- a/cocos/2d/CCFontFreeType.h +++ b/cocos/2d/CCFontFreeType.h @@ -25,11 +25,12 @@ #ifndef _FontFreetype_h_ #define _FontFreetype_h_ +#include "CCFont.h" +#include "CCData.h" + #include #include -#include "CCFont.h" - #include FT_FREETYPE_H NS_CC_BEGIN @@ -73,7 +74,7 @@ private: FT_Face _fontRef; int _letterPadding; std::string _fontName; - unsigned char* _ttfData; + Data _ttfData; bool _dynamicGlyphCollection; }; From 4ed988b8c598bca83d5ae495d02a085412937d01 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 13:45:31 +0800 Subject: [PATCH 08/26] Fixes linux build failure. --- cocos/base/CCData.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index f2efd16239..40c1d53c06 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -26,8 +26,8 @@ #define __CCDATA_H__ #include "CCPlatformMacros.h" -#include // for ssize_t -#include +#include // for ssize_t on android +#include // for ssize_t on linux NS_CC_BEGIN From 81d073aff08a9387d009a1ab035089e0fc918fd7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 16:29:55 +0800 Subject: [PATCH 09/26] Reverts FileUtil::getFileData to virtual function. --- cocos/2d/platform/CCFileUtils.h | 2 +- cocos/2d/platform/android/CCFileUtilsAndroid.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index c43e5d3823..8035e83b97 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -96,7 +96,7 @@ public: * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned. */ - CC_DEPRECATED_ATTRIBUTE unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size); + CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size); /** * Gets resource file data from a zip file. diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.h b/cocos/2d/platform/android/CCFileUtilsAndroid.h index 5e1f0b0d0c..0097a2c149 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.h +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.h @@ -57,7 +57,7 @@ public: bool init(); /** @deprecated Please use FileUtils::getDataFromFile or FileUtils::getStringFromFile instead. */ - CC_DEPRECATED_ATTRIBUTE unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size); + CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override; /** * Gets string from a file. From c3b7406b43c39f24a296cc04ee96941af3ad3eb3 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 24 Dec 2013 09:00:04 +0000 Subject: [PATCH 10/26] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index daff147b1f..46d0b76130 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit daff147b1ff3d3754cb014c4e9c575676dea68b9 +Subproject commit 46d0b761304efa3f22b768aaa61577a99a82c02d From b6dc3d037104aa64eb8ff247bee98e7dc95bfcc2 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 24 Dec 2013 17:16:28 +0800 Subject: [PATCH 11/26] fix clippingNode bug --- cocos/2d/CCClippingNode.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index e69b34273d..552b1f081c 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -200,6 +200,11 @@ void ClippingNode::drawFullScreenQuadClearStencil() void ClippingNode::visit() { + if(!_visible) + return; + + kmGLPushMatrix(); + transform(); //Add group command Renderer* renderer = Director::getInstance()->getRenderer(); @@ -222,7 +227,31 @@ void ClippingNode::visit() afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); renderer->addCommand(afterDrawStencilCmd); - Node::visit(); + int i = 0; + + if(!_children.empty()) + { + sortAllChildren(); + // draw children zOrder < 0 + for( ; i < _children.size(); i++ ) + { + auto node = _children.at(i); + + if ( node && node->getZOrder() < 0 ) + node->visit(); + else + break; + } + // self draw + this->draw(); + + for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) + (*it)->visit(); + } + else + { + this->draw(); + } CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand(); afterVisitCmd->init(0,_vertexZ); @@ -230,6 +259,8 @@ void ClippingNode::visit() renderer->addCommand(afterVisitCmd); renderer->popGroup(); + + kmGLPopMatrix(); } Node* ClippingNode::getStencil() const From 0ff85852ccbccad69713f535008cb283a04eddcb Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 18:08:40 +0800 Subject: [PATCH 12/26] =?UTF-8?q?Don=E2=80=99t=20use=20FileUtils::getInsta?= =?UTF-8?q?nce()->getFileData,=20please=20use=20getStringFromFile=20and=20?= =?UTF-8?q?getDataFromFile=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCTextureCache.cpp | 7 ++--- cocos/2d/CCUserDefaultAndroid.cpp | 11 ++++---- .../cocostudio/CCDataReaderHelper.cpp | 10 ++----- .../cocostudio/CCSGUIReader.cpp | 15 +++++----- .../cocostudio/CCSSceneReader.cpp | 28 ++++++++----------- cocos/editor-support/spine/spine-cocos2dx.cpp | 24 ++++++++++++---- .../javascript/bindings/ScriptingCore.cpp | 25 ++++++++--------- .../lua/bindings/Cocos2dxLuaLoader.cpp | 8 ++---- 8 files changed, 61 insertions(+), 67 deletions(-) diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 24ffcb5733..d840a2e093 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -629,10 +629,10 @@ void VolatileTextureMgr::reloadAllTextures() case VolatileTexture::kImageFile: { Image* image = new Image(); - ssize_t size = 0; - unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size); - if (image && image->initWithImageData(pBuffer, size)) + Data data = FileUtils::getInstance()->getDataFromFile(vt->_fileName); + + if (image && image->initWithImageData(data->getBytes(), data->getSize()) { Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); @@ -640,7 +640,6 @@ void VolatileTextureMgr::reloadAllTextures() Texture2D::setDefaultAlphaPixelFormat(oldPixelFormat); } - free(pBuffer); CC_SAFE_RELEASE(image); } break; diff --git a/cocos/2d/CCUserDefaultAndroid.cpp b/cocos/2d/CCUserDefaultAndroid.cpp index 01d41273f5..af82d29364 100644 --- a/cocos/2d/CCUserDefaultAndroid.cpp +++ b/cocos/2d/CCUserDefaultAndroid.cpp @@ -75,15 +75,16 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; ssize_t size; - char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size); - //const char* pXmlBuffer = (const char*)data.getBuffer(); - if(nullptr == pXmlBuffer) + + std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath().c_str()); + + if (xmlBuffer.empty()) { CCLOG("can not read xml file"); break; } - xmlDoc->Parse(pXmlBuffer); - free(pXmlBuffer); + xmlDoc->Parse(xmlBuffer.c_str()); + // get root node rootNode = xmlDoc->RootElement(); if (nullptr == rootNode) diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index d5bbec47d5..779197b62d 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -288,11 +288,8 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) std::string str = &filePathStr[startPos]; // Read content from file - ssize_t size; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - unsigned char *pTempContent = (unsigned char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); - - std::string contentStr = std::string((const char*)pTempContent, size); + std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath); DataInfo dataInfo; dataInfo.filename = filePathStr; @@ -307,8 +304,6 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) { DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo); } - - free(pTempContent); } void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Object *target, SEL_SCHEDULE selector) @@ -391,10 +386,9 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string str = &filePathStr[startPos]; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - ssize_t size; // XXX fileContent is being leaked - data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); + data->fileContent = FileUtils::getInstance()->getStringFromFile(fullPath); if (str == ".xml") { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 625627fff1..5d5a57e16c 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -122,22 +122,22 @@ const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const UIWidget* GUIReader::widgetFromJsonFile(const char *fileName) { DictionaryHelper* dicHelper = DICTOOL; - char *des = nullptr; + std::string jsonpath; JsonDictionary *jsonDict = nullptr; jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName); int pos = jsonpath.find_last_of('/'); m_strFilePath = jsonpath.substr(0,pos+1); - ssize_t size = 0; - des = (char*)(CCFileUtils::getInstance()->getFileData(jsonpath.c_str(),"r" , &size)); - if(nullptr == des || strcmp(des, "") == 0) + + std::string des = FileUtils::getInstance()->getStringFromFile(jsonpath); + if (des.empty()) { - printf("read json file[%s] error!\n", fileName); + CCLOG("read json file[%s] error!\n", fileName); return nullptr; } - std::string strDes(des); + jsonDict = new JsonDictionary(); - jsonDict->initWithDescription(strDes.c_str()); + jsonDict->initWithDescription(des.c_str()); UIWidget* widget = nullptr; const char* fileVersion = dicHelper->getStringValue_json(jsonDict, "version"); @@ -164,7 +164,6 @@ UIWidget* GUIReader::widgetFromJsonFile(const char *fileName) CC_SAFE_DELETE(pReader); CC_SAFE_DELETE(jsonDict); - free(des); return widget; } diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index d682c504b7..b84c2773ad 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -47,19 +47,16 @@ namespace cocostudio { cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName) { - ssize_t size = 0; - char* pData = 0; cocos2d::Node *pNode = nullptr; do { CC_BREAK_IF(pszFileName == nullptr); - pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pszFileName, "r", &size)); - CC_BREAK_IF(pData == nullptr || strcmp(pData, "") == 0); + std::string fileContent = cocos2d::FileUtils::getInstance()->getStringFromFile(pszFileName); + CC_BREAK_IF(fileContent.empty()); JsonDictionary *jsonDict = new JsonDictionary(); - jsonDict->initWithDescription(pData); + jsonDict->initWithDescription(fileContent.c_str()); pNode = createObject(jsonDict,nullptr); CC_SAFE_DELETE(jsonDict); - free(pData); } while (0); return pNode; @@ -215,11 +212,12 @@ namespace cocostudio { { file_path = reDir.substr(0, pos+1); } - ssize_t size = 0; - char *des = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(),"r" , &size)); + + std::string des = cocos2d::FileUtils::getInstance()->getStringFromFile(pPath); + JsonDictionary *jsonDict = new JsonDictionary(); - jsonDict->initWithDescription(des); - if(nullptr == des || strcmp(des, "") == 0) + jsonDict->initWithDescription(des.c_str()); + if (des.empty()) { CCLOG("read json file[%s] error!\n", pPath.c_str()); } @@ -263,7 +261,6 @@ namespace cocostudio { CC_SAFE_DELETE(jsonDict); CC_SAFE_DELETE(subData); - free(des); } else if(comName != nullptr && strcmp(comName, "CCComAudio") == 0) { @@ -285,14 +282,11 @@ namespace cocostudio { if (nResType == 0) { pAttribute = ComAttribute::create(); - ssize_t size = 0; - char* pData = 0; - pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size)); - if(pData != nullptr && strcmp(pData, "") != 0) + std::string fileContent = cocos2d::FileUtils::getInstance()->getStringFromFile(pPath); + if (!fileContent.empty()) { - pAttribute->getDict()->initWithDescription(pData); + pAttribute->getDict()->initWithDescription(fileContent.c_str()); } - free(pData); } else { diff --git a/cocos/editor-support/spine/spine-cocos2dx.cpp b/cocos/editor-support/spine/spine-cocos2dx.cpp index 8f895fcff4..734492a91e 100644 --- a/cocos/editor-support/spine/spine-cocos2dx.cpp +++ b/cocos/editor-support/spine/spine-cocos2dx.cpp @@ -52,12 +52,24 @@ void _spAtlasPage_disposeTexture (spAtlasPage* self) { ((TextureAtlas*)self->rendererObject)->release(); } -char* _spUtil_readFile (const char* path, int* length) { - ssize_t size; - char* data = reinterpret_cast( - FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "rb", &size)); - *length = static_cast(size); - return data;} +char* _spUtil_readFile (const char* path, int* length) +{ + char* ret = nullptr; + int size = 0; + Data data = FileUtils::getInstance()->getDataFromFile(path); + + if (!data.isNull()) + { + size = static_cast(data.getSize()); + *length = size; + // Allocates one more byte for string terminal, it will be safe when parsing JSON file in Spine runtime. + ret = (char*)malloc(size + 1); + ret[size] = '\0'; + memcpy(ret, data.getBytes(), size); + } + + return ret; +} /**/ diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.cpp b/cocos/scripting/javascript/bindings/ScriptingCore.cpp index a23101156e..bdbf4978e0 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.cpp +++ b/cocos/scripting/javascript/bindings/ScriptingCore.cpp @@ -533,18 +533,17 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c // a) check jsc file first std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT; - ssize_t length = 0; - unsigned char* data = futil->getFileData(byteCodePath.c_str(), - "rb", - &length); + + Data data = futil->getDataFromFile(byteCodePath); - if (data) { - script = JS_DecodeScript(cx, data, length, NULL, NULL); - free(data); + if (!data.isNull()) + { + script = JS_DecodeScript(cx, data.getBytes(), static_cast(data.getSize()), nullptr, nullptr); } // b) no jsc file, check js file - if (!script) { + if (!script) + { /* Clear any pending exception from previous failed decoding. */ ReportException(cx); @@ -553,12 +552,10 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c options.setUTF8(true).setFileAndLine(fullPath.c_str(), 1); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - String* content = String::createWithContentsOfFile(path); - if (content) { - // Not supported in SpiderMonkey 19.0 - //JSScript* script = JS_CompileScript(cx, global, (char*)content, contentSize, path, 1); - const char* contentCStr = content->getCString(); - script = JS::Compile(cx, obj, options, contentCStr, strlen(contentCStr)); + std::string jsFileContent = futil->getStringFromFile(fullPath); + if (!jsFileContent.empty()) + { + script = JS::Compile(cx, obj, options, jsFileContent.c_str(), jsFileContent.size()); } #else script = JS::Compile(cx, obj, options, fullPath.c_str()); diff --git a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp index fa1f7cb01c..13c9c26e34 100644 --- a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp +++ b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp @@ -46,17 +46,15 @@ extern "C" } filename.append(".lua"); - long codeBufferSize = 0; - unsigned char* codeBuffer = FileUtils::getInstance()->getFileData(filename.c_str(), "rb", &codeBufferSize); + Data data = FileUtils::getInstance()->getDataFromFile(filename); - if (codeBuffer) + if (!data.isNull()) { - if (luaL_loadbuffer(L, (char*)codeBuffer, codeBufferSize, filename.c_str()) != 0) + if (luaL_loadbuffer(L, (char*)data.getBytes(), data.getSize(), filename.c_str()) != 0) { luaL_error(L, "error loading module %s from file %s :\n\t%s", lua_tostring(L, 1), filename.c_str(), lua_tostring(L, -1)); } - free(codeBuffer); } else { From d08cb63a82922a35870c35793bf55fbb7879b08c Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 18:19:32 +0800 Subject: [PATCH 13/26] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index e6b5f0a0a6..6598b78d90 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ cocos2d-x-3.0beta0 ?? 2013 [FIX] Updates spine runtime to the latest version. [FIX] Uses `const std::string&` instead of `const char*`. [FIX] LabelBMFont string can't be shown integrally. + [FIX] Deprecates FileUtils::getFileData, adds FileUtils::getStringFromFile/getDataFromFile. [Android] [NEW] build/android-build.sh: add supporting to generate .apk file [FIX] XMLHttpRequest receives wrong binary array. From 1f5611ae053311d3fe5bbfe13c1d08acb9a9adf4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 18:23:36 +0800 Subject: [PATCH 14/26] =?UTF-8?q?Adds=20missing=20=E2=80=98)=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCTextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index d840a2e093..e1c160f101 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -632,7 +632,7 @@ void VolatileTextureMgr::reloadAllTextures() Data data = FileUtils::getInstance()->getDataFromFile(vt->_fileName); - if (image && image->initWithImageData(data->getBytes(), data->getSize()) + if (image && image->initWithImageData(data->getBytes(), data->getSize())) { Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); From 17a6dbebb62dcdbc59b7c7b42583949ca4589cbb Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 19:05:35 +0800 Subject: [PATCH 15/26] Compilation error fixes. --- cocos/2d/CCTextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index e1c160f101..419f3fe860 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -632,7 +632,7 @@ void VolatileTextureMgr::reloadAllTextures() Data data = FileUtils::getInstance()->getDataFromFile(vt->_fileName); - if (image && image->initWithImageData(data->getBytes(), data->getSize())) + if (image && image->initWithImageData(data.getBytes(), data.getSize())) { Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat); From 122f97f20ada1d8986bee238e54c1ed8ecb57066 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 09:51:55 +0800 Subject: [PATCH 16/26] fix actionTest->ActionFollow, ActionCatmullRomStacked --- .../Classes/ActionsTest/ActionsTest.cpp | 38 ++++++++++++++++--- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 8 ++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index ff70e66f66..07f9d62b33 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -2,6 +2,10 @@ #include "../testResource.h" #include "cocos2d.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCGroupCommand.h" + static std::function createFunctions[] = { CL(ActionManual), @@ -1284,14 +1288,23 @@ void ActionFollow::onEnter() } void ActionFollow::draw() +{ + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ActionFollow::onDraw, this); + + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void ActionFollow::onDraw() { auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width*2 - 100; - float y = winSize.height; + float x = winSize.width*2 - 100; + float y = winSize.height; - Point vertices[] = { Point(5,5), Point(x-5,5), Point(x-5,y-5), Point(5,y-5) }; - DrawPrimitives::drawPoly(vertices, 4, true); + Point vertices[] = { Point(5,5), Point(x-5,5), Point(x-5,y-5), Point(5,y-5) }; + DrawPrimitives::drawPoly(vertices, 4, true); } std::string ActionFollow::subtitle() const @@ -1589,10 +1602,25 @@ void ActionCatmullRomStacked::draw() // move to 50,50 since the "by" path will start at 50,50 kmGLPushMatrix(); kmGLTranslatef(50, 50, 0); - DrawPrimitives::drawCatmullRom(_array1,50); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); kmGLPopMatrix(); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void ActionCatmullRomStacked::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewMV1); + DrawPrimitives::drawCatmullRom(_array1,50); + kmGLLoadMatrix(&_modelViewMV2); DrawPrimitives::drawCatmullRom(_array2,50); + kmGLLoadMatrix(&oldMat); } std::string ActionCatmullRomStacked::title() const diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 257c28b28e..9730863c83 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -343,6 +343,9 @@ public: virtual void onEnter(); virtual void draw(); virtual std::string subtitle() const override; + +protected: + void onDraw(); }; class ActionTargeted : public ActionsDemo @@ -415,6 +418,11 @@ public: virtual void onEnter(); virtual std::string title() const override; virtual std::string subtitle() const override; +protected: + //cached data and callback + kmMat4 _modelViewMV1; + kmMat4 _modelViewMV2; + void onDraw(); private: PointArray* _array1; PointArray* _array2; From c29b796c1574057e962823cd42a58d4d6bc5a2f7 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 09:58:35 +0800 Subject: [PATCH 17/26] fix actionTest->ActionCardinalSplineStacked --- .../Classes/ActionsTest/ActionsTest.cpp | 20 +++++++++++++++++-- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 07f9d62b33..e06f0512c2 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -1712,15 +1712,31 @@ void ActionCardinalSplineStacked::draw() // move to 50,50 since the "by" path will start at 50,50 kmGLPushMatrix(); kmGLTranslatef(50, 50, 0); - DrawPrimitives::drawCardinalSpline(_array, 0, 100); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); kmGLPopMatrix(); auto s = Director::getInstance()->getWinSize(); kmGLPushMatrix(); kmGLTranslatef(s.width/2, 50, 0); - DrawPrimitives::drawCardinalSpline(_array, 1, 100); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); + + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void ActionCardinalSplineStacked::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewMV1); + DrawPrimitives::drawCardinalSpline(_array, 0, 100); + kmGLLoadMatrix(&_modelViewMV2); + DrawPrimitives::drawCardinalSpline(_array, 1, 100); + kmGLLoadMatrix(&oldMat); } std::string ActionCardinalSplineStacked::title() const diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 9730863c83..219c16ec33 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -440,6 +440,10 @@ public: virtual std::string subtitle() const override; private: PointArray* _array; +protected: + void onDraw(); + kmMat4 _modelViewMV1; + kmMat4 _modelViewMV2; }; class Issue1305 : public ActionsDemo From 960c64d7873a5666c7c0c0286ae07ecce9b8f7a1 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 10:20:29 +0800 Subject: [PATCH 18/26] =?UTF-8?q?fix=20actionTest->ActionCardinalSpline?= =?UTF-8?q?=EF=BC=8CActionCatmullRom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Classes/ActionsTest/ActionsTest.cpp | 44 ++++++++++++++++--- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 8 ++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index e06f0512c2..66222daa7c 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -2080,12 +2080,30 @@ void ActionCatmullRom::draw() // move to 50,50 since the "by" path will start at 50,50 kmGLPushMatrix(); kmGLTranslatef(50, 50, 0); - DrawPrimitives::drawCatmullRom(_array1, 50); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); + kmGLPopMatrix(); - - DrawPrimitives::drawCatmullRom(_array2,50); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); + + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); } + +void ActionCatmullRom::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewMV1); + DrawPrimitives::drawCatmullRom(_array1, 50); + kmGLLoadMatrix(&_modelViewMV2); + DrawPrimitives::drawCatmullRom(_array2,50); + kmGLLoadMatrix(&oldMat); +} + + std::string ActionCatmullRom::title() const { return "CatmullRomBy / CatmullRomTo"; @@ -2158,15 +2176,31 @@ void ActionCardinalSpline::draw() // move to 50,50 since the "by" path will start at 50,50 kmGLPushMatrix(); kmGLTranslatef(50, 50, 0); - DrawPrimitives::drawCardinalSpline(_array, 0, 100); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); kmGLPopMatrix(); auto s = Director::getInstance()->getWinSize(); kmGLPushMatrix(); kmGLTranslatef(s.width/2, 50, 0); - DrawPrimitives::drawCardinalSpline(_array, 1, 100); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); + + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void ActionCardinalSpline::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewMV1); + DrawPrimitives::drawCardinalSpline(_array, 0, 100); + kmGLLoadMatrix(&_modelViewMV2); + DrawPrimitives::drawCardinalSpline(_array, 1, 100); + kmGLLoadMatrix(&oldMat); } std::string ActionCardinalSpline::title() const diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 219c16ec33..5477fd2967 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -534,6 +534,10 @@ public: private: PointArray *_array1; PointArray *_array2; +protected: + void onDraw(); + kmMat4 _modelViewMV1; + kmMat4 _modelViewMV2; }; class ActionCardinalSpline : public ActionsDemo @@ -549,6 +553,10 @@ public: virtual std::string title() const override; private: PointArray *_array; +protected: + void onDraw(); + kmMat4 _modelViewMV1; + kmMat4 _modelViewMV2; }; class PauseResumeActions : public ActionsDemo From fac87108f6e8e1e2eace806c630da0665e117b5b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 10:54:31 +0800 Subject: [PATCH 19/26] fix actionTest->Box2dTest --- .../TestCpp/Classes/Box2DTest/Box2dTest.cpp | 20 ++++++++++++++++++- .../Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index ba9d1982fe..b02af726c2 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -1,6 +1,9 @@ #include "Box2dTest.h" #include "../testResource.h" #include "extensions/cocos-ext.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" + USING_NS_CC_EXT; #define PTM_RATIO 32 @@ -144,13 +147,28 @@ void Box2DTestLayer::draw() GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); kmGLPushMatrix(); + kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); - world->DrawDebugData(); + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); kmGLPopMatrix(); #endif } +#if CC_ENABLE_BOX2D_INTEGRATION +void Box2DTestLayer::onDraw() +{ + kmMat4 oldMV; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMV); + kmGLLoadMatrix(&_modelViewMV); + world->DrawDebugData(); + kmGLLoadMatrix(&oldMV); +} +#endif + void Box2DTestLayer::addNewSpriteAtPosition(Point p) { CCLOG("Add sprite %0.2f x %02.f",p.x,p.y); diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h index 5c22274ba3..f791c68256 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h @@ -24,6 +24,11 @@ public: void onTouchesEnded(const std::vector& touches, Event* event); //CREATE_NODE(Box2DTestLayer); +#if CC_ENABLE_BOX2D_INTEGRATION +protected: + kmMat4 _modelViewMV; + void onDraw(); +#endif } ; class Box2DTestScene : public TestScene From 6fce4f9061e83410c07ca15377e44577e859aa40 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Dec 2013 11:00:27 +0800 Subject: [PATCH 20/26] =?UTF-8?q?Don=E2=80=99t=20use=20=E2=80=98String::cr?= =?UTF-8?q?eateWithFormat=E2=80=99=20in=20our=20codes,=20use=20StringUtils?= =?UTF-8?q?::format()=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCDeprecated.h | 2 +- cocos/2d/CCGLProgram.cpp | 10 +++++----- cocos/2d/CCTexture2D.cpp | 2 +- cocos/2d/CCTextureAtlas.cpp | 2 +- cocos/2d/CCTextureCache.cpp | 2 +- cocos/base/CCPlatformMacros.h | 2 +- cocos/base/CCString.h | 3 --- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cocos/2d/CCDeprecated.h b/cocos/2d/CCDeprecated.h index d7fc7589fd..b2710848bf 100644 --- a/cocos/2d/CCDeprecated.h +++ b/cocos/2d/CCDeprecated.h @@ -1038,7 +1038,7 @@ CC_DEPRECATED_ATTRIBUTE typedef __Integer CCInteger; CC_DEPRECATED_ATTRIBUTE typedef __Bool Bool; CC_DEPRECATED_ATTRIBUTE typedef __Bool CCBool; CC_DEPRECATED_ATTRIBUTE typedef __String CCString; -//CC_DEPRECATED_ATTRIBUTE typedef __String String; +CC_DEPRECATED_ATTRIBUTE typedef __String String; CC_DEPRECATED_ATTRIBUTE typedef __RGBAProtocol RGBAProtocol; CC_DEPRECATED_ATTRIBUTE typedef __NodeRGBA NodeRGBA; diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index 61ed0112fc..0d9441cde3 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -154,18 +154,18 @@ bool GLProgram::initWithVertexShaderByteArray(const GLchar* vShaderByteArray, co bool GLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename) { - const GLchar * vertexSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str())->getCString(); - const GLchar * fragmentSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str())->getCString(); + std::string vertexSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(vShaderFilename).c_str()); + std::string fragmentSource = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename(fShaderFilename).c_str()); - return initWithVertexShaderByteArray(vertexSource, fragmentSource); + return initWithVertexShaderByteArray(vertexSource.c_str(), fragmentSource.c_str()); } std::string GLProgram::getDescription() const { - return String::createWithFormat("", - (size_t)this, _program, _vertShader, _fragShader)->getCString(); + (size_t)this, _program, _vertShader, _fragShader); } bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source) diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index ba421d1a65..09539152a7 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -673,7 +673,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat std::string Texture2D::getDescription() const { - return String::createWithFormat("", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT)->getCString(); + return StringUtils::format("", _name, (long)_pixelsWide, (long)_pixelsHigh, _maxS, _maxT); } // implementation Texture2D (Image) diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index a2751f66cb..e443a26146 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj) std::string TextureAtlas::getDescription() const { - return String::createWithFormat("", _totalQuads)->getCString(); + return StringUtils::format("", _totalQuads); } diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 419f3fe860..d7a745a40f 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -89,7 +89,7 @@ void TextureCache::purgeSharedTextureCache() std::string TextureCache::getDescription() const { - return String::createWithFormat("", _textures.size() )->getCString(); + return StringUtils::format("", _textures.size()); } void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_CallFuncO selector) diff --git a/cocos/base/CCPlatformMacros.h b/cocos/base/CCPlatformMacros.h index 0cdf83c8a0..7fbfa542c8 100644 --- a/cocos/base/CCPlatformMacros.h +++ b/cocos/base/CCPlatformMacros.h @@ -205,7 +205,7 @@ public: virtual void set##funName(varType var) \ #define CC_BREAK_IF(cond) if(cond) break #define __CCLOGWITHFUNCTION(s, ...) \ - log("%s : %s",__FUNCTION__, String::createWithFormat(s, ##__VA_ARGS__)->getCString()) + log("%s : %s",__FUNCTION__, StringUtils::format(s, ##__VA_ARGS__).c_str()) // cocos2d debug #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 diff --git a/cocos/base/CCString.h b/cocos/base/CCString.h index ba5b773b84..a3f4fd94ba 100644 --- a/cocos/base/CCString.h +++ b/cocos/base/CCString.h @@ -239,9 +239,6 @@ public: }; - -CC_DEPRECATED_ATTRIBUTE typedef __String String; - // end of data_structure group /// @} From 538da31773b8aef89071b5ca8bf104460ae6a51d Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Dec 2013 11:18:14 +0800 Subject: [PATCH 21/26] Removes CC prefix for CCSkeleton and CCSkeletonAnimation. Adds namespace `sp` for JSBindings. --- cocos/editor-support/spine/CCSkeleton.cpp | 58 +++++++++---------- cocos/editor-support/spine/CCSkeleton.h | 18 +++--- .../spine/CCSkeletonAnimation.cpp | 54 ++++++++--------- .../spine/CCSkeletonAnimation.h | 24 ++++---- .../TestCpp/Classes/SpineTest/SpineTest.cpp | 4 +- .../Cpp/TestCpp/Classes/SpineTest/SpineTest.h | 4 +- tools/tojs/cocos2dx_spine.ini | 10 ++-- 7 files changed, 86 insertions(+), 86 deletions(-) diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index a194809d41..70c342c53d 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -40,25 +40,25 @@ using std::max; namespace spine { -CCSkeleton* CCSkeleton::createWithData (spSkeletonData* skeletonData, bool isOwnsSkeletonData) { - CCSkeleton* node = new CCSkeleton(skeletonData, isOwnsSkeletonData); +Skeleton* Skeleton::createWithData (spSkeletonData* skeletonData, bool isOwnsSkeletonData) { + Skeleton* node = new Skeleton(skeletonData, isOwnsSkeletonData); node->autorelease(); return node; } -CCSkeleton* CCSkeleton::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) { - CCSkeleton* node = new CCSkeleton(skeletonDataFile, atlas, scale); +Skeleton* Skeleton::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) { + Skeleton* node = new Skeleton(skeletonDataFile, atlas, scale); node->autorelease(); return node; } -CCSkeleton* CCSkeleton::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) { - CCSkeleton* node = new CCSkeleton(skeletonDataFile, atlasFile, scale); +Skeleton* Skeleton::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) { + Skeleton* node = new Skeleton(skeletonDataFile, atlasFile, scale); node->autorelease(); return node; } -void CCSkeleton::initialize () { +void Skeleton::initialize () { atlas = 0; debugSlots = false; debugBones = false; @@ -73,23 +73,23 @@ void CCSkeleton::initialize () { scheduleUpdate(); } -void CCSkeleton::setSkeletonData (spSkeletonData *skeletonData, bool isOwnsSkeletonData) { +void Skeleton::setSkeletonData (spSkeletonData *skeletonData, bool isOwnsSkeletonData) { skeleton = spSkeleton_create(skeletonData); rootBone = skeleton->bones[0]; this->ownsSkeletonData = isOwnsSkeletonData; } -CCSkeleton::CCSkeleton () { +Skeleton::Skeleton () { initialize(); } -CCSkeleton::CCSkeleton (spSkeletonData *skeletonData, bool isOwnsSkeletonData) { +Skeleton::Skeleton (spSkeletonData *skeletonData, bool isOwnsSkeletonData) { initialize(); setSkeletonData(skeletonData, isOwnsSkeletonData); } -CCSkeleton::CCSkeleton (const char* skeletonDataFile, spAtlas* aAtlas, float scale) { +Skeleton::Skeleton (const char* skeletonDataFile, spAtlas* aAtlas, float scale) { initialize(); spSkeletonJson* json = spSkeletonJson_create(aAtlas); @@ -101,7 +101,7 @@ CCSkeleton::CCSkeleton (const char* skeletonDataFile, spAtlas* aAtlas, float sca setSkeletonData(skeletonData, true); } -CCSkeleton::CCSkeleton (const char* skeletonDataFile, const char* atlasFile, float scale) { +Skeleton::Skeleton (const char* skeletonDataFile, const char* atlasFile, float scale) { initialize(); atlas = spAtlas_readAtlasFile(atlasFile); @@ -116,17 +116,17 @@ CCSkeleton::CCSkeleton (const char* skeletonDataFile, const char* atlasFile, flo setSkeletonData(skeletonData, true); } -CCSkeleton::~CCSkeleton () { +Skeleton::~Skeleton () { if (ownsSkeletonData) spSkeletonData_dispose(skeleton->data); if (atlas) spAtlas_dispose(atlas); spSkeleton_dispose(skeleton); } -void CCSkeleton::update (float deltaTime) { +void Skeleton::update (float deltaTime) { spSkeleton_update(skeleton, deltaTime * timeScale); } -void CCSkeleton::draw () { +void Skeleton::draw () { CC_NODE_DRAW_SETUP(); GL::blendFunc(blendFunc.src, blendFunc.dst); @@ -222,11 +222,11 @@ void CCSkeleton::draw () { } } -TextureAtlas* CCSkeleton::getTextureAtlas (spRegionAttachment* regionAttachment) const { +TextureAtlas* Skeleton::getTextureAtlas (spRegionAttachment* regionAttachment) const { return (TextureAtlas*)((spAtlasRegion*)regionAttachment->rendererObject)->page->rendererObject; } -Rect CCSkeleton::getBoundingBox () const { +Rect Skeleton::getBoundingBox () const { float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN; float scaleX = getScaleX(); float scaleY = getScaleY(); @@ -259,50 +259,50 @@ Rect CCSkeleton::getBoundingBox () const { // --- Convenience methods for Skeleton_* functions. -void CCSkeleton::updateWorldTransform () { +void Skeleton::updateWorldTransform () { spSkeleton_updateWorldTransform(skeleton); } -void CCSkeleton::setToSetupPose () { +void Skeleton::setToSetupPose () { spSkeleton_setToSetupPose(skeleton); } -void CCSkeleton::setBonesToSetupPose () { +void Skeleton::setBonesToSetupPose () { spSkeleton_setBonesToSetupPose(skeleton); } -void CCSkeleton::setSlotsToSetupPose () { +void Skeleton::setSlotsToSetupPose () { spSkeleton_setSlotsToSetupPose(skeleton); } -spBone* CCSkeleton::findBone (const char* boneName) const { +spBone* Skeleton::findBone (const char* boneName) const { return spSkeleton_findBone(skeleton, boneName); } -spSlot* CCSkeleton::findSlot (const char* slotName) const { +spSlot* Skeleton::findSlot (const char* slotName) const { return spSkeleton_findSlot(skeleton, slotName); } -bool CCSkeleton::setSkin (const char* skinName) { +bool Skeleton::setSkin (const char* skinName) { return spSkeleton_setSkinByName(skeleton, skinName) ? true : false; } -spAttachment* CCSkeleton::getAttachment (const char* slotName, const char* attachmentName) const { +spAttachment* Skeleton::getAttachment (const char* slotName, const char* attachmentName) const { return spSkeleton_getAttachmentForSlotName(skeleton, slotName, attachmentName); } -bool CCSkeleton::setAttachment (const char* slotName, const char* attachmentName) { +bool Skeleton::setAttachment (const char* slotName, const char* attachmentName) { return spSkeleton_setAttachment(skeleton, slotName, attachmentName) ? true : false; } // --- CCBlendProtocol -const cocos2d::BlendFunc& CCSkeleton::getBlendFunc () const { +const cocos2d::BlendFunc& Skeleton::getBlendFunc () const { return blendFunc; } -void CCSkeleton::setBlendFunc (const cocos2d::BlendFunc& aBlendFunc) { +void Skeleton::setBlendFunc (const cocos2d::BlendFunc& aBlendFunc) { this->blendFunc = aBlendFunc; } -void CCSkeleton::setFittedBlendingFunc(cocos2d::TextureAtlas * nextRenderedTexture) +void Skeleton::setFittedBlendingFunc(cocos2d::TextureAtlas * nextRenderedTexture) { if(nextRenderedTexture->getTexture() && nextRenderedTexture->getTexture()->hasPremultipliedAlpha()) { diff --git a/cocos/editor-support/spine/CCSkeleton.h b/cocos/editor-support/spine/CCSkeleton.h index abeb3fa8ce..ab4270be0d 100644 --- a/cocos/editor-support/spine/CCSkeleton.h +++ b/cocos/editor-support/spine/CCSkeleton.h @@ -42,7 +42,7 @@ namespace spine { /** Draws a skeleton. */ -class CCSkeleton: public cocos2d::Node, public cocos2d::BlendProtocol { +class Skeleton: public cocos2d::Node, public cocos2d::BlendProtocol { public: spSkeleton* skeleton; spBone* rootBone; @@ -52,15 +52,15 @@ public: bool premultipliedAlpha; cocos2d::BlendFunc blendFunc; - static CCSkeleton* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); - static CCSkeleton* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); - static CCSkeleton* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0); + static Skeleton* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); + static Skeleton* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); + static Skeleton* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0); - CCSkeleton (spSkeletonData* skeletonData, bool ownsSkeletonData = false); - CCSkeleton (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); - CCSkeleton (const char* skeletonDataFile, const char* atlasFile, float scale = 0); + Skeleton (spSkeletonData* skeletonData, bool ownsSkeletonData = false); + Skeleton (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); + Skeleton (const char* skeletonDataFile, const char* atlasFile, float scale = 0); - virtual ~CCSkeleton (); + virtual ~Skeleton (); virtual void update (float deltaTime) override; virtual void draw() override; @@ -93,7 +93,7 @@ public: virtual void setBlendFunc(const cocos2d::BlendFunc& func) override; protected: - CCSkeleton (); + Skeleton (); void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData); virtual cocos2d::TextureAtlas* getTextureAtlas (spRegionAttachment* regionAttachment) const; diff --git a/cocos/editor-support/spine/CCSkeletonAnimation.cpp b/cocos/editor-support/spine/CCSkeletonAnimation.cpp index c899de17c2..f4cd9dab9a 100644 --- a/cocos/editor-support/spine/CCSkeletonAnimation.cpp +++ b/cocos/editor-support/spine/CCSkeletonAnimation.cpp @@ -43,28 +43,28 @@ using std::vector; namespace spine { static void callback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) { - ((CCSkeletonAnimation*)state->context)->onAnimationStateEvent(trackIndex, type, event, loopCount); + ((SkeletonAnimation*)state->context)->onAnimationStateEvent(trackIndex, type, event, loopCount); } -CCSkeletonAnimation* CCSkeletonAnimation::createWithData (spSkeletonData* skeletonData) { - CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonData); +SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData) { + SkeletonAnimation* node = new SkeletonAnimation(skeletonData); node->autorelease(); return node; } -CCSkeletonAnimation* CCSkeletonAnimation::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) { - CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonDataFile, atlas, scale); +SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) { + SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlas, scale); node->autorelease(); return node; } -CCSkeletonAnimation* CCSkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) { - CCSkeletonAnimation* node = new CCSkeletonAnimation(skeletonDataFile, atlasFile, scale); +SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) { + SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlasFile, scale); node->autorelease(); return node; } -void CCSkeletonAnimation::initialize () { +void SkeletonAnimation::initialize () { listenerInstance = 0; listenerMethod = 0; @@ -74,27 +74,27 @@ void CCSkeletonAnimation::initialize () { state->listener = callback; } -CCSkeletonAnimation::CCSkeletonAnimation (spSkeletonData *skeletonData) - : CCSkeleton(skeletonData) { +SkeletonAnimation::SkeletonAnimation (spSkeletonData *skeletonData) + : Skeleton(skeletonData) { initialize(); } -CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale) - : CCSkeleton(skeletonDataFile, atlas, scale) { +SkeletonAnimation::SkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale) + : Skeleton(skeletonDataFile, atlas, scale) { initialize(); } -CCSkeletonAnimation::CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale) - : CCSkeleton(skeletonDataFile, atlasFile, scale) { +SkeletonAnimation::SkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale) + : Skeleton(skeletonDataFile, atlasFile, scale) { initialize(); } -CCSkeletonAnimation::~CCSkeletonAnimation () { +SkeletonAnimation::~SkeletonAnimation () { if (ownsAnimationStateData) spAnimationStateData_dispose(state->data); spAnimationState_dispose(state); } -void CCSkeletonAnimation::update (float deltaTime) { +void SkeletonAnimation::update (float deltaTime) { super::update(deltaTime); deltaTime *= timeScale; @@ -103,7 +103,7 @@ void CCSkeletonAnimation::update (float deltaTime) { spSkeleton_updateWorldTransform(skeleton); } -void CCSkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) { +void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) { CCAssert(stateData, "stateData cannot be null."); if (ownsAnimationStateData) spAnimationStateData_dispose(state->data); @@ -115,46 +115,46 @@ void CCSkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData state->listener = callback; } -void CCSkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration) { +void SkeletonAnimation::setMix (const char* fromAnimation, const char* toAnimation, float duration) { spAnimationStateData_setMixByName(state->data, fromAnimation, toAnimation, duration); } -void CCSkeletonAnimation::setAnimationListener (Object* instance, SEL_AnimationStateEvent method) { +void SkeletonAnimation::setAnimationListener (Object* instance, SEL_AnimationStateEvent method) { listenerInstance = instance; listenerMethod = method; } -spTrackEntry* CCSkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) { +spTrackEntry* SkeletonAnimation::setAnimation (int trackIndex, const char* name, bool loop) { spAnimation* animation = spSkeletonData_findAnimation(skeleton->data, name); if (!animation) { - CCLog("Spine: Animation not found: %s", name); + log("Spine: Animation not found: %s", name); return 0; } return spAnimationState_setAnimation(state, trackIndex, animation, loop); } -spTrackEntry* CCSkeletonAnimation::addAnimation (int trackIndex, const char* name, bool loop, float delay) { +spTrackEntry* SkeletonAnimation::addAnimation (int trackIndex, const char* name, bool loop, float delay) { spAnimation* animation = spSkeletonData_findAnimation(skeleton->data, name); if (!animation) { - CCLog("Spine: Animation not found: %s", name); + log("Spine: Animation not found: %s", name); return 0; } return spAnimationState_addAnimation(state, trackIndex, animation, loop, delay); } -spTrackEntry* CCSkeletonAnimation::getCurrent (int trackIndex) { +spTrackEntry* SkeletonAnimation::getCurrent (int trackIndex) { return spAnimationState_getCurrent(state, trackIndex); } -void CCSkeletonAnimation::clearTracks () { +void SkeletonAnimation::clearTracks () { spAnimationState_clearTracks(state); } -void CCSkeletonAnimation::clearTrack (int trackIndex) { +void SkeletonAnimation::clearTrack (int trackIndex) { spAnimationState_clearTrack(state, trackIndex); } -void CCSkeletonAnimation::onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount) { +void SkeletonAnimation::onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount) { if (listenerInstance) (listenerInstance->*listenerMethod)(this, trackIndex, type, event, loopCount); } diff --git a/cocos/editor-support/spine/CCSkeletonAnimation.h b/cocos/editor-support/spine/CCSkeletonAnimation.h index 784a6771a5..228a07b88e 100644 --- a/cocos/editor-support/spine/CCSkeletonAnimation.h +++ b/cocos/editor-support/spine/CCSkeletonAnimation.h @@ -40,25 +40,25 @@ namespace spine { -class CCSkeletonAnimation; -typedef void (cocos2d::Object::*SEL_AnimationStateEvent)(spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount); +class SkeletonAnimation; +typedef void (cocos2d::Object::*SEL_AnimationStateEvent)(spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount); #define animationStateEvent_selector(_SELECTOR) (SEL_AnimationStateEvent)(&_SELECTOR) /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be * played later. */ -class CCSkeletonAnimation: public CCSkeleton { +class SkeletonAnimation: public Skeleton { public: spAnimationState* state; - static CCSkeletonAnimation* createWithData (spSkeletonData* skeletonData); - static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); - static CCSkeletonAnimation* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0); + static SkeletonAnimation* createWithData (spSkeletonData* skeletonData); + static SkeletonAnimation* createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); + static SkeletonAnimation* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 0); - CCSkeletonAnimation (spSkeletonData* skeletonData); - CCSkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); - CCSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale = 0); + SkeletonAnimation (spSkeletonData* skeletonData); + SkeletonAnimation (const char* skeletonDataFile, spAtlas* atlas, float scale = 0); + SkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale = 0); - virtual ~CCSkeletonAnimation (); + virtual ~SkeletonAnimation (); virtual void update (float deltaTime); @@ -75,10 +75,10 @@ public: virtual void onAnimationStateEvent (int trackIndex, spEventType type, spEvent* event, int loopCount); protected: - CCSkeletonAnimation (); + SkeletonAnimation (); private: - typedef CCSkeleton super; + typedef Skeleton super; cocos2d::Object* listenerInstance; SEL_AnimationStateEvent listenerMethod; bool ownsAnimationStateData; diff --git a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp index 7d70a87640..78e70ba8e8 100644 --- a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp @@ -49,7 +49,7 @@ void SpineTestScene::runThisTest() bool SpineTestLayer::init () { if (!Layer::init()) return false; - skeletonNode = CCSkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas"); + skeletonNode = SkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas"); skeletonNode->setMix("walk", "jump", 0.2f); skeletonNode->setMix("jump", "walk", 0.4f); @@ -82,7 +82,7 @@ void SpineTestLayer::update (float deltaTime) { } -void SpineTestLayer::animationStateEvent (CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) { +void SpineTestLayer::animationStateEvent (SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) { spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex); const char* animationName = (entry && entry->animation) ? entry->animation->name : 0; diff --git a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h index a5c9d83ddd..33eea39c34 100644 --- a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h +++ b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h @@ -38,13 +38,13 @@ public: class SpineTestLayer: public cocos2d::Layer { private: - spine::CCSkeletonAnimation* skeletonNode; + spine::SkeletonAnimation* skeletonNode; public: virtual bool init (); virtual void update (float deltaTime); - void animationStateEvent (spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount); + void animationStateEvent (spine::SkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount); CREATE_FUNC (SpineTestLayer); }; diff --git a/tools/tojs/cocos2dx_spine.ini b/tools/tojs/cocos2dx_spine.ini index 62f4ba8f6a..9a6507072e 100644 --- a/tools/tojs/cocos2dx_spine.ini +++ b/tools/tojs/cocos2dx_spine.ini @@ -1,7 +1,7 @@ [cocos2dx_spine] prefix = cocos2dx_spine -target_namespace = cc +target_namespace = sp android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include android_flags = -D_SIZE_T_DEFINED_ @@ -20,12 +20,12 @@ extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h -skip = CCSkeleton::[createWithData], - CCSkeletonAnimation::[createWithData] +skip = Skeleton::[createWithData], + SkeletonAnimation::[createWithData] -classes = CCSkeleton CCSkeletonAnimation +classes = Skeleton SkeletonAnimation -remove_prefix = CC +remove_prefix = classes_have_no_parents = From 856265950d952901a3ab641b12f860842ef7e4f7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Dec 2013 11:24:02 +0800 Subject: [PATCH 22/26] Updates JS tests for SpineTest. --- samples/Javascript/Shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index fda861cde4..ff3a95b059 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit fda861cde4387948e95811966d9c4ceea04dc758 +Subproject commit ff3a95b059be8421677ed6817b73ae2ac577781d From c168dc4731498358ce8ebba7909d92562c858416 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 25 Dec 2013 11:38:46 +0800 Subject: [PATCH 23/26] fix TestCpp project can't work on debug mode on vs. --- samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index 83e04f7424..a1b18efb49 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -76,7 +76,7 @@ Level3 - EditAndContinue + OldStyle 4267;4251;4244;%(DisableSpecificWarnings) true From 598d295c6cd60ad6d6ed8d1be3725e457a747388 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 11:44:05 +0800 Subject: [PATCH 24/26] fix actionTest->DrawPrimitiveTest --- .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 23 ++++++++++++++++--- .../DrawPrimitivesTest/DrawPrimitivesTest.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index feeb4c9fe0..c027645ddf 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -1,4 +1,6 @@ #include "DrawPrimitivesTest.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" using namespace std; @@ -114,8 +116,20 @@ DrawPrimitivesTest::DrawPrimitivesTest() void DrawPrimitivesTest::draw() { + CustomCommand * cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void DrawPrimitivesTest::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewTransform); - CHECK_GL_ERROR_DEBUG(); + //draw + CHECK_GL_ERROR_DEBUG(); // draw a simple line // The default state is: @@ -127,7 +141,7 @@ void DrawPrimitivesTest::draw() CHECK_GL_ERROR_DEBUG(); - // line: color, width, aliased + // line: color, width, aliased // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible // GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone // glDisable(GL_LINE_SMOOTH); @@ -138,7 +152,7 @@ void DrawPrimitivesTest::draw() CHECK_GL_ERROR_DEBUG(); // TIP: - // If you are going to use always the same color or width, you don't + // If you are going to use always thde same color or width, you don't // need to call it before every draw // // Remember: OpenGL is a state-machine. @@ -221,6 +235,9 @@ void DrawPrimitivesTest::draw() DrawPrimitives::setPointSize(1); CHECK_GL_ERROR_DEBUG(); + + //end draw + kmGLLoadMatrix(&oldMat); } string DrawPrimitivesTest::title() const diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h index 9adef0855c..597d99f6c2 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h @@ -28,6 +28,8 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; virtual void draw(); +protected: + void onDraw(); }; class DrawNodeTest : public BaseLayer From 02c28cf8916f98dcffa69e12ca8c1c9bdfe68ccd Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 11:46:40 +0800 Subject: [PATCH 25/26] change indent to spaces --- .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index c027645ddf..9fe6f6c3fe 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -131,110 +131,110 @@ void DrawPrimitivesTest::onDraw() //draw CHECK_GL_ERROR_DEBUG(); - // draw a simple line - // The default state is: - // Line Width: 1 - // color: 255,255,255,255 (white, non-transparent) - // Anti-Aliased - // glEnable(GL_LINE_SMOOTH); + // draw a simple line + // The default state is: + // Line Width: 1 + // color: 255,255,255,255 (white, non-transparent) + // Anti-Aliased + // glEnable(GL_LINE_SMOOTH); DrawPrimitives::drawLine( VisibleRect::leftBottom(), VisibleRect::rightTop() ); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); // line: color, width, aliased - // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible - // GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone - // glDisable(GL_LINE_SMOOTH); - glLineWidth( 5.0f ); - DrawPrimitives::setDrawColor4B(255,0,0,255); + // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible + // GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone + // glDisable(GL_LINE_SMOOTH); + glLineWidth( 5.0f ); + DrawPrimitives::setDrawColor4B(255,0,0,255); DrawPrimitives::drawLine( VisibleRect::leftTop(), VisibleRect::rightBottom() ); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // TIP: - // If you are going to use always thde same color or width, you don't - // need to call it before every draw - // - // Remember: OpenGL is a state-machine. + // TIP: + // If you are going to use always thde same color or width, you don't + // need to call it before every draw + // + // Remember: OpenGL is a state-machine. - // draw big point in the center - DrawPrimitives::setPointSize(64); - DrawPrimitives::setDrawColor4B(0,0,255,128); + // draw big point in the center + DrawPrimitives::setPointSize(64); + DrawPrimitives::setDrawColor4B(0,0,255,128); DrawPrimitives::drawPoint( VisibleRect::center() ); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw 4 small points - Point points[] = { Point(60,60), Point(70,70), Point(60,70), Point(70,60) }; - DrawPrimitives::setPointSize(4); - DrawPrimitives::setDrawColor4B(0,255,255,255); - DrawPrimitives::drawPoints( points, 4); + // draw 4 small points + Point points[] = { Point(60,60), Point(70,70), Point(60,70), Point(70,60) }; + DrawPrimitives::setPointSize(4); + DrawPrimitives::setDrawColor4B(0,255,255,255); + DrawPrimitives::drawPoints( points, 4); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw a green circle with 10 segments - glLineWidth(16); - DrawPrimitives::setDrawColor4B(0, 255, 0, 255); + // draw a green circle with 10 segments + glLineWidth(16); + DrawPrimitives::setDrawColor4B(0, 255, 0, 255); DrawPrimitives::drawCircle( VisibleRect::center(), 100, 0, 10, false); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw a green circle with 50 segments with line to center - glLineWidth(2); - DrawPrimitives::setDrawColor4B(0, 255, 255, 255); + // draw a green circle with 50 segments with line to center + glLineWidth(2); + DrawPrimitives::setDrawColor4B(0, 255, 255, 255); DrawPrimitives::drawCircle( VisibleRect::center(), 50, CC_DEGREES_TO_RADIANS(90), 50, true); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw a pink solid circle with 50 segments - glLineWidth(2); - DrawPrimitives::setDrawColor4B(255, 0, 255, 255); + // draw a pink solid circle with 50 segments + glLineWidth(2); + DrawPrimitives::setDrawColor4B(255, 0, 255, 255); DrawPrimitives::drawSolidCircle( VisibleRect::center() + Point(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // open yellow poly - DrawPrimitives::setDrawColor4B(255, 255, 0, 255); - glLineWidth(10); - Point vertices[] = { Point(0,0), Point(50,50), Point(100,50), Point(100,100), Point(50,100) }; - DrawPrimitives::drawPoly( vertices, 5, false); + // open yellow poly + DrawPrimitives::setDrawColor4B(255, 255, 0, 255); + glLineWidth(10); + Point vertices[] = { Point(0,0), Point(50,50), Point(100,50), Point(100,100), Point(50,100) }; + DrawPrimitives::drawPoly( vertices, 5, false); - CHECK_GL_ERROR_DEBUG(); - - // filled poly - glLineWidth(1); - Point filledVertices[] = { Point(0,120), Point(50,120), Point(50,170), Point(25,200), Point(0,170) }; - DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) ); + CHECK_GL_ERROR_DEBUG(); + + // filled poly + glLineWidth(1); + Point filledVertices[] = { Point(0,120), Point(50,120), Point(50,170), Point(25,200), Point(0,170) }; + DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) ); - // closed purble poly - DrawPrimitives::setDrawColor4B(255, 0, 255, 255); - glLineWidth(2); - Point vertices2[] = { Point(30,130), Point(30,230), Point(50,200) }; - DrawPrimitives::drawPoly( vertices2, 3, true); + // closed purble poly + DrawPrimitives::setDrawColor4B(255, 0, 255, 255); + glLineWidth(2); + Point vertices2[] = { Point(30,130), Point(30,230), Point(50,200) }; + DrawPrimitives::drawPoly( vertices2, 3, true); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw quad bezier path + // draw quad bezier path DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); - // draw cubic bezier path + // draw cubic bezier path DrawPrimitives::drawCubicBezier(VisibleRect::center(), Point(VisibleRect::center().x+30,VisibleRect::center().y+50), Point(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); //draw a solid polygon - Point vertices3[] = {Point(60,160), Point(70,190), Point(100,190), Point(90,160)}; + Point vertices3[] = {Point(60,160), Point(70,190), Point(100,190), Point(90,160)}; DrawPrimitives::drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) ); - // restore original values - glLineWidth(1); - DrawPrimitives::setDrawColor4B(255,255,255,255); - DrawPrimitives::setPointSize(1); + // restore original values + glLineWidth(1); + DrawPrimitives::setDrawColor4B(255,255,255,255); + DrawPrimitives::setPointSize(1); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); //end draw kmGLLoadMatrix(&oldMat); @@ -274,10 +274,10 @@ DrawNodeTest::DrawNodeTest() const float w=20; const float h=50; Point star[] = { - Point(o+w,o-h), Point(o+w*2, o), // lower spike - Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike - // {o +w, o+w*2+h}, {o,o+w*2}, // top spike - // {o -h, o+w}, {o,o}, // left spike + Point(o+w,o-h), Point(o+w*2, o), // lower spike + Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike + // {o +w, o+w*2+h}, {o,o+w*2}, // top spike + // {o -h, o+w}, {o,o}, // left spike }; draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1)); @@ -289,9 +289,9 @@ DrawNodeTest::DrawNodeTest() const float w=20; const float h=50; Point star[] = { - Point(o,o), Point(o+w,o-h), Point(o+w*2, o), // lower spike - Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike - Point(o +w, o+w*2+h), Point(o,o+w*2), // top spike + Point(o,o), Point(o+w,o-h), Point(o+w*2, o), // lower spike + Point(o + w*2 + h, o+w ), Point(o + w*2, o+w*2), // right spike + Point(o +w, o+w*2+h), Point(o,o+w*2), // top spike Point(o -h, o+w), // left spike }; From 9aa48cac37b5354a4ba172dafe6b87c3a7a8e0c6 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 25 Dec 2013 03:49:23 +0000 Subject: [PATCH 26/26] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 46d0b76130..4b31f207c6 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 46d0b761304efa3f22b768aaa61577a99a82c02d +Subproject commit 4b31f207c6743c246fc2116699ab2c995db18cf3