From 3344c5243cc29ed9ebb8136d35a66e57bfd27c0d Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 24 Dec 2013 10:51:47 +0800 Subject: [PATCH 01/25] change some const char* to const std::string& --- cocos/2d/CCComponent.cpp | 8 ++--- cocos/2d/CCComponent.h | 4 +-- cocos/2d/CCComponentContainer.cpp | 7 ++--- cocos/2d/CCComponentContainer.h | 4 +-- cocos/2d/CCConfiguration.cpp | 6 ++-- cocos/2d/CCConfiguration.h | 2 +- cocos/2d/CCFontAtlasCache.cpp | 6 ++-- cocos/2d/CCFontAtlasCache.h | 6 ++-- cocos/2d/CCFontAtlasFactory.cpp | 4 +-- cocos/2d/CCFontAtlasFactory.h | 4 +-- cocos/2d/CCMenuItem.cpp | 18 +++++------ cocos/2d/CCMenuItem.h | 14 ++++----- cocos/2d/CCMotionStreak.cpp | 6 ++-- cocos/2d/CCMotionStreak.h | 4 +-- cocos/2d/CCNode.cpp | 4 +-- cocos/2d/CCNode.h | 4 +-- cocos/2d/CCNotificationCenter.cpp | 36 +++++++++++----------- cocos/2d/CCNotificationCenter.h | 20 ++++++------ cocos/2d/CCParticleExamples.cpp | 2 +- cocos/2d/CCSpriteBatchNode.cpp | 2 +- cocos/2d/CCSpriteBatchNode.h | 2 +- cocos/2d/CCTextureAtlas.cpp | 4 +-- cocos/2d/CCTextureAtlas.h | 2 +- cocos/2d/platform/CCFileUtils.cpp | 17 +++++----- cocos/2d/platform/CCFileUtils.h | 4 +-- cocos/2d/platform/CCImage.h | 2 +- cocos/2d/platform/CCImageCommon_cpp.h | 12 ++++---- cocos/2d/platform/CCSAXParser.cpp | 4 +-- cocos/2d/platform/CCSAXParser.h | 3 +- cocos/2d/platform/mac/CCEGLView.h | 2 +- cocos/2d/platform/mac/CCEGLView.mm | 2 +- cocos/2d/renderer/CCNewSprite.cpp | 2 +- cocos/2d/renderer/CCNewSprite.h | 2 +- cocos/2d/renderer/CCNewSpriteBatchNode.cpp | 2 +- cocos/2d/renderer/CCNewSpriteBatchNode.h | 2 +- cocos/2d/renderer/CCNewTextureAtlas.cpp | 2 +- cocos/2d/renderer/CCNewTextureAtlas.h | 2 +- cocos/base/CCArray.cpp | 8 ++--- cocos/base/CCArray.h | 4 +-- 39 files changed, 118 insertions(+), 121 deletions(-) diff --git a/cocos/2d/CCComponent.cpp b/cocos/2d/CCComponent.cpp index fa228d0ff7..4f8482367a 100644 --- a/cocos/2d/CCComponent.cpp +++ b/cocos/2d/CCComponent.cpp @@ -72,14 +72,14 @@ Component* Component::create(void) return ret; } -const char* Component::getName() const +const std::string& Component::getName() const { - return _name.c_str(); + return _name; } -void Component::setName(const char *name) +void Component::setName(const std::string& name) { - _name.assign(name); + _name = name; } Node* Component::getOwner() const diff --git a/cocos/2d/CCComponent.h b/cocos/2d/CCComponent.h index 3babdbba46..5631c2585f 100644 --- a/cocos/2d/CCComponent.h +++ b/cocos/2d/CCComponent.h @@ -60,8 +60,8 @@ public: virtual void setEnabled(bool b); static Component* create(void); - const char* getName() const; - void setName(const char *name); + const std::string& getName() const; + void setName(const std::string& name); void setOwner(Node *pOwner); Node* getOwner() const; diff --git a/cocos/2d/CCComponentContainer.cpp b/cocos/2d/CCComponentContainer.cpp index 0e510d8de9..905bebbe27 100644 --- a/cocos/2d/CCComponentContainer.cpp +++ b/cocos/2d/CCComponentContainer.cpp @@ -40,12 +40,10 @@ ComponentContainer::~ComponentContainer(void) CC_SAFE_DELETE(_components); } -Component* ComponentContainer::get(const char *name) const +Component* ComponentContainer::get(const std::string& name) const { Component* ret = nullptr; - CCASSERT(name != nullptr, "Argument must be non-nil"); do { - CC_BREAK_IF(nullptr == name); CC_BREAK_IF(nullptr == _components); ret = _components->at(name); @@ -77,10 +75,9 @@ bool ComponentContainer::add(Component *com) return ret; } -bool ComponentContainer::remove(const char *name) +bool ComponentContainer::remove(const std::string& name) { bool ret = false; - CCASSERT(name != nullptr, "Argument must be non-nil"); do { CC_BREAK_IF(!_components); diff --git a/cocos/2d/CCComponentContainer.h b/cocos/2d/CCComponentContainer.h index e50fbbc8d9..d895693a86 100644 --- a/cocos/2d/CCComponentContainer.h +++ b/cocos/2d/CCComponentContainer.h @@ -47,9 +47,9 @@ public: * @lua NA */ virtual ~ComponentContainer(void); - virtual Component* get(const char *name) const; + virtual Component* get(const std::string& name) const; virtual bool add(Component *com); - virtual bool remove(const char *name); + virtual bool remove(const std::string& name); virtual void removeAll(); virtual void visit(float delta); public: diff --git a/cocos/2d/CCConfiguration.cpp b/cocos/2d/CCConfiguration.cpp index ea3e64d362..07ff02933d 100644 --- a/cocos/2d/CCConfiguration.cpp +++ b/cocos/2d/CCConfiguration.cpp @@ -284,7 +284,7 @@ void Configuration::setValue(const std::string& key, const Value& value) // // load file // -void Configuration::loadConfigFile(const char *filename) +void Configuration::loadConfigFile(const std::string& filename) { ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(filename); CCASSERT(!dict.empty(), "cannot create dictionary"); @@ -312,14 +312,14 @@ void Configuration::loadConfigFile(const char *filename) if (! validMetadata) { - CCLOG("Invalid config format for file: %s", filename); + CCLOG("Invalid config format for file: %s", filename.c_str()); return; } auto dataIter = dict.find("data"); if (dataIter == dict.end() || dataIter->second.getType() != Value::Type::MAP) { - CCLOG("Expected 'data' dict, but not found. Config file: %s", filename); + CCLOG("Expected 'data' dict, but not found. Config file: %s", filename.c_str()); return; } diff --git a/cocos/2d/CCConfiguration.h b/cocos/2d/CCConfiguration.h index f0296080ec..90387d5c38 100644 --- a/cocos/2d/CCConfiguration.h +++ b/cocos/2d/CCConfiguration.h @@ -128,7 +128,7 @@ public: void gatherGPUInfo(); /** Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added. */ - void loadConfigFile(const char *filename); + void loadConfigFile(const std::string& filename); private: Configuration(void); diff --git a/cocos/2d/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp index 197aacde7f..b72b76540c 100644 --- a/cocos/2d/CCFontAtlasCache.cpp +++ b/cocos/2d/CCFontAtlasCache.cpp @@ -30,7 +30,7 @@ NS_CC_BEGIN std::unordered_map FontAtlasCache::_atlasMap; -FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) +FontAtlas * FontAtlasCache::getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) { std::string atlasName = generateFontName(fontFileName, size, glyphs, useDistanceField); FontAtlas *tempAtlas = _atlasMap[atlasName]; @@ -49,7 +49,7 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, return tempAtlas; } -FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName) +FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName) { std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM,false); FontAtlas *tempAtlas = _atlasMap[atlasName]; @@ -68,7 +68,7 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName) return tempAtlas; } -std::string FontAtlasCache::generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField) +std::string FontAtlasCache::generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField) { std::string tempName(fontFileName); diff --git a/cocos/2d/CCFontAtlasCache.h b/cocos/2d/CCFontAtlasCache.h index b64d9ea6f3..acbbb28ca9 100644 --- a/cocos/2d/CCFontAtlasCache.h +++ b/cocos/2d/CCFontAtlasCache.h @@ -38,14 +38,14 @@ class CC_DLL FontAtlasCache public: - static FontAtlas * getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); - static FontAtlas * getFontAtlasFNT(const char *fontFileName); + static FontAtlas * getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); + static FontAtlas * getFontAtlasFNT(const std::string& fontFileName); static bool releaseFontAtlas(FontAtlas *atlas); private: - static std::string generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField); + static std::string generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField); static std::unordered_map _atlasMap; }; diff --git a/cocos/2d/CCFontAtlasFactory.cpp b/cocos/2d/CCFontAtlasFactory.cpp index 5c06b2ba9c..8e532af2c5 100644 --- a/cocos/2d/CCFontAtlasFactory.cpp +++ b/cocos/2d/CCFontAtlasFactory.cpp @@ -30,7 +30,7 @@ NS_CC_BEGIN -FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) +FontAtlas * FontAtlasFactory::createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) { Font *font = Font::createWithTTF(fntFilePath, fontSize, glyphs, customGlyphs); @@ -45,7 +45,7 @@ FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fo } } -FontAtlas * FontAtlasFactory::createAtlasFromFNT(const char* fntFilePath) +FontAtlas * FontAtlasFactory::createAtlasFromFNT(const std::string& fntFilePath) { Font *font = Font::createWithFNT(fntFilePath); diff --git a/cocos/2d/CCFontAtlasFactory.h b/cocos/2d/CCFontAtlasFactory.h index d1f3604ad1..b03806dccd 100644 --- a/cocos/2d/CCFontAtlasFactory.h +++ b/cocos/2d/CCFontAtlasFactory.h @@ -36,8 +36,8 @@ class CC_DLL FontAtlasFactory public: - static FontAtlas * createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); - static FontAtlas * createAtlasFromFNT(const char* fntFilePath); + static FontAtlas * createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); + static FontAtlas * createAtlasFromFNT(const std::string& fntFilePath); private: }; diff --git a/cocos/2d/CCMenuItem.cpp b/cocos/2d/CCMenuItem.cpp index 31cf74363c..7ec1097ee1 100644 --- a/cocos/2d/CCMenuItem.cpp +++ b/cocos/2d/CCMenuItem.cpp @@ -320,7 +320,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st } // XXX: deprecated -MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) +MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) { MenuItemAtlasFont *ret = new MenuItemAtlasFont(); ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector); @@ -337,7 +337,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st } // XXX: deprecated -bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) +bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) { _target = target; CC_SAFE_RETAIN(_target); @@ -387,7 +387,7 @@ const std::string& MenuItemFont::getFontName() } // XXX: deprecated -MenuItemFont * MenuItemFont::create(const char *value, Object* target, SEL_MenuHandler selector) +MenuItemFont * MenuItemFont::create(const std::string& value, Object* target, SEL_MenuHandler selector) { MenuItemFont *ret = new MenuItemFont(); ret->initWithString(value, target, selector); @@ -422,9 +422,9 @@ MenuItemFont::~MenuItemFont() } // XXX: deprecated -bool MenuItemFont::initWithString(const char *value, Object* target, SEL_MenuHandler selector) +bool MenuItemFont::initWithString(const std::string& value, Object* target, SEL_MenuHandler selector) { - CCASSERT( value != nullptr && strlen(value) != 0, "Value length must be greater than 0"); + CCASSERT( !value.empty(), "Value length must be greater than 0"); _target = target; CC_SAFE_RETAIN(target); @@ -433,7 +433,7 @@ bool MenuItemFont::initWithString(const char *value, Object* target, SEL_MenuHan bool MenuItemFont::initWithString(const std::string& value, const ccMenuCallback& callback) { - CCASSERT( value.size() >= 0, "Value length must be greater than 0"); + CCASSERT( !value.empty(), "Value length must be greater than 0"); _fontName = _globalFontName; _fontSize = _globalFontSize; @@ -710,7 +710,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std: } // XXX deprecated -MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector) +MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector) { return MenuItemImage::create(normalImage, selectedImage, "", target, selector); } @@ -721,7 +721,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std: } // XXX deprecated -MenuItemImage * MenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector) +MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector) { MenuItemImage *ret = new MenuItemImage(); if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector)) @@ -758,7 +758,7 @@ MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std: } // XXX: deprecated -bool MenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector) +bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector) { _target = target; CC_SAFE_RETAIN(_target); diff --git a/cocos/2d/CCMenuItem.h b/cocos/2d/CCMenuItem.h index 112e23c808..d44dd60d97 100644 --- a/cocos/2d/CCMenuItem.h +++ b/cocos/2d/CCMenuItem.h @@ -217,7 +217,7 @@ public: /** creates a menu item from a string and atlas with a target/selector */ static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap); /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ - CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback); @@ -233,7 +233,7 @@ protected: virtual ~MenuItemAtlasFont(){} /** initializes a menu item from a string and atlas with a target/selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); /** initializes a menu item from a string and atlas with a target/selector */ bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback); @@ -251,7 +251,7 @@ public: /** creates a menu item from a string without target/selector. To be used with MenuItemToggle */ static MenuItemFont * create(const std::string& value = ""); /** creates a menu item from a string with a target/selector */ - CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const char *value, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const std::string& value, Object* target, SEL_MenuHandler selector); /** creates a menu item from a string with a target/selector */ static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback); @@ -306,7 +306,7 @@ protected: virtual ~MenuItemFont(); /** initializes a menu item from a string with a target/selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE bool initWithString(const std::string& value, Object* target, SEL_MenuHandler selector); /** initializes a menu item from a string with a target/selector */ bool initWithString(const std::string& value, const ccMenuCallback& callback); @@ -411,12 +411,12 @@ public: /** creates a menu item with a normal,selected and disabled image*/ static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage); /** creates a menu item with a normal and selected image with target/selector */ - CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, Object* target, SEL_MenuHandler selector); /** creates a menu item with a normal and selected image with a callable object */ static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const ccMenuCallback& callback); /** creates a menu item with a normal,selected and disabled image with target/selector */ - CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector); /** creates a menu item with a normal,selected and disabled image with a callable object */ static MenuItemImage* create(const std::string&normalImage, const std::string&selectedImage, const std::string&disabledImage, const ccMenuCallback& callback); @@ -440,7 +440,7 @@ protected: bool init(); /** initializes a menu item with a normal, selected and disabled image with target/selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector); /** initializes a menu item with a normal, selected and disabled image with a callable object */ bool initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback); diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 6034cac483..70a00b622c 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -65,7 +65,7 @@ MotionStreak::~MotionStreak() CC_SAFE_FREE(_texCoords); } -MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const Color3B& color, const char* path) +MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path) { MotionStreak *ret = new MotionStreak(); if (ret && ret->initWithFade(fade, minSeg, stroke, color, path)) @@ -91,9 +91,9 @@ MotionStreak* MotionStreak::create(float fade, float minSeg, float stroke, const return nullptr; } -bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const char* path) +bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path) { - CCASSERT(path != nullptr, "Invalid filename"); + CCASSERT(!path.empty(), "Invalid filename"); Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(path); return initWithFade(fade, minSeg, stroke, color, texture); diff --git a/cocos/2d/CCMotionStreak.h b/cocos/2d/CCMotionStreak.h index e26ccaad6f..a8aaf5e4b4 100644 --- a/cocos/2d/CCMotionStreak.h +++ b/cocos/2d/CCMotionStreak.h @@ -50,7 +50,7 @@ class CC_DLL MotionStreak : public Node, public TextureProtocol { public: /** creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture filename */ - static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const char* path); + static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path); /** creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture */ static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, Texture2D* texture); @@ -116,7 +116,7 @@ protected: virtual ~MotionStreak(); /** initializes a motion streak with fade in seconds, minimum segments, stroke's width, color and texture filename */ - bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const char* path); + bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path); /** initializes a motion streak with fade in seconds, minimum segments, stroke's width, color and texture */ bool initWithFade(float fade, float minSeg, float stroke, const Color3B& color, Texture2D* texture); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index cee03e61ac..496fcb4a11 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -1346,7 +1346,7 @@ void Node::updateTransform() child->updateTransform(); } -Component* Node::getComponent(const char *pName) +Component* Node::getComponent(const std::string& pName) { if( _componentContainer ) return _componentContainer->get(pName); @@ -1361,7 +1361,7 @@ bool Node::addComponent(Component *pComponent) return _componentContainer->add(pComponent); } -bool Node::removeComponent(const char *pName) +bool Node::removeComponent(const std::string& pName) { if( _componentContainer ) return _componentContainer->remove(pName); diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index c04c5c8fbe..af95adc220 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1322,7 +1322,7 @@ public: /** * gets a component by its name */ - Component* getComponent(const char *pName); + Component* getComponent(const std::string& pName); /** * adds a component @@ -1332,7 +1332,7 @@ public: /** * removes a component by its name */ - virtual bool removeComponent(const char *pName); + virtual bool removeComponent(const std::string& pName); /** * removes all components diff --git a/cocos/2d/CCNotificationCenter.cpp b/cocos/2d/CCNotificationCenter.cpp index 8eb36c13eb..ac24115f62 100644 --- a/cocos/2d/CCNotificationCenter.cpp +++ b/cocos/2d/CCNotificationCenter.cpp @@ -74,7 +74,7 @@ void NotificationCenter::purgeNotificationCenter(void) // // internal functions // -bool NotificationCenter::observerExisted(Object *target,const char *name, Object *sender) +bool NotificationCenter::observerExisted(Object *target, const std::string& name, Object *sender) { Object* obj = nullptr; CCARRAY_FOREACH(_observers, obj) @@ -83,7 +83,7 @@ bool NotificationCenter::observerExisted(Object *target,const char *name, Object if (!observer) continue; - if (!strcmp(observer->getName(),name) && observer->getTarget() == target && observer->getSender() == sender) + if (observer->getName().compare(name) == 0 && observer->getTarget() == target && observer->getSender() == sender) return true; } return false; @@ -94,7 +94,7 @@ bool NotificationCenter::observerExisted(Object *target,const char *name, Object // void NotificationCenter::addObserver(Object *target, SEL_CallFuncO selector, - const char *name, + const std::string& name, Object *sender) { if (this->observerExisted(target, name, sender)) @@ -108,7 +108,7 @@ void NotificationCenter::addObserver(Object *target, _observers->addObject(observer); } -void NotificationCenter::removeObserver(Object *target,const char *name) +void NotificationCenter::removeObserver(Object *target, const std::string& name) { Object* obj = nullptr; CCARRAY_FOREACH(_observers, obj) @@ -117,7 +117,7 @@ void NotificationCenter::removeObserver(Object *target,const char *name) if (!observer) continue; - if (!strcmp(observer->getName(),name) && observer->getTarget() == target) + if (observer->getName().compare(name) == 0 && observer->getTarget() == target) { _observers->removeObject(observer); return; @@ -146,7 +146,7 @@ int NotificationCenter::removeAllObservers(Object *target) return static_cast(toRemove->count()); } -void NotificationCenter::registerScriptObserver( Object *target, int handler,const char* name) +void NotificationCenter::registerScriptObserver( Object *target, int handler,const std::string& name) { if (this->observerExisted(target, name, nullptr)) @@ -161,7 +161,7 @@ void NotificationCenter::registerScriptObserver( Object *target, int handler,con _observers->addObject(observer); } -void NotificationCenter::unregisterScriptObserver(Object *target,const char* name) +void NotificationCenter::unregisterScriptObserver(Object *target,const std::string& name) { Object* obj = nullptr; CCARRAY_FOREACH(_observers, obj) @@ -170,14 +170,14 @@ void NotificationCenter::unregisterScriptObserver(Object *target,const char* nam if (!observer) continue; - if ( !strcmp(observer->getName(),name) && observer->getTarget() == target) + if ( !observer->getName().compare(name) && observer->getTarget() == target) { _observers->removeObject(observer); } } } -void NotificationCenter::postNotification(const char *name, Object *sender) +void NotificationCenter::postNotification(const std::string& name, Object *sender) { __Array* ObserversCopy = __Array::createWithCapacity(_observers->count()); ObserversCopy->addObjectsFromArray(_observers); @@ -188,11 +188,11 @@ void NotificationCenter::postNotification(const char *name, Object *sender) if (!observer) continue; - if (!strcmp(name,observer->getName()) && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr)) + if (!observer->getName().compare(name) && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr)) { if (0 != observer->getHandler()) { - BasicScriptData data(this, (void*)name); + BasicScriptData data(this, (void*)name.c_str()); ScriptEvent scriptEvent(kNotificationEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); } @@ -204,14 +204,14 @@ void NotificationCenter::postNotification(const char *name, Object *sender) } } -void NotificationCenter::postNotification(const char *name) +void NotificationCenter::postNotification(const std::string& name) { this->postNotification(name,nullptr); } -int NotificationCenter::getObserverHandlerByName(const char* name) +int NotificationCenter::getObserverHandlerByName(const std::string& name) { - if (nullptr == name || strlen(name) == 0) + if (name.empty()) { return 0; } @@ -223,7 +223,7 @@ int NotificationCenter::getObserverHandlerByName(const char* name) if (nullptr == observer) continue; - if ( 0 == strcmp(observer->getName(),name) ) + if ( 0 == observer->getName().compare(name) ) { return observer->getHandler(); break; @@ -240,7 +240,7 @@ int NotificationCenter::getObserverHandlerByName(const char* name) //////////////////////////////////////////////////////////////////////////////// NotificationObserver::NotificationObserver(Object *target, SEL_CallFuncO selector, - const char *name, + const std::string& name, Object *sender) { _target = target; @@ -278,9 +278,9 @@ SEL_CallFuncO NotificationObserver::getSelector() const return _selector; } -const char* NotificationObserver::getName() const +const std::string& NotificationObserver::getName() const { - return _name.c_str(); + return _name; } Object* NotificationObserver::getSender() const diff --git a/cocos/2d/CCNotificationCenter.h b/cocos/2d/CCNotificationCenter.h index 6935255518..f2265b1518 100644 --- a/cocos/2d/CCNotificationCenter.h +++ b/cocos/2d/CCNotificationCenter.h @@ -67,14 +67,14 @@ public: */ void addObserver(Object *target, SEL_CallFuncO selector, - const char *name, + const std::string& name, Object *sender); /** @brief Removes the observer by the specified target and name. * @param target The target of this notification. * @param name The name of this notification. */ - void removeObserver(Object *target,const char *name); + void removeObserver(Object *target,const std::string& name); /** @brief Removes all notifications registered by this target * @param target The target of this notification. @@ -86,21 +86,21 @@ public: * @note Only supports Lua Binding now. * @param handler The lua handler. */ - void registerScriptObserver(Object *target,int handler,const char* name); + void registerScriptObserver(Object *target,int handler,const std::string& name); /** Unregisters script observer */ - void unregisterScriptObserver(Object *target,const char* name); + void unregisterScriptObserver(Object *target,const std::string& name); /** @brief Posts one notification event by name. * @param name The name of this notification. */ - void postNotification(const char *name); + void postNotification(const std::string& name); /** @brief Posts one notification event by name. * @param name The name of this notification. * @param sender The object posting the notification. Can be nullptr */ - void postNotification(const char *name, Object *sender); + void postNotification(const std::string& name, Object *sender); /** @brief Gets script handler. * @note Only supports Lua Binding now. @@ -112,12 +112,12 @@ public: * @param name The name of this notification. * @return The observer script handle. */ - int getObserverHandlerByName(const char* name); + int getObserverHandlerByName(const std::string& name); private: // internal functions // Check whether the observer exists by the specified target and name. - bool observerExisted(Object *target,const char *name, Object *sender); + bool observerExisted(Object *target,const std::string& name, Object *sender); // variables // @@ -138,7 +138,7 @@ public: */ NotificationObserver(Object *target, SEL_CallFuncO selector, - const char *name, + const std::string& name, Object *sender); /** NotificationObserver destructor function @@ -168,7 +168,7 @@ public: * @js NA * @lua NA */ - const char* getName() const; + const std::string& getName() const; /** * @js NA * @lua NA diff --git a/cocos/2d/CCParticleExamples.cpp b/cocos/2d/CCParticleExamples.cpp index d2368d5cac..6f7a307db3 100644 --- a/cocos/2d/CCParticleExamples.cpp +++ b/cocos/2d/CCParticleExamples.cpp @@ -41,7 +41,7 @@ static Texture2D* getDefaultTexture() do { bool ret = false; - const char* key = "/__firePngData"; + const std::string key = "/__firePngData"; texture = Director::getInstance()->getTextureCache()->getTextureForKey(key); CC_BREAK_IF(texture != nullptr); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 2ed19e294d..874b3013d7 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -110,7 +110,7 @@ bool SpriteBatchNode::init() /* * init with FileImage */ -bool SpriteBatchNode::initWithFile(const char* fileImage, ssize_t capacity) +bool SpriteBatchNode::initWithFile(const std::string& fileImage, ssize_t capacity) { Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage); return initWithTexture(texture2D, capacity); diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index 73508fe762..a46cfa3d5f 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -95,7 +95,7 @@ public: * @js init * @lua init */ - bool initWithFile(const char* fileImage, ssize_t capacity); + bool initWithFile(const std::string& fileImage, ssize_t capacity); bool init(); /** returns the TextureAtlas object */ diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index a2751f66cb..aae93de984 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, ssize_t capac return nullptr; } -bool TextureAtlas::initWithFile(const char * file, ssize_t capacity) +bool TextureAtlas::initWithFile(const std::string& file, ssize_t capacity) { // retained in property Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file); @@ -145,7 +145,7 @@ bool TextureAtlas::initWithFile(const char * file, ssize_t capacity) } else { - CCLOG("cocos2d: Could not open file: %s", file); + CCLOG("cocos2d: Could not open file: %s", file.c_str()); return false; } } diff --git a/cocos/2d/CCTextureAtlas.h b/cocos/2d/CCTextureAtlas.h index 424d67eb99..28154cd609 100644 --- a/cocos/2d/CCTextureAtlas.h +++ b/cocos/2d/CCTextureAtlas.h @@ -81,7 +81,7 @@ public: * * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ - bool initWithFile(const char* file, ssize_t capacity); + bool initWithFile(const std::string& file, ssize_t capacity); /** initializes a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for Quads. diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 9ab635f7e0..117234cab0 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -82,7 +82,7 @@ public: { } - ValueMap dictionaryWithContentsOfFile(const char *fileName) + ValueMap dictionaryWithContentsOfFile(const std::string& fileName) { _resultType = SAX_RESULT_DICT; SAXParser parser; @@ -94,7 +94,7 @@ public: return _rootDict; } - ValueVector arrayWithContentsOfFile(const char* fileName) + ValueVector arrayWithContentsOfFile(const std::string& fileName) { _resultType = SAX_RESULT_ARRAY; SAXParser parser; @@ -491,10 +491,10 @@ void FileUtils::purgeCachedEntries() _fullPathCache.clear(); } -unsigned char* FileUtils::getFileData(const char* filename, const char* mode, ssize_t *size) +unsigned char* FileUtils::getFileData(const std::string& filename, const char* mode, ssize_t *size) { unsigned char * buffer = nullptr; - CCASSERT(filename != nullptr && size != nullptr && mode != nullptr, "Invalid parameters."); + CCASSERT(!filename.empty() && size != nullptr && mode != nullptr, "Invalid parameters."); *size = 0; do { @@ -521,7 +521,7 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, ss return buffer; } -unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, ssize_t *size) +unsigned char* FileUtils::getFileDataFromZip(const std::string& zipFilePath, const std::string& filename, ssize_t *size) { unsigned char * buffer = nullptr; unzFile file = nullptr; @@ -529,13 +529,12 @@ unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char do { - CC_BREAK_IF(!zipFilePath || !filename); - CC_BREAK_IF(strlen(zipFilePath) == 0); + CC_BREAK_IF(zipFilePath.empty()); - file = unzOpen(zipFilePath); + file = unzOpen(zipFilePath.c_str()); CC_BREAK_IF(!file); - int ret = unzLocateFile(file, filename, 1); + int ret = unzLocateFile(file, filename.c_str(), 1); CC_BREAK_IF(UNZ_OK != ret); char filePathA[260]; diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 2f8962df76..b70e7c9bc6 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -84,7 +84,7 @@ public: * @return Upon success, a pointer to the data is returned, otherwise nullptr. * @warning Recall: you are responsible for calling free() on any Non-nullptr pointer returned. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t *size); + virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t *size); /** * Gets resource file data from a zip file. @@ -94,7 +94,7 @@ public: * @return Upon success, a pointer to the data is returned, otherwise nullptr. * @warning Recall: you are responsible for calling free() on any Non-nullptr pointer returned. */ - virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, ssize_t *size); + virtual unsigned char* getFileDataFromZip(const std::string& zipFilePath, const std::string& filename, ssize_t *size); /** Returns the fullpath for a given filename. diff --git a/cocos/2d/platform/CCImage.h b/cocos/2d/platform/CCImage.h index 6351ff6439..f6d5f8772d 100644 --- a/cocos/2d/platform/CCImage.h +++ b/cocos/2d/platform/CCImage.h @@ -111,7 +111,7 @@ public: @param path the absolute file path. @return true if loaded correctly. */ - bool initWithImageFile(const char *path); + bool initWithImageFile(const std::string& path); /** @brief Load image from stream buffer. diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index 8cbafd7817..b86cbc84bd 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -395,10 +395,10 @@ Image::~Image() } } -bool Image::initWithImageFile(const char * strPath) +bool Image::initWithImageFile(const std::string& path) { - bool bRet = false; - _filePath = FileUtils::getInstance()->fullPathForFilename(strPath); + bool ret = false; + _filePath = FileUtils::getInstance()->fullPathForFilename(path); #ifdef EMSCRIPTEN // Emscripten includes a re-implementation of SDL that uses HTML5 canvas @@ -408,7 +408,7 @@ bool Image::initWithImageFile(const char * strPath) SDL_Surface *iSurf = IMG_Load(fullPath.c_str()); int size = 4 * (iSurf->w * iSurf->h); - bRet = initWithRawData((const unsigned char*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true); + ret = initWithRawData((const unsigned char*)iSurf->pixels, size, iSurf->w, iSurf->h, 8, true); unsigned int *tmp = (unsigned int *)_data; int nrPixels = iSurf->w * iSurf->h; @@ -425,13 +425,13 @@ bool Image::initWithImageFile(const char * strPath) if (buffer != nullptr && bufferLen > 0) { - bRet = initWithImageData(buffer, bufferLen); + ret = initWithImageData(buffer, bufferLen); } free(buffer); #endif // EMSCRIPTEN - return bRet; + return ret; } bool Image::initWithImageFileThreadSafe(const char *fullpath) diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index bb121e7ec1..b9890afc7b 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -111,11 +111,11 @@ bool SAXParser::parse(const char* xmlData, size_t dataLength) return tinyDoc.Accept( &printer ); } -bool SAXParser::parse(const char *file) +bool SAXParser::parse(const std::string& file) { bool ret = false; ssize_t size = 0; - char* buffer = (char*)FileUtils::getInstance()->getFileData(file, "rt", &size); + char* buffer = (char*)FileUtils::getInstance()->getFileData(file.c_str(), "rt", &size); if (buffer != nullptr && size > 0) { ret = parse(buffer, size); diff --git a/cocos/2d/platform/CCSAXParser.h b/cocos/2d/platform/CCSAXParser.h index 09d5152563..ff913523ac 100644 --- a/cocos/2d/platform/CCSAXParser.h +++ b/cocos/2d/platform/CCSAXParser.h @@ -27,6 +27,7 @@ #include "CCPlatformConfig.h" #include "platform/CCCommon.h" #include "string.h" // for size_t +#include NS_CC_BEGIN @@ -87,7 +88,7 @@ public: * @js NA * @lua NA */ - bool parse(const char *file); + bool parse(const std::string& file); /** * @js NA * @lua NA diff --git a/cocos/2d/platform/mac/CCEGLView.h b/cocos/2d/platform/mac/CCEGLView.h index 518cb7d8d2..d58d70dc4b 100644 --- a/cocos/2d/platform/mac/CCEGLView.h +++ b/cocos/2d/platform/mac/CCEGLView.h @@ -53,7 +53,7 @@ public: /* *frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. */ - bool init(const char* viewName, float width, float height, float frameZoomFactor = 1.0f); + bool init(const std::string& viewName, float width, float height, float frameZoomFactor = 1.0f); public: //void resize(int width, int height); diff --git a/cocos/2d/platform/mac/CCEGLView.mm b/cocos/2d/platform/mac/CCEGLView.mm index 0f5ef6b2c8..335b513634 100644 --- a/cocos/2d/platform/mac/CCEGLView.mm +++ b/cocos/2d/platform/mac/CCEGLView.mm @@ -325,7 +325,7 @@ EGLView::~EGLView() s_pEglView = nullptr; } -bool EGLView::init(const char *viewName, float width, float height, float frameZoomFactor) +bool EGLView::init(const std::string& viewName, float width, float height, float frameZoomFactor) { if(nullptr != _mainWindow) return true; diff --git a/cocos/2d/renderer/CCNewSprite.cpp b/cocos/2d/renderer/CCNewSprite.cpp index 6cbd62cb97..b76e5ecc25 100644 --- a/cocos/2d/renderer/CCNewSprite.cpp +++ b/cocos/2d/renderer/CCNewSprite.cpp @@ -48,7 +48,7 @@ NewSprite* NewSprite::create() return nullptr; } -NewSprite* NewSprite::create(const char *filename) +NewSprite* NewSprite::create(const std::string& filename) { NewSprite* sprite = new NewSprite(); if(sprite && sprite->initWithFile(filename)) diff --git a/cocos/2d/renderer/CCNewSprite.h b/cocos/2d/renderer/CCNewSprite.h index aeda67ab50..3dd34222b8 100644 --- a/cocos/2d/renderer/CCNewSprite.h +++ b/cocos/2d/renderer/CCNewSprite.h @@ -35,7 +35,7 @@ class NewSprite : public Sprite public: static NewSprite* create(); - static NewSprite* create(const char *filename); + static NewSprite* create(const std::string& filename); virtual void updateQuadVertices(); virtual void draw(void) override; diff --git a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp index 07aa234fce..675d6b4ed0 100644 --- a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp +++ b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp @@ -42,7 +42,7 @@ NewSpriteBatchNode *NewSpriteBatchNode::createWithTexture(Texture2D *tex, int ca return batchNode; } -NewSpriteBatchNode *NewSpriteBatchNode::create(const char *fileImage, long capacity) +NewSpriteBatchNode *NewSpriteBatchNode::create(const std::string& fileImage, long capacity) { NewSpriteBatchNode* batchNode = new NewSpriteBatchNode(); batchNode->initWithFile(fileImage, capacity); diff --git a/cocos/2d/renderer/CCNewSpriteBatchNode.h b/cocos/2d/renderer/CCNewSpriteBatchNode.h index dabae243aa..93b8c48f52 100644 --- a/cocos/2d/renderer/CCNewSpriteBatchNode.h +++ b/cocos/2d/renderer/CCNewSpriteBatchNode.h @@ -36,7 +36,7 @@ class NewSpriteBatchNode : public SpriteBatchNode static const int DEFAULT_CAPACITY = 29; public: static NewSpriteBatchNode* createWithTexture(Texture2D* tex, int capacity = DEFAULT_CAPACITY); - static NewSpriteBatchNode* create(const char* fileImage, long capacity = DEFAULT_CAPACITY); + static NewSpriteBatchNode* create(const std::string& fileImage, long capacity = DEFAULT_CAPACITY); void draw(void); diff --git a/cocos/2d/renderer/CCNewTextureAtlas.cpp b/cocos/2d/renderer/CCNewTextureAtlas.cpp index 4358669fcd..5daa2a805c 100644 --- a/cocos/2d/renderer/CCNewTextureAtlas.cpp +++ b/cocos/2d/renderer/CCNewTextureAtlas.cpp @@ -41,7 +41,7 @@ NewTextureAtlas::~NewTextureAtlas() } -NewTextureAtlas *NewTextureAtlas::create(const char *file, long capacity) +NewTextureAtlas *NewTextureAtlas::create(const std::string& file, long capacity) { NewTextureAtlas * textureAtlas = new NewTextureAtlas(); if(textureAtlas && textureAtlas->initWithFile(file, capacity)) diff --git a/cocos/2d/renderer/CCNewTextureAtlas.h b/cocos/2d/renderer/CCNewTextureAtlas.h index 9f497c76a6..844b588560 100644 --- a/cocos/2d/renderer/CCNewTextureAtlas.h +++ b/cocos/2d/renderer/CCNewTextureAtlas.h @@ -34,7 +34,7 @@ NS_CC_BEGIN class NewTextureAtlas : public TextureAtlas { public: - static NewTextureAtlas* create(const char* file, long capacity); + static NewTextureAtlas* create(const std::string& file, long capacity); static NewTextureAtlas* createWithTexture(Texture2D *texture, long capacity); void drawNumberOfQuads(long numberOfQuads, long start); diff --git a/cocos/base/CCArray.cpp b/cocos/base/CCArray.cpp index 0bb3e2b2ed..8e827878a5 100644 --- a/cocos/base/CCArray.cpp +++ b/cocos/base/CCArray.cpp @@ -122,7 +122,7 @@ __Array* __Array::createWithCapacity(int capacity) return array; } -__Array* __Array::createWithContentsOfFile(const char* fileName) +__Array* __Array::createWithContentsOfFile(const std::string& fileName) { __Array* ret = __Array::createWithContentsOfFileThreadSafe(fileName); if (ret != nullptr) @@ -132,7 +132,7 @@ __Array* __Array::createWithContentsOfFile(const char* fileName) return ret; } -__Array* __Array::createWithContentsOfFileThreadSafe(const char* fileName) +__Array* __Array::createWithContentsOfFileThreadSafe(const std::string& fileName) { return FileUtils::getInstance()->createArrayWithContentsOfFile(fileName); } @@ -465,7 +465,7 @@ __Array* __Array::createWithCapacity(ssize_t capacity) return array; } -__Array* __Array::createWithContentsOfFile(const char* fileName) +__Array* __Array::createWithContentsOfFile(const std::string& fileName) { __Array* ret = __Array::createWithContentsOfFileThreadSafe(fileName); if (ret != nullptr) @@ -475,7 +475,7 @@ __Array* __Array::createWithContentsOfFile(const char* fileName) return ret; } -__Array* __Array::createWithContentsOfFileThreadSafe(const char* fileName) +__Array* __Array::createWithContentsOfFileThreadSafe(const std::string& fileName) { ValueVector arr = FileUtils::getInstance()->getValueVectorFromFile(fileName); diff --git a/cocos/base/CCArray.h b/cocos/base/CCArray.h index 17166d7588..8b40329a26 100644 --- a/cocos/base/CCArray.h +++ b/cocos/base/CCArray.h @@ -261,7 +261,7 @@ public: @return The Array pointer generated from the file * @js NA */ - static __Array* createWithContentsOfFile(const char* pFileName); + static __Array* createWithContentsOfFile(const std::string& pFileName); /* @brief The same meaning as arrayWithContentsOfFile(), but it doesn't call autorelease, so the @@ -269,7 +269,7 @@ public: * @js NA * @lua NA */ - static __Array* createWithContentsOfFileThreadSafe(const char* pFileName); + static __Array* createWithContentsOfFileThreadSafe(const std::string& pFileName); /** * @js NA * @lua NA From 6e6ccbd5f9b3662c2f24d875d2e26bdf0fe44429 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 24 Dec 2013 15:49:58 +0800 Subject: [PATCH 02/25] change some const char* to const std::string& --- cocos/2d/CCIMEDelegate.h | 4 +- cocos/2d/CCIMEDispatcher.cpp | 7 +- cocos/2d/CCIMEDispatcher.h | 2 +- cocos/2d/CCSpriteBatchNode.cpp | 2 +- cocos/2d/CCSpriteBatchNode.h | 2 +- cocos/2d/CCTMXLayer.h | 4 +- cocos/2d/CCTMXTiledMap.h | 4 +- cocos/2d/CCTextFieldTTF.cpp | 4 +- cocos/2d/CCTextFieldTTF.h | 2 +- cocos/2d/CCTextureAtlas.cpp | 2 +- cocos/2d/CCTextureAtlas.h | 2 +- cocos/2d/CCTextureCache.cpp | 6 +- cocos/2d/CCTextureCache.h | 4 +- cocos/2d/ccTypes.cpp | 1 + cocos/2d/ccTypes.h | 2 + cocos/2d/platform/CCImage.h | 2 +- cocos/2d/platform/CCImageCommon_cpp.h | 2 +- cocos/2d/platform/ios/CCImage.mm | 92 +++++++++++++-------------- 18 files changed, 74 insertions(+), 70 deletions(-) diff --git a/cocos/2d/CCIMEDelegate.h b/cocos/2d/CCIMEDelegate.h index d7fee2e59b..053359abfc 100644 --- a/cocos/2d/CCIMEDelegate.h +++ b/cocos/2d/CCIMEDelegate.h @@ -25,9 +25,11 @@ THE SOFTWARE. #ifndef __CC_IME_DELEGATE_H__ #define __CC_IME_DELEGATE_H__ +#include #include "CCGeometry.h" NS_CC_BEGIN +extern const std::string STD_STRING_EMPTY; /** * @addtogroup input @@ -114,7 +116,7 @@ protected: * @js NA * @lua NA */ - virtual const char * getContentText() { return 0; } + virtual const std::string& getContentText() { return STD_STRING_EMPTY; } ////////////////////////////////////////////////////////////////////////// // keyboard show/hide notification diff --git a/cocos/2d/CCIMEDispatcher.cpp b/cocos/2d/CCIMEDispatcher.cpp index 8c2724e51e..7bc493c988 100644 --- a/cocos/2d/CCIMEDispatcher.cpp +++ b/cocos/2d/CCIMEDispatcher.cpp @@ -239,14 +239,13 @@ void IMEDispatcher::dispatchDeleteBackward() } while (0); } -const char * IMEDispatcher::getContentText() +const std::string& IMEDispatcher::getContentText() { - const char * contentText = 0; if (_impl && _impl->_delegateWithIme) { - contentText = _impl->_delegateWithIme->getContentText(); + return _impl->_delegateWithIme->getContentText(); } - return (contentText) ? contentText : ""; + return STD_STRING_EMPTY; } ////////////////////////////////////////////////////////////////////////// diff --git a/cocos/2d/CCIMEDispatcher.h b/cocos/2d/CCIMEDispatcher.h index d03ca15e24..ea551a4d3e 100644 --- a/cocos/2d/CCIMEDispatcher.h +++ b/cocos/2d/CCIMEDispatcher.h @@ -77,7 +77,7 @@ public: * @js NA * @lua NA */ - const char * getContentText(); + const std::string& getContentText(); ////////////////////////////////////////////////////////////////////////// // dispatch keyboard notification diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 874b3013d7..7bd45f035b 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capa * creation with File Image */ -SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/) +SpriteBatchNode* SpriteBatchNode::create(const std::string& fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new SpriteBatchNode(); batchNode->initWithFile(fileImage, capacity); diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index 260a500bb4..82adde74af 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -74,7 +74,7 @@ public: The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr. */ - static SpriteBatchNode* create(const char* fileImage, ssize_t capacity = DEFAULT_CAPACITY); + static SpriteBatchNode* create(const std::string& fileImage, ssize_t capacity = DEFAULT_CAPACITY); /** * @js ctor */ diff --git a/cocos/2d/CCTMXLayer.h b/cocos/2d/CCTMXLayer.h index 31cd4b9cbd..d153f6472d 100644 --- a/cocos/2d/CCTMXLayer.h +++ b/cocos/2d/CCTMXLayer.h @@ -143,8 +143,8 @@ public: /** Creates the tiles */ void setupTiles(); - inline const char* getLayerName(){ return _layerName.c_str(); } - inline void setLayerName(const char *layerName){ _layerName = layerName; } + inline const std::string& getLayerName(){ return _layerName; } + inline void setLayerName(const std::string& layerName){ _layerName = layerName; } /** size of the layer in tiles */ inline const Size& getLayerSize() const { return _layerSize; }; diff --git a/cocos/2d/CCTMXTiledMap.h b/cocos/2d/CCTMXTiledMap.h index a72a85ea1b..7f39531a7f 100644 --- a/cocos/2d/CCTMXTiledMap.h +++ b/cocos/2d/CCTMXTiledMap.h @@ -122,7 +122,7 @@ public: * @js NA * @lua NA */ - CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const char *layerName) const { return getLayer(layerName); }; + CC_DEPRECATED_ATTRIBUTE TMXLayer* layerNamed(const std::string& layerName) const { return getLayer(layerName); }; /** return the TMXObjectGroup for the specific group */ TMXObjectGroup* getObjectGroup(const std::string& groupName) const; @@ -130,7 +130,7 @@ public: * @js NA * @lua NA */ - CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const char *groupName) const { return getObjectGroup(groupName); }; + CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const std::string& groupName) const { return getObjectGroup(groupName); }; /** return the value for the specific property name */ Value getProperty(const std::string& propertyName) const; diff --git a/cocos/2d/CCTextFieldTTF.cpp b/cocos/2d/CCTextFieldTTF.cpp index 93ef04cd1d..6924296cfc 100644 --- a/cocos/2d/CCTextFieldTTF.cpp +++ b/cocos/2d/CCTextFieldTTF.cpp @@ -236,9 +236,9 @@ void TextFieldTTF::deleteBackward() setString(text); } -const char * TextFieldTTF::getContentText() +const std::string& TextFieldTTF::getContentText() { - return _inputText.c_str(); + return _inputText; } void TextFieldTTF::draw() diff --git a/cocos/2d/CCTextFieldTTF.h b/cocos/2d/CCTextFieldTTF.h index d36df0c547..5c011b18cc 100644 --- a/cocos/2d/CCTextFieldTTF.h +++ b/cocos/2d/CCTextFieldTTF.h @@ -182,7 +182,7 @@ protected: virtual bool canDetachWithIME() override; virtual void insertText(const char * text, int len) override; virtual void deleteBackward() override; - virtual const char * getContentText() override; + virtual const std::string& getContentText() override; private: class LengthStack; LengthStack * _lens; diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index aae93de984..cb7ab0362a 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -110,7 +110,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads) // TextureAtlas - alloc & init -TextureAtlas * TextureAtlas::create(const char* file, ssize_t capacity) +TextureAtlas * TextureAtlas::create(const std::string& file, ssize_t capacity) { TextureAtlas * textureAtlas = new TextureAtlas(); if(textureAtlas && textureAtlas->initWithFile(file, capacity)) diff --git a/cocos/2d/CCTextureAtlas.h b/cocos/2d/CCTextureAtlas.h index 28154cd609..2862b13eb0 100644 --- a/cocos/2d/CCTextureAtlas.h +++ b/cocos/2d/CCTextureAtlas.h @@ -59,7 +59,7 @@ public: /** creates a TextureAtlas with an filename and with an initial capacity for Quads. * The TextureAtlas capacity can be increased in runtime. */ - static TextureAtlas* create(const char* file , ssize_t capacity); + static TextureAtlas* create(const std::string& file , ssize_t capacity); /** creates a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for n Quads. diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 24ffcb5733..e6a4297109 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -193,13 +193,13 @@ void TextureCache::loadImage() if (generateImage) { - const char *filename = asyncStruct->filename.c_str(); + const std::string& filename = asyncStruct->filename; // generate image image = new Image(); if (image && !image->initWithImageFileThreadSafe(filename)) { CC_SAFE_RELEASE(image); - CCLOG("can not load %s", filename); + CCLOG("can not load %s", filename.c_str()); continue; } } @@ -245,7 +245,7 @@ void TextureCache::addImageAsyncCallBack(float dt) Object *target = asyncStruct->target; SEL_CallFuncO selector = asyncStruct->selector; - const char* filename = asyncStruct->filename.c_str(); + const std::string& filename = asyncStruct->filename; Texture2D *texture = nullptr; if (image) diff --git a/cocos/2d/CCTextureCache.h b/cocos/2d/CCTextureCache.h index 40aaf7be9a..4bb508bc24 100644 --- a/cocos/2d/CCTextureCache.h +++ b/cocos/2d/CCTextureCache.h @@ -124,13 +124,13 @@ public: * If "key" is nil, then a new texture will be created each time. */ Texture2D* addImage(Image *image, const std::string &key); - CC_DEPRECATED_ATTRIBUTE Texture2D* addUIImage(Image *image, const char *key) { return addImage(image,key); } + CC_DEPRECATED_ATTRIBUTE Texture2D* addUIImage(Image *image, const std::string& key) { return addImage(image,key); } /** Returns an already created texture. Returns nil if the texture doesn't exist. @since v0.99.5 */ Texture2D* getTextureForKey(const std::string& key) const; - CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const char* key) const { return getTextureForKey(key); } + CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const std::string& key) const { return getTextureForKey(key); } /** Purges the dictionary of loaded textures. * Call this method if you receive the "Memory Warning" diff --git a/cocos/2d/ccTypes.cpp b/cocos/2d/ccTypes.cpp index e0ea80029e..da1430110d 100644 --- a/cocos/2d/ccTypes.cpp +++ b/cocos/2d/ccTypes.cpp @@ -25,6 +25,7 @@ #include "ccTypes.h" NS_CC_BEGIN +const std::string STD_STRING_EMPTY(""); /** * Color3B diff --git a/cocos/2d/ccTypes.h b/cocos/2d/ccTypes.h index c5e5d36f83..7083a34d6e 100644 --- a/cocos/2d/ccTypes.h +++ b/cocos/2d/ccTypes.h @@ -471,6 +471,8 @@ public: Acceleration(): x(0), y(0), z(0), timestamp(0) {} }; +extern const std::string STD_STRING_EMPTY; + NS_CC_END #endif //__CCTYPES_H__ diff --git a/cocos/2d/platform/CCImage.h b/cocos/2d/platform/CCImage.h index f6d5f8772d..c89bcd3412 100644 --- a/cocos/2d/platform/CCImage.h +++ b/cocos/2d/platform/CCImage.h @@ -246,7 +246,7 @@ private: @param imageType the type of image, currently only supporting two types. @return true if loaded correctly. */ - bool initWithImageFileThreadSafe(const char *fullpath); + bool initWithImageFileThreadSafe(const std::string& fullpath); Format detectFormat(const unsigned char * data, ssize_t dataLen); bool isPng(const unsigned char * data, ssize_t dataLen); diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index b86cbc84bd..0184351698 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -434,7 +434,7 @@ bool Image::initWithImageFile(const std::string& path) return ret; } -bool Image::initWithImageFileThreadSafe(const char *fullpath) +bool Image::initWithImageFileThreadSafe(const std::string& fullpath) { bool ret = false; ssize_t dataLen = 0; diff --git a/cocos/2d/platform/ios/CCImage.mm b/cocos/2d/platform/ios/CCImage.mm index fdecdb9b5c..a2cc87dbec 100644 --- a/cocos/2d/platform/ios/CCImage.mm +++ b/cocos/2d/platform/ios/CCImage.mm @@ -87,20 +87,20 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize #define ALIGN_CENTER 3 #define ALIGN_BOTTOM 2 -static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign, const char * pFontName, int nSize, tImageInfo* pInfo) +static bool _initWithString(const char * text, cocos2d::Image::TextAlign align, const char * fontName, int size, tImageInfo* info) { bool bRet = false; do { - CC_BREAK_IF(! pText || ! pInfo); + CC_BREAK_IF(! text || ! info); - NSString * str = [NSString stringWithUTF8String:pText]; - NSString * fntName = [NSString stringWithUTF8String:pFontName]; + NSString * str = [NSString stringWithUTF8String:text]; + NSString * fntName = [NSString stringWithUTF8String:fontName]; CGSize dim, constrainSize; - constrainSize.width = pInfo->width; - constrainSize.height = pInfo->height; + constrainSize.width = info->width; + constrainSize.height = info->height; // On iOS custom fonts must be listed beforehand in the App info.plist (in order to be usable) and referenced only the by the font family name itself when // calling [UIFont fontWithName]. Therefore even if the developer adds 'SomeFont.ttf' or 'fonts/SomeFont.ttf' to the App .plist, the font must @@ -110,7 +110,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign fntName = [[fntName lastPathComponent] stringByDeletingPathExtension]; // create the font - id font = [UIFont fontWithName:fntName size:nSize]; + id font = [UIFont fontWithName:fntName size:size]; if (font) { @@ -120,7 +120,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign { if (!font) { - font = [UIFont systemFontOfSize:nSize]; + font = [UIFont systemFontOfSize:size]; } if (font) @@ -136,7 +136,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign if (constrainSize.height > dim.height) { // vertical alignment - unsigned int vAlignment = ((int)eAlign >> 4) & 0x0F; + unsigned int vAlignment = ((int)align >> 4) & 0x0F; if (vAlignment == ALIGN_TOP) { startH = 0; @@ -166,16 +166,16 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign float shadowStrokePaddingX = 0.0f; float shadowStrokePaddingY = 0.0f; - if ( pInfo->hasStroke ) + if ( info->hasStroke ) { - shadowStrokePaddingX = ceilf(pInfo->strokeSize); - shadowStrokePaddingY = ceilf(pInfo->strokeSize); + shadowStrokePaddingX = ceilf(info->strokeSize); + shadowStrokePaddingY = ceilf(info->strokeSize); } - if ( pInfo->hasShadow ) + if ( info->hasShadow ) { - shadowStrokePaddingX = std::max(shadowStrokePaddingX, (float)fabs(pInfo->shadowOffset.width)); - shadowStrokePaddingY = std::max(shadowStrokePaddingY, (float)fabs(pInfo->shadowOffset.height)); + shadowStrokePaddingX = std::max(shadowStrokePaddingX, (float)fabs(info->shadowOffset.width)); + shadowStrokePaddingY = std::max(shadowStrokePaddingY, (float)fabs(info->shadowOffset.height)); } // add the padding (this could be 0 if no shadow and no stroke) @@ -203,7 +203,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign } // text color - CGContextSetRGBFillColor(context, pInfo->tintColorR, pInfo->tintColorG, pInfo->tintColorB, 1); + CGContextSetRGBFillColor(context, info->tintColorR, info->tintColorG, info->tintColorB, 1); // move Y rendering to the top of the image CGContextTranslateCTM(context, 0.0f, (dim.height - shadowStrokePaddingY) ); CGContextScaleCTM(context, 1.0f, -1.0f); //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential @@ -212,30 +212,30 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign UIGraphicsPushContext(context); // measure text size with specified font and determine the rectangle to draw text in - unsigned uHoriFlag = (int)eAlign & 0x0f; - UITextAlignment align = (UITextAlignment)((2 == uHoriFlag) ? UITextAlignmentRight + unsigned uHoriFlag = (int)align & 0x0f; + UITextAlignment testAlign = (UITextAlignment)((2 == uHoriFlag) ? UITextAlignmentRight : (3 == uHoriFlag) ? UITextAlignmentCenter : UITextAlignmentLeft); // take care of stroke if needed - if ( pInfo->hasStroke ) + if ( info->hasStroke ) { CGContextSetTextDrawingMode(context, kCGTextFillStroke); - CGContextSetRGBStrokeColor(context, pInfo->strokeColorR, pInfo->strokeColorG, pInfo->strokeColorB, 1); - CGContextSetLineWidth(context, pInfo->strokeSize); + CGContextSetRGBStrokeColor(context, info->strokeColorR, info->strokeColorG, info->strokeColorB, 1); + CGContextSetLineWidth(context, info->strokeSize); } // take care of shadow if needed - if ( pInfo->hasShadow ) + if ( info->hasShadow ) { CGSize offset; - offset.height = pInfo->shadowOffset.height; - offset.width = pInfo->shadowOffset.width; - CGFloat shadowColorValues[] = {0, 0, 0, pInfo->shadowOpacity}; + offset.height = info->shadowOffset.height; + offset.width = info->shadowOffset.width; + CGFloat shadowColorValues[] = {0, 0, 0, info->shadowOpacity}; CGColorRef shadowColor = CGColorCreate (colorSpace, shadowColorValues); - CGContextSetShadowWithColor(context, offset, pInfo->shadowBlur, shadowColor); + CGContextSetShadowWithColor(context, offset, info->shadowBlur, shadowColor); CGColorRelease (shadowColor); } @@ -266,7 +266,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign float textHeight = dim.height - shadowStrokePaddingY; - if ( pInfo->shadowOffset.width < 0 ) + if ( info->shadowOffset.width < 0 ) { textOriginX = shadowStrokePaddingX; } @@ -275,7 +275,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign textOriginX = 0.0; } - if (pInfo->shadowOffset.height > 0) + if (info->shadowOffset.height > 0) { textOrigingY = startH; } @@ -289,7 +289,7 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign CGContextBeginTransparencyLayerWithRect(context, rect, nullptr); // actually draw the text in the context // XXX: ios7 casting - [str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align]; + [str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)testAlign]; CGContextEndTransparencyLayer(context); @@ -300,10 +300,10 @@ static bool _initWithString(const char * pText, cocos2d::Image::TextAlign eAlign CGContextRelease(context); // output params - pInfo->data = data; - pInfo->isPremultipliedAlpha = true; - pInfo->width = dim.width; - pInfo->height = dim.height; + info->data = data; + info->isPremultipliedAlpha = true; + info->width = dim.width; + info->height = dim.height; bRet = true; } while (0); @@ -325,12 +325,12 @@ bool Image::initWithString( } bool Image::initWithStringShadowStroke( - const char * pText, - int nWidth , - int nHeight , - TextAlign eAlignMask , - const char * pFontName , - int nSize , + const char * text, + int width , + int height , + TextAlign alignMask , + const char * fontName , + int size , float textTintR, float textTintG, float textTintB, @@ -349,8 +349,8 @@ bool Image::initWithStringShadowStroke( tImageInfo info = {0}; - info.width = nWidth; - info.height = nHeight; + info.width = width; + info.height = height; info.hasShadow = shadow; info.shadowOffset.width = shadowOffsetX; info.shadowOffset.height = shadowOffsetY; @@ -366,7 +366,7 @@ bool Image::initWithStringShadowStroke( info.tintColorB = textTintB; - if (! _initWithString(pText, eAlignMask, pFontName, nSize, &info)) + if (! _initWithString(text, alignMask, fontName, size, &info)) { return false; } @@ -380,7 +380,7 @@ bool Image::initWithStringShadowStroke( return true; } -bool Image::saveToFile(const std::string& filename, bool bIsToRGB) +bool Image::saveToFile(const std::string& filename, bool isToRGB) { bool saveToPNG = false; bool needToCopyPixels = false; @@ -392,7 +392,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) int bitsPerComponent = 8; int bitsPerPixel = hasAlpha() ? 32 : 24; - if ((! saveToPNG) || bIsToRGB) + if ((! saveToPNG) || isToRGB) { bitsPerPixel = 24; } @@ -404,7 +404,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) // The data has alpha channel, and want to save it with an RGB png file, // or want to save as jpg, remove the alpha channel. - if ((saveToPNG && hasAlpha() && bIsToRGB) + if ((saveToPNG && hasAlpha() && isToRGB) || (! saveToPNG)) { pixels = new unsigned char[myDataLength]; @@ -424,7 +424,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) // make data provider with data. CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; - if (saveToPNG && hasAlpha() && (! bIsToRGB)) + if (saveToPNG && hasAlpha() && (! isToRGB)) { bitmapInfo |= kCGImageAlphaPremultipliedLast; } From 122f97f20ada1d8986bee238e54c1ed8ecb57066 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 09:51:55 +0800 Subject: [PATCH 03/25] 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 04/25] 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 05/25] =?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 06/25] 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 07/25] =?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 08/25] 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 09/25] 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 10/25] 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 11/25] 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 12/25] 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 13/25] [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 From 699424e3c7aace537c4c04f2bf0b496e5c0b599f Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 11:53:50 +0800 Subject: [PATCH 14/25] remove ArmatureTestLayer::draw --- .../ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp | 5 ----- .../ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h | 1 - 2 files changed, 6 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index a1f1fdf11f..f0af8894d6 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -228,11 +228,6 @@ void ArmatureTestLayer::backCallback(Object *pSender) Director::getInstance()->replaceScene(s); s->release(); } -void ArmatureTestLayer::draw() -{ - Layer::draw(); -} - void TestAsynchronousLoading::onEnter() { diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 06228f8f98..f30d89beac 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -62,7 +62,6 @@ public: // overrides virtual void onEnter() override; virtual void onExit() override; - virtual void draw() override; protected: MenuItemImage *restartItem; From f2e18f32a9e81c185d61973b866c957ff0c3b3b2 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Wed, 25 Dec 2013 13:57:17 +0800 Subject: [PATCH 15/25] fix android compile error --- cocos/2d/CCTextureCache.cpp | 4 ++-- cocos/2d/CCTextureCache.h | 2 +- cocos/2d/platform/android/CCFileUtilsAndroid.cpp | 4 ++-- cocos/2d/platform/android/CCFileUtilsAndroid.h | 2 +- cocos/2d/platform/android/jni/IMEJni.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 375d5cb38f..0fd08affcf 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -326,7 +326,7 @@ Texture2D * TextureCache::addImage(const std::string &path) { #if CC_ENABLE_CACHE_TEXTURE_DATA // cache the texture file name - VolatileTextureMgr::addImageTexture(texture, fullpath.c_str()); + VolatileTextureMgr::addImageTexture(texture, fullpath); #endif // texture already retained, no need to re-retain it _textures.insert( std::make_pair(fullpath, texture) ); @@ -509,7 +509,7 @@ VolatileTexture::~VolatileTexture() CC_SAFE_RELEASE(_uiImage); } -void VolatileTextureMgr::addImageTexture(Texture2D *tt, const char* imageFileName) +void VolatileTextureMgr::addImageTexture(Texture2D *tt, const std::string& imageFileName) { if (_isReloading) { diff --git a/cocos/2d/CCTextureCache.h b/cocos/2d/CCTextureCache.h index 4bb508bc24..df94ff16a9 100644 --- a/cocos/2d/CCTextureCache.h +++ b/cocos/2d/CCTextureCache.h @@ -250,7 +250,7 @@ protected: class VolatileTextureMgr { public: - static void addImageTexture(Texture2D *tt, const char* imageFileName); + static void addImageTexture(Texture2D *tt, const std::string& imageFileName); static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition); static void addDataTexture(Texture2D *tt, void* data, int dataLen, Texture2D::PixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp index 6e9aae8eca..061cd9b789 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp @@ -247,11 +247,11 @@ Data FileUtilsAndroid::getDataFromFile(const std::string& filename) return getData(filename, false); } -unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, ssize_t * size) +unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const char* mode, ssize_t * size) { unsigned char * data = 0; - if ((! filename) || (! mode) || 0 == strlen(filename)) + if ( filename.empty() || (! mode) ) { return 0; } diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.h b/cocos/2d/platform/android/CCFileUtilsAndroid.h index 0097a2c149..f7819ab8ab 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 virtual unsigned char* getFileData(const char* filename, const char* mode, ssize_t * size) override; + CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override; /** * Gets string from a file. diff --git a/cocos/2d/platform/android/jni/IMEJni.cpp b/cocos/2d/platform/android/jni/IMEJni.cpp index 30bf6a1e47..5cc75a8fcd 100644 --- a/cocos/2d/platform/android/jni/IMEJni.cpp +++ b/cocos/2d/platform/android/jni/IMEJni.cpp @@ -74,7 +74,7 @@ extern "C" { if (JniHelper::getJavaVM()->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || ! env) { return 0; } - const char * text = cocos2d::IMEDispatcher::sharedDispatcher()->getContentText(); - return env->NewStringUTF(text); + const std::string& text = cocos2d::IMEDispatcher::sharedDispatcher()->getContentText(); + return env->NewStringUTF(text.c_str()); } } From 22a62d9d07d85b77a6e2a448c76ac0a5970d589b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 14:02:13 +0800 Subject: [PATCH 16/25] Fix TestBoundingBox --- .../CocoStudioArmatureTest/ArmatureScene.cpp | 18 ++++++++++++++---- .../CocoStudioArmatureTest/ArmatureScene.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index f0af8894d6..f1afd308cd 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -2,6 +2,8 @@ #include "../../testResource.h" #include "cocostudio/CocoStudio.h" #include "CCNodeGrid.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" using namespace cocos2d; @@ -1092,16 +1094,24 @@ std::string TestBoundingBox::title() const } void TestBoundingBox::draw() { - CC_NODE_DRAW_SETUP(); + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); + +} +void TestBoundingBox::onDraw() +{ + getShaderProgram()->use(); + getShaderProgram()->setUniformsForBuiltins(_modelViewTransform); + rect = armature->getBoundingBox(); - + DrawPrimitives::setDrawColor4B(100, 100, 100, 255); DrawPrimitives::drawRect(rect.origin, Point(rect.getMaxX(), rect.getMaxY())); } - - void TestAnchorPoint::onEnter() { ArmatureTestLayer::onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index f30d89beac..1fce072d63 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -295,6 +295,8 @@ public: cocostudio::Armature *armature; Rect rect; +protected: + void onDraw(); }; class TestAnchorPoint : public ArmatureTestLayer From 2c2953abc1434e42b821c342faa11673915e4754 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Wed, 25 Dec 2013 14:20:37 +0800 Subject: [PATCH 17/25] =?UTF-8?q?change=20=E2=80=9Cstring.compare()?= =?UTF-8?q?=E2=80=9D=20to=20=E2=80=9C=3D=3D=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCNotificationCenter.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCNotificationCenter.cpp b/cocos/2d/CCNotificationCenter.cpp index ac24115f62..7d2a647b92 100644 --- a/cocos/2d/CCNotificationCenter.cpp +++ b/cocos/2d/CCNotificationCenter.cpp @@ -83,7 +83,7 @@ bool NotificationCenter::observerExisted(Object *target, const std::string& name if (!observer) continue; - if (observer->getName().compare(name) == 0 && observer->getTarget() == target && observer->getSender() == sender) + if (observer->getName() == name && observer->getTarget() == target && observer->getSender() == sender) return true; } return false; @@ -117,7 +117,7 @@ void NotificationCenter::removeObserver(Object *target, const std::string& name) if (!observer) continue; - if (observer->getName().compare(name) == 0 && observer->getTarget() == target) + if (observer->getName() == name && observer->getTarget() == target) { _observers->removeObject(observer); return; @@ -170,7 +170,7 @@ void NotificationCenter::unregisterScriptObserver(Object *target,const std::stri if (!observer) continue; - if ( !observer->getName().compare(name) && observer->getTarget() == target) + if ( observer->getName() == name && observer->getTarget() == target) { _observers->removeObject(observer); } @@ -188,7 +188,7 @@ void NotificationCenter::postNotification(const std::string& name, Object *sende if (!observer) continue; - if (!observer->getName().compare(name) && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr)) + if (observer->getName() == name && (observer->getSender() == sender || observer->getSender() == nullptr || sender == nullptr)) { if (0 != observer->getHandler()) { @@ -223,7 +223,7 @@ int NotificationCenter::getObserverHandlerByName(const std::string& name) if (nullptr == observer) continue; - if ( 0 == observer->getName().compare(name) ) + if ( observer->getName() == name ) { return observer->getHandler(); break; From c71cd5a4070a464228851b816e90dd4fed7da1b5 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 25 Dec 2013 06:39:38 +0000 Subject: [PATCH 18/25] [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 4b31f207c6..2f60892e10 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 4b31f207c6743c246fc2116699ab2c995db18cf3 +Subproject commit 2f60892e1053a2e7dabfbab9da1058063475eb97 From e8d57154dd86b9c9a2753f6e060dfa7ee8650be4 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 14:52:49 +0800 Subject: [PATCH 19/25] fix Label->Atlas1 --- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 18 ++++++++++++++---- .../Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index 003fe790ef..b4d94d3d85 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -1,5 +1,7 @@ - #include "LabelTest.h" +#include "LabelTest.h" #include "../testResource.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" enum { kTagTileMap = 1, @@ -206,13 +208,21 @@ void Atlas1::draw() { // GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // GL_TEXTURE_2D - - _textureAtlas->drawQuads(); - + + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(Atlas1::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); + // [textureAtlas drawNumberOfQuads:3]; } +void Atlas1::onDraw() +{ + _textureAtlas->drawQuads(); +} + std::string Atlas1::title() const { return "CCTextureAtlas"; diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index 1d27def081..f939278170 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -36,6 +36,8 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; virtual void draw(); +protected: + void onDraw(); }; class LabelAtlasTest : public AtlasDemo From 19522152d52936a60fd6d2cbde810f34ab8ed8ea Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 15:05:49 +0800 Subject: [PATCH 20/25] fix Label->Atlas4 --- samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp | 8 ++++++++ samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index b4d94d3d85..57d5618a78 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -525,6 +525,14 @@ Atlas4::Atlas4() } void Atlas4::draw() +{ + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(Atlas4::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void Atlas4::onDraw() { auto s = Director::getInstance()->getWinSize(); DrawPrimitives::drawLine( Point(0, s.height/2), Point(s.width, s.height/2) ); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index f939278170..c532bef477 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -104,6 +104,8 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; +protected: + void onDraw(); }; class Atlas5 : public AtlasDemo From 7333a636c13302c52815fc970b80126f4248f5d0 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 15:13:11 +0800 Subject: [PATCH 21/25] fix Label->LabelBMFontBounds --- samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp | 8 ++++++++ samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index 57d5618a78..09280e9b63 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -1612,6 +1612,14 @@ std::string LabelBMFontBounds::subtitle() const } void LabelBMFontBounds::draw() +{ + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void LabelBMFontBounds::onDraw() { auto labelSize = label1->getContentSize(); auto origin = Director::getInstance()->getWinSize(); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index c532bef477..11c9934f93 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -376,6 +376,8 @@ public: virtual void draw(); virtual std::string title() const override; virtual std::string subtitle() const override; +protected: + void onDraw(); private: LabelBMFont *label1; }; From 142b189305b8b5dd95ada0cb39fd1585b7ec0e46 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Dec 2013 16:06:39 +0800 Subject: [PATCH 22/25] Some warning fixes. --- cocos/2d/CCActionInterval.cpp | 6 +++--- cocos/editor-support/spine/CCSkeleton.cpp | 2 +- cocos/editor-support/spine/SkeletonJson.cpp | 2 +- cocos/editor-support/spine/extension.cpp | 2 +- cocos/editor-support/spine/spine-cocos2dx.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index d35beacd81..7d4a1e0bbb 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2053,7 +2053,7 @@ void Animate::startWithTarget(Node *target) if (_animation->getRestoreOriginalFrame()) { - _origFrame = sprite->getDisplayFrame(); + _origFrame = sprite->getSpriteFrame(); _origFrame->retain(); } _nextFrame = 0; @@ -2064,7 +2064,7 @@ void Animate::stop(void) { if (_animation->getRestoreOriginalFrame() && _target) { - static_cast(_target)->setDisplayFrame(_origFrame); + static_cast(_target)->setSpriteFrame(_origFrame); } ActionInterval::stop(); @@ -2097,7 +2097,7 @@ void Animate::update(float t) if( splitTime <= t ) { AnimationFrame* frame = frames.at(i); frameToDisplay = frame->getSpriteFrame(); - static_cast(_target)->setDisplayFrame(frameToDisplay); + static_cast(_target)->setSpriteFrame(frameToDisplay); const ValueMap& dict = frame->getUserInfo(); if ( !dict.empty() ) diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index 70c342c53d..77e2243b7d 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -168,7 +168,7 @@ void Skeleton::draw () { textureAtlas = regionTextureAtlas; setFittedBlendingFunc(textureAtlas); - int quadCount = textureAtlas->getTotalQuads(); + ssize_t quadCount = textureAtlas->getTotalQuads(); if (textureAtlas->getCapacity() == quadCount) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); diff --git a/cocos/editor-support/spine/SkeletonJson.cpp b/cocos/editor-support/spine/SkeletonJson.cpp index 81bbe9e617..352c492f91 100644 --- a/cocos/editor-support/spine/SkeletonJson.cpp +++ b/cocos/editor-support/spine/SkeletonJson.cpp @@ -65,7 +65,7 @@ void spSkeletonJson_dispose (spSkeletonJson* self) { void _spSkeletonJson_setError (spSkeletonJson* self, Json* root, const char* value1, const char* value2) { char message[256]; - int length; + size_t length = 0; FREE(self->error); strcpy(message, value1); length = strlen(value1); diff --git a/cocos/editor-support/spine/extension.cpp b/cocos/editor-support/spine/extension.cpp index 4c520e06fa..2a5ca375e1 100644 --- a/cocos/editor-support/spine/extension.cpp +++ b/cocos/editor-support/spine/extension.cpp @@ -62,7 +62,7 @@ char* _readFile (const char* path, int* length) { if (!file) return 0; fseek(file, 0, SEEK_END); - *length = ftell(file); + *length = (int)ftell(file); fseek(file, 0, SEEK_SET); data = MALLOC(char, *length); diff --git a/cocos/editor-support/spine/spine-cocos2dx.h b/cocos/editor-support/spine/spine-cocos2dx.h index c4e01fe5bb..f0b597be4b 100644 --- a/cocos/editor-support/spine/spine-cocos2dx.h +++ b/cocos/editor-support/spine/spine-cocos2dx.h @@ -39,6 +39,6 @@ #include #include -void spRegionAttachment_updateQuad (spRegionAttachment* self, spSlot* slot, cocos2d::ccV3F_C4B_T2F_Quad* quad, bool premultiplied = false); +void spRegionAttachment_updateQuad (spRegionAttachment* self, spSlot* slot, cocos2d::V3F_C4B_T2F_Quad* quad, bool premultiplied = false); #endif /* SPINE_COCOS2DX_H_ */ From 218dc7c1150e932b714f02b1caffac694b7e50db Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 16:18:29 +0800 Subject: [PATCH 23/25] fix RenderTextureTest->simpleSprite --- .../RenderTextureTest/RenderTextureTest.cpp | 43 ++++++------------- .../RenderTextureTest/RenderTextureTest.h | 3 +- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index b679aeb463..096a7899f9 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -1,6 +1,8 @@ #include "CCConfiguration.h" #include "RenderTextureTest.h" #include "../testBasic.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" // Test #1 by Jason Booth (slipster216) // Test #3 by David Deaco (ddeaco) @@ -586,6 +588,17 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea } void SpriteRenderTextureBug::SimpleSprite::draw() +{ + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); + + Sprite::draw(); + +} + +void SpriteRenderTextureBug::SimpleSprite::onBeforeDraw() { if (_rt == nullptr) { @@ -595,36 +608,6 @@ void SpriteRenderTextureBug::SimpleSprite::draw() } _rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); _rt->end(); - - CC_NODE_DRAW_SETUP(); - - BlendFunc blend = getBlendFunc(); - GL::blendFunc(blend.src, blend.dst); - - GL::bindTexture2D(getTexture()->getName()); - - // - // Attributes - // - - GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); - -#define kQuadSize sizeof(_quad.bl) - long offset = (long)&_quad; - - // vertex - int diff = offsetof( V3F_C4B_T2F, vertices); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - - // texCoods - diff = offsetof( V3F_C4B_T2F, texCoords); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); - - // color - diff = offsetof( V3F_C4B_T2F, colors); - glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } SpriteRenderTextureBug::SpriteRenderTextureBug() diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index 9e37954566..03a202deec 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -113,7 +113,8 @@ public: SimpleSprite(); virtual void draw(); - + protected: + void onBeforeDraw(); public: RenderTexture *_rt; }; From 781663596392e0778ccb3f8f5f54bfa168d0cb0a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 16:38:43 +0800 Subject: [PATCH 24/25] fix ShadeNodeTest->ShaderNode --- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 24 +++++++++++++------ .../TestCpp/Classes/ShaderTest/ShaderTest.h | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 687aa6940b..8874fead6f 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -1,6 +1,8 @@ #include "ShaderTest.h" #include "../testResource.h" #include "cocos2d.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCRenderer.h" static int sceneIdx = -1; @@ -194,30 +196,38 @@ void ShaderNode::setPosition(const Point &newPosition) void ShaderNode::draw() { - CC_NODE_DRAW_SETUP(); + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(ShaderNode::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} +void ShaderNode::onDraw() +{ + return; + CC_NODE_DRAW_SETUP(); + float w = SIZE_X, h = SIZE_Y; GLfloat vertices[12] = {0,0, w,0, w,h, 0,0, 0,h, w,h}; - + // // Uniforms // getShaderProgram()->setUniformLocationWith2f(_uniformCenter, _center.x, _center.y); getShaderProgram()->setUniformLocationWith2f(_uniformResolution, _resolution.x, _resolution.y); - + // time changes all the time, so it is Ok to call OpenGL directly, and not the "cached" version glUniform1f(_uniformTime, _time); - + GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); - + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); - + glDrawArrays(GL_TRIANGLES, 0, 6); CC_INCREMENT_GL_DRAWS(1); } - /// ShaderMonjori ShaderMonjori::ShaderMonjori() diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h index 274654d808..ef5c04ef76 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h @@ -126,6 +126,9 @@ public: static ShaderNode* shaderNodeWithVertex(const char *vert, const char *frag); +protected: + void onDraw(); + private: Vertex2F _center; From 2eaba86d76ed9a1303a3ba2013d9d87e3748ac28 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Wed, 25 Dec 2013 16:54:09 +0800 Subject: [PATCH 25/25] fix ShadeNodeTest->SpriteBlur --- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 8874fead6f..d3b1565d01 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -204,7 +204,6 @@ void ShaderNode::draw() void ShaderNode::onDraw() { - return; CC_NODE_DRAW_SETUP(); float w = SIZE_X, h = SIZE_Y; @@ -448,6 +447,8 @@ public: GLuint blurLocation; GLuint subLocation; +protected: + void onDraw(); }; SpriteBlur::~SpriteBlur() @@ -530,39 +531,47 @@ void SpriteBlur::initProgram() } void SpriteBlur::draw() +{ + CustomCommand *cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(SpriteBlur::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(cmd); +} + +void SpriteBlur::onDraw() { GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); BlendFunc blend = getBlendFunc(); GL::blendFunc(blend.src, blend.dst); - + getShaderProgram()->use(); getShaderProgram()->setUniformsForBuiltins(); getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); - + GL::bindTexture2D( getTexture()->getName()); - + // // Attributes // #define kQuadSize sizeof(_quad.bl) long offset = (long)&_quad; - + // vertex int diff = offsetof( V3F_C4B_T2F, vertices); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - + // texCoods diff = offsetof( V3F_C4B_T2F, texCoords); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); - + // color diff = offsetof( V3F_C4B_T2F, colors); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); - - + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - + CC_INCREMENT_GL_DRAWS(1); }