From d590986e730ec25ab2b0ea8193f42bf521368732 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 13 Nov 2013 15:55:36 -0800 Subject: [PATCH 01/28] Constructors are protected --- cocos/2d/CCLabel.cpp | 10 +- cocos/2d/CCLabelBMFont.cpp | 8 +- cocos/2d/CCLayer.h | 76 +++--- cocos/2d/CCNode.h | 47 ++-- cocos/2d/CCScene.h | 28 +-- cocos/2d/CCSprite.cpp | 24 +- cocos/2d/CCSprite.h | 228 +++++++++--------- cocos/2d/CCTMXLayer.cpp | 8 +- cocos/2d/CCTransition.cpp | 1 - cocos/2d/ccMacros.h | 18 ++ cocos/gui/UIButton.cpp | 12 +- cocos/gui/UICheckBox.cpp | 20 +- cocos/gui/UIImageView.cpp | 4 +- cocos/gui/UILayout.cpp | 4 +- cocos/gui/UILoadingBar.cpp | 4 +- cocos/gui/UISlider.cpp | 20 +- .../GUI/CCControlExtension/CCScale9Sprite.cpp | 73 +++--- .../Classes/ActionsTest/ActionsTest.cpp | 9 - .../TestCpp/Classes/ActionsTest/ActionsTest.h | 98 ++++++++ .../ClippingNodeTest/ClippingNodeTest.cpp | 9 - .../ClippingNodeTest/ClippingNodeTest.h | 34 +++ .../ConfigurationTest/ConfigurationTest.cpp | 11 +- .../ConfigurationTest/ConfigurationTest.h | 10 + .../Scale9SpriteTest/Scale9SpriteTest.cpp | 9 - .../Scale9SpriteTest/Scale9SpriteTest.h | 28 +++ .../Classes/FileUtilsTest/FileUtilsTest.cpp | 9 - .../Classes/FileUtilsTest/FileUtilsTest.h | 10 + .../NewEventDispatcherTest.cpp | 18 +- .../PerformanceTest/PerformanceAllocTest.cpp | 7 +- .../PerformanceTest/PerformanceAllocTest.h | 10 + .../PerformanceNodeChildrenTest.h | 34 +++ .../Classes/PhysicsTest/PhysicsTest.cpp | 9 - .../TestCpp/Classes/PhysicsTest/PhysicsTest.h | 28 ++- .../Classes/SchedulerTest/SchedulerTest.cpp | 15 +- .../Classes/SchedulerTest/SchedulerTest.h | 53 +++- .../Classes/ShaderTest/ShaderTest2.cpp | 23 +- .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- samples/Cpp/TestCpp/Classes/testBasic.cpp | 19 +- samples/Cpp/TestCpp/Classes/testBasic.h | 2 +- 39 files changed, 614 insertions(+), 418 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 0dc7fc5081..45fbbeb5e6 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -119,16 +119,16 @@ Label::~Label() if (_fontAtlas) FontAtlasCache::releaseFontAtlas(_fontAtlas); - delete _reusedLetter; + _reusedLetter->release(); } bool Label::init() { if(_fontAtlas) { - _reusedLetter = new Sprite; - _reusedLetter->initWithTexture(&_fontAtlas->getTexture(0)); + _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); + _reusedLetter->retain(); return SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); } @@ -437,15 +437,13 @@ Sprite * Label::getLetter(int ID) uvRect.origin.x = _lettersInfo[ID].def.U; uvRect.origin.y = _lettersInfo[ID].def.V; - sp = new Sprite(); - sp->initWithTexture(&_fontAtlas->getTexture(_lettersInfo[ID].def.textureID),uvRect); + sp = Sprite::createWithTexture(&_fontAtlas->getTexture(_lettersInfo[ID].def.textureID), uvRect); sp->setBatchNode(this); sp->setAnchorPoint(Point(_lettersInfo[ID].def.anchorX, _lettersInfo[ID].def.anchorY)); sp->setPosition(_lettersInfo[ID].position); sp->setOpacity(_realOpacity); this->addSpriteWithoutQuad(sp, ID, ID); - sp->release(); } return sp; } diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 6749c5d107..c004cabd0f 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -511,8 +511,8 @@ bool LabelBMFont::initWithString(const std::string& theString, const std::string _imageOffset = imageOffset; - _reusedChar = new Sprite(); - _reusedChar->initWithTexture(_textureAtlas->getTexture(), Rect(0, 0, 0, 0), false); + _reusedChar = Sprite::createWithTexture(_textureAtlas->getTexture(), Rect(0, 0, 0, 0)); + _reusedChar->retain(); _reusedChar->setBatchNode(this); this->setString(theString, true); @@ -663,10 +663,8 @@ void LabelBMFont::createFontChars() } else { - fontChar = new Sprite(); - fontChar->initWithTexture(_textureAtlas->getTexture(), rect); + fontChar = Sprite::createWithTexture(_textureAtlas->getTexture(), rect); addChild(fontChar, i, i); - fontChar->release(); } // Apply label properties diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index 2aafa9a895..6120428c32 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -59,18 +59,8 @@ class CC_DLL Layer : public Node { public: /** creates a fullscreen black layer */ - static Layer *create(void); - /** - * @js ctor - */ - Layer(); - /** - * @js NA - * @lua NA - */ - virtual ~Layer(); - virtual bool init(); - + static Layer *create(); + // Deprecated touch callbacks. CC_DEPRECATED_ATTRIBUTE virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent); return false;}; CC_DEPRECATED_ATTRIBUTE virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) final {CC_UNUSED_PARAM(pTouch); CC_UNUSED_PARAM(pEvent);} @@ -109,9 +99,14 @@ public: /** @deprecated Please override onKeyReleased and check the keycode of KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE) instead. */ CC_DEPRECATED_ATTRIBUTE virtual void keyBackClicked() final {}; CC_DEPRECATED_ATTRIBUTE virtual void keyMenuClicked() final {}; - // - // Overrides - // + +protected: + Layer(); + virtual ~Layer(); + virtual bool init(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Layer); }; #ifdef __apple__ @@ -130,17 +125,7 @@ class CC_DLL LayerRGBA : public Layer, public RGBAProtocol { public: CREATE_FUNC(LayerRGBA); - /** - * @js ctor - */ - LayerRGBA(); - /** - * @js NA - * @lua NA - */ - virtual ~LayerRGBA(); - - virtual bool init(); + // // Overrides @@ -161,10 +146,18 @@ public: virtual void setOpacityModifyRGB(bool bValue) override {CC_UNUSED_PARAM(bValue);} virtual bool isOpacityModifyRGB() const override { return false; } + protected: + LayerRGBA(); + virtual ~LayerRGBA(); + virtual bool init(); + GLubyte _displayedOpacity, _realOpacity; Color3B _displayedColor, _realColor; bool _cascadeOpacityEnabled, _cascadeColorEnabled; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(LayerRGBA); }; // @@ -188,27 +181,6 @@ public: static LayerColor * create(const Color4B& color, GLfloat width, GLfloat height); /** creates a Layer with color. Width and height are the window size. */ static LayerColor * create(const Color4B& color); - /** - * @js ctor - */ - LayerColor(); - /** - * @js NA - * @lua NA - */ - virtual ~LayerColor(); - - virtual bool init(); - /** initializes a Layer with color, width and height in Points - * @js init - * @lua init - */ - bool initWithColor(const Color4B& color, GLfloat width, GLfloat height); - /** initializes a Layer with color. Width and height are the window size. - * @js init - * @lua init - */ - bool initWithColor(const Color4B& color); /** change width in Points*/ void changeWidth(GLfloat w); @@ -242,11 +214,21 @@ public: virtual void setBlendFunc(const BlendFunc& blendFunc) override; protected: + LayerColor(); + virtual ~LayerColor(); + virtual bool init(); + bool initWithColor(const Color4B& color, GLfloat width, GLfloat height); + bool initWithColor(const Color4B& color); + virtual void updateColor(); BlendFunc _blendFunc; Vertex2F _squareVertices[4]; Color4F _squareColors[4]; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(LayerColor); + }; // diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 5a363c8053..65f94f565d 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -152,25 +152,6 @@ public: */ static Node * create(void); - /** - * Default constructor - * @js ctor - */ - Node(void); - - /** - * Default destructor - * @js NA - * @lua NA - */ - virtual ~Node(void); - - /** - * Initializes the instance of Node - * @return Whether the initialization was successful. - */ - virtual bool init(); - /** * Gets the description string. It makes debugging easier. * @return A string terminated with '\0' @@ -1413,7 +1394,11 @@ public: #endif protected: - + // Nodes should be created using create(); + Node(); + virtual ~Node(); + virtual bool init(); + /// lazy allocs void childrenAlloc(void); @@ -1496,6 +1481,9 @@ protected: #ifdef CC_USE_PHYSICS PhysicsBody* _physicsBody; ///< the physicsBody the node have #endif + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Node); }; //#pragma mark - NodeRGBA @@ -1512,18 +1500,6 @@ protected: class CC_DLL NodeRGBA : public Node, public RGBAProtocol { public: - /** - * @js ctor - */ - NodeRGBA(); - /** - * @js NA - * @lua NA - */ - virtual ~NodeRGBA(); - - virtual bool init(); - // overrides virtual GLubyte getOpacity() const override; virtual GLubyte getDisplayedOpacity() const override; @@ -1543,12 +1519,19 @@ public: virtual bool isOpacityModifyRGB() const override { return false; }; protected: + NodeRGBA(); + virtual ~NodeRGBA(); + virtual bool init(); + GLubyte _displayedOpacity; GLubyte _realOpacity; Color3B _displayedColor; Color3B _realColor; bool _cascadeColorEnabled; bool _cascadeOpacityEnabled; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(NodeRGBA); }; // end of base_node group diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index 19f5c5f1cc..5355541096 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -56,18 +56,9 @@ public: static Scene *createWithPhysics(); #endif - Scene(); - /** - * @js NA - * @lua NA - */ - virtual ~Scene(); - - bool init(); - + #ifdef CC_USE_PHYSICS public: - bool initWithPhysics(); inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } @@ -77,14 +68,23 @@ public: virtual void update(float delta) override; protected: - virtual void addChildToPhysicsWorld(Node* child); - -protected: + bool initWithPhysics(); + void addChildToPhysicsWorld(Node* child); + PhysicsWorld* _physicsWorld; #endif // CC_USE_PHYSICS - + + +protected: + Scene(); + virtual ~Scene(); + bool init(); + friend class Node; friend class SpriteBatchNode; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Scene); }; // end of scene group diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 186f569676..60f86ff429 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -70,10 +70,10 @@ Sprite* Sprite::createWithTexture(Texture2D *texture) return NULL; } -Sprite* Sprite::createWithTexture(Texture2D *texture, const Rect& rect) +Sprite* Sprite::createWithTexture(Texture2D *texture, const Rect& rect, bool rotated) { Sprite *sprite = new Sprite(); - if (sprite && sprite->initWithTexture(texture, rect)) + if (sprite && sprite->initWithTexture(texture, rect, rotated)) { sprite->autorelease(); return sprite; @@ -304,12 +304,18 @@ Sprite::~Sprite(void) CC_SAFE_RELEASE(_texture); } + +void Sprite::setTexture(const std::string &filename) +{ + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + setTexture(texture); +} + void Sprite::setTextureRect(const Rect& rect) { setTextureRect(rect, false, rect.size); } - void Sprite::setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) { _rectRotated = rotated; @@ -982,7 +988,17 @@ void Sprite::updateDisplayedOpacity(GLubyte opacity) // Frames -void Sprite::setDisplayFrame(SpriteFrame *pNewFrame) +void Sprite::setSpriteFrame(const std::string &spriteFrameName) +{ + SpriteFrameCache *cache = SpriteFrameCache::getInstance(); + SpriteFrame *spriteFrame = cache->getSpriteFrameByName(spriteFrameName); + + CCASSERT(spriteFrame, "Invalid spriteFrameName"); + + setSpriteFrame(spriteFrame); +} + +void Sprite::setSpriteFrame(SpriteFrame *pNewFrame) { _unflippedOffsetPositionFromCenter = pNewFrame->getOffset(); diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 317effad84..a0c70d4705 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -133,9 +133,10 @@ public: * @param texture A pointer to an existing Texture2D object. * You can use a Texture2D object for many sprites. * @param rect Only the contents inside the rect of this texture will be applied for this sprite. + * @param rotated Whether or not the rect is rotated * @return A valid sprite object that is marked as autoreleased. */ - static Sprite* createWithTexture(Texture2D *texture, const Rect& rect); + static Sprite* createWithTexture(Texture2D *texture, const Rect& rect, bool rotated=false); /** * Creates a sprite with an sprite frame. @@ -159,113 +160,6 @@ public: /// @} end of creators group - /// @{ - /// @name Initializers - - /** - * Default constructor - * @js ctor - */ - Sprite(void); - - /** - * Default destructor - * @js NA - * @lua NA - */ - virtual ~Sprite(void); - - /** - * Initializes an empty sprite with nothing init. - */ - virtual bool init(void); - - /** - * Initializes a sprite with a texture. - * - * After initialization, the rect used will be the size of the texture, and the offset will be (0,0). - * - * @param texture A pointer to an existing Texture2D object. - * You can use a Texture2D object for many sprites. - * @return true if the sprite is initialized properly, false otherwise. - */ - virtual bool initWithTexture(Texture2D *texture); - - /** - * Initializes a sprite with a texture and a rect. - * - * After initialization, the offset will be (0,0). - * - * @param texture A pointer to an exisiting Texture2D object. - * You can use a Texture2D object for many sprites. - * @param rect Only the contents inside rect of this texture will be applied for this sprite. - * @return true if the sprite is initialized properly, false otherwise. - */ - virtual bool initWithTexture(Texture2D *texture, const Rect& rect); - - /** - * Initializes a sprite with a texture and a rect in points, optionally rotated. - * - * After initialization, the offset will be (0,0). - * @note This is the designated initializer. - * - * @param texture A Texture2D object whose texture will be applied to this sprite. - * @param rect A rectangle assigned the contents of texture. - * @param rotated Whether or not the texture rectangle is rotated. - * @return true if the sprite is initialized properly, false otherwise. - */ - virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated); - - /** - * Initializes a sprite with an SpriteFrame. The texture and rect in SpriteFrame will be applied on this sprite - * - * @param pSpriteFrame A SpriteFrame object. It should includes a valid texture and a rect - * @return true if the sprite is initialized properly, false otherwise. - */ - virtual bool initWithSpriteFrame(SpriteFrame *pSpriteFrame); - - /** - * Initializes a sprite with an sprite frame name. - * - * A SpriteFrame will be fetched from the SpriteFrameCache by name. - * If the SpriteFrame doesn't exist it will raise an exception. - * - * @param spriteFrameName A key string that can fected a volid SpriteFrame from SpriteFrameCache - * @return true if the sprite is initialized properly, false otherwise. - */ - virtual bool initWithSpriteFrameName(const std::string& spriteFrameName); - - /** - * Initializes a sprite with an image filename. - * - * This method will find filename from local file system, load its content to Texture2D, - * then use Texture2D to create a sprite. - * After initialization, the rect used will be the size of the image. The offset will be (0,0). - * - * @param filename The path to an image file in local file system - * @return true if the sprite is initialized properly, false otherwise. - * @js init - * @lua init - */ - virtual bool initWithFile(const std::string& filename); - - /** - * Initializes a sprite with an image filename, and a rect. - * - * This method will find filename from local file system, load its content to Texture2D, - * then use Texture2D to create a sprite. - * After initialization, the offset will be (0,0). - * - * @param filename The path to an image file in local file system. - * @param rect The rectangle assigned the content area from texture. - * @return true if the sprite is initialized properly, false otherwise. - * @js init - * @lua init - */ - virtual bool initWithFile(const std::string& filename, const Rect& rect); - - /// @} end of initializers - /// @{ /// @name BatchNode methods @@ -298,7 +192,10 @@ public: /// @{ - /// @name Texture methods + /// @name Texture / Frame methods + + /** Sets a new texture (from a filename) to the sprite */ + virtual void setTexture(const std::string &filename ); /** * Updates the texture rect of the Sprite in points. @@ -320,17 +217,14 @@ public: */ virtual void setVertexRect(const Rect& rect); - /// @} end of texture methods - - - - /// @{ - /// @name Frames methods - /** - * Sets a new display frame to the Sprite. + * Sets a new SpriteFrame to the Sprite. */ - virtual void setDisplayFrame(SpriteFrame *pNewFrame); + virtual void setSpriteFrame(SpriteFrame* newFrame); + virtual void setSpriteFrame(const std::string &spriteFrameName); + + /** @deprecated Use `setSpriteFrame()` instead. */ + virtual void setDisplayFrame(SpriteFrame *newFrame) CC_DEPRECATED_ATTRIBUTE { setSpriteFrame(newFrame); } /** * Returns whether or not a SpriteFrame is being displayed @@ -531,6 +425,97 @@ public: /// @} protected: + + Sprite(void); + virtual ~Sprite(void); + + /* Initializes an empty sprite with nothing init. */ + virtual bool init(void); + + /** + * Initializes a sprite with a texture. + * + * After initialization, the rect used will be the size of the texture, and the offset will be (0,0). + * + * @param texture A pointer to an existing Texture2D object. + * You can use a Texture2D object for many sprites. + * @return true if the sprite is initialized properly, false otherwise. + */ + virtual bool initWithTexture(Texture2D *texture); + + /** + * Initializes a sprite with a texture and a rect. + * + * After initialization, the offset will be (0,0). + * + * @param texture A pointer to an exisiting Texture2D object. + * You can use a Texture2D object for many sprites. + * @param rect Only the contents inside rect of this texture will be applied for this sprite. + * @return true if the sprite is initialized properly, false otherwise. + */ + virtual bool initWithTexture(Texture2D *texture, const Rect& rect); + + /** + * Initializes a sprite with a texture and a rect in points, optionally rotated. + * + * After initialization, the offset will be (0,0). + * @note This is the designated initializer. + * + * @param texture A Texture2D object whose texture will be applied to this sprite. + * @param rect A rectangle assigned the contents of texture. + * @param rotated Whether or not the texture rectangle is rotated. + * @return true if the sprite is initialized properly, false otherwise. + */ + virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated); + + /** + * Initializes a sprite with an SpriteFrame. The texture and rect in SpriteFrame will be applied on this sprite + * + * @param pSpriteFrame A SpriteFrame object. It should includes a valid texture and a rect + * @return true if the sprite is initialized properly, false otherwise. + */ + virtual bool initWithSpriteFrame(SpriteFrame *pSpriteFrame); + + /** + * Initializes a sprite with an sprite frame name. + * + * A SpriteFrame will be fetched from the SpriteFrameCache by name. + * If the SpriteFrame doesn't exist it will raise an exception. + * + * @param spriteFrameName A key string that can fected a volid SpriteFrame from SpriteFrameCache + * @return true if the sprite is initialized properly, false otherwise. + */ + virtual bool initWithSpriteFrameName(const std::string& spriteFrameName); + + /** + * Initializes a sprite with an image filename. + * + * This method will find filename from local file system, load its content to Texture2D, + * then use Texture2D to create a sprite. + * After initialization, the rect used will be the size of the image. The offset will be (0,0). + * + * @param filename The path to an image file in local file system + * @return true if the sprite is initialized properly, false otherwise. + * @js init + * @lua init + */ + virtual bool initWithFile(const std::string& filename); + + /** + * Initializes a sprite with an image filename, and a rect. + * + * This method will find filename from local file system, load its content to Texture2D, + * then use Texture2D to create a sprite. + * After initialization, the offset will be (0,0). + * + * @param filename The path to an image file in local file system. + * @param rect The rectangle assigned the content area from texture. + * @return true if the sprite is initialized properly, false otherwise. + * @js init + * @lua init + */ + virtual bool initWithFile(const std::string& filename, const Rect& rect); + void updateColor(void); virtual void setTextureCoords(Rect rect); virtual void updateBlendFunc(void); @@ -575,8 +560,11 @@ protected: bool _opacityModifyRGB; // image is flipped - bool _flippedX; /// Whether the sprite is flipped horizontally or not - bool _flippedY; /// Whether the sprite is flipped vertically or not + bool _flippedX; /// Whether the sprite is flipped horizontally or not + bool _flippedY; /// Whether the sprite is flipped vertically or not + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Sprite); }; diff --git a/cocos/2d/CCTMXLayer.cpp b/cocos/2d/CCTMXLayer.cpp index aa48b8b2b4..87a9893126 100644 --- a/cocos/2d/CCTMXLayer.cpp +++ b/cocos/2d/CCTMXLayer.cpp @@ -294,9 +294,9 @@ Sprite* TMXLayer::reusedTileWithRect(Rect rect) { if (! _reusedTile) { - _reusedTile = new Sprite(); - _reusedTile->initWithTexture(_textureAtlas->getTexture(), rect, false); + _reusedTile = Sprite::createWithTexture(_textureAtlas->getTexture(), rect); _reusedTile->setBatchNode(this); + _reusedTile->retain(); } else { @@ -335,8 +335,7 @@ Sprite * TMXLayer::getTileAt(const Point& pos) Rect rect = _tileSet->rectForGID(gid); rect = CC_RECT_PIXELS_TO_POINTS(rect); - tile = new Sprite(); - tile->initWithTexture(this->getTexture(), rect); + tile = Sprite::createWithTexture(this->getTexture(), rect); tile->setBatchNode(this); tile->setPosition(getPositionAt(pos)); tile->setVertexZ((float)getVertexZForPos(pos)); @@ -345,7 +344,6 @@ Sprite * TMXLayer::getTileAt(const Point& pos) unsigned int indexForZ = atlasIndexForExistantZ(z); this->addSpriteWithoutQuad(tile, indexForZ, z); - tile->release(); } } diff --git a/cocos/2d/CCTransition.cpp b/cocos/2d/CCTransition.cpp index 4642b7404b..4477c9a41a 100644 --- a/cocos/2d/CCTransition.cpp +++ b/cocos/2d/CCTransition.cpp @@ -77,7 +77,6 @@ bool TransitionScene::initWithDuration(float t, Scene *scene) if (_outScene == NULL) { _outScene = Scene::create(); - _outScene->init(); } _outScene->retain(); diff --git a/cocos/2d/ccMacros.h b/cocos/2d/ccMacros.h index dbea2d512a..f82f3c9284 100644 --- a/cocos/2d/ccMacros.h +++ b/cocos/2d/ccMacros.h @@ -257,4 +257,22 @@ extern unsigned int CC_DLL g_uNumberOfDraws; */ #define AnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification" +// A macro to disallow the copy constructor and operator= functions +// This should be used in the private: declarations for a class +#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#define CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + CC_DISALLOW_COPY_AND_ASSIGN(TypeName) + + + #endif // __CCMACROS_H__ diff --git a/cocos/gui/UIButton.cpp b/cocos/gui/UIButton.cpp index d18627be1e..a8ccb322ee 100644 --- a/cocos/gui/UIButton.cpp +++ b/cocos/gui/UIButton.cpp @@ -193,10 +193,10 @@ void UIButton::loadTextureNormal(const char* normal,TextureResType texType) switch (_normalTexType) { case UI_TEX_TYPE_LOCAL: - dynamic_cast(_buttonNormalRenderer)->initWithFile(normal); + dynamic_cast(_buttonNormalRenderer)->setTexture(normal); break; case UI_TEX_TYPE_PLIST: - dynamic_cast(_buttonNormalRenderer)->initWithSpriteFrameName(normal); + dynamic_cast(_buttonNormalRenderer)->setSpriteFrame(normal); break; default: break; @@ -239,10 +239,10 @@ void UIButton::loadTexturePressed(const char* selected,TextureResType texType) switch (_pressedTexType) { case UI_TEX_TYPE_LOCAL: - dynamic_cast(_buttonClickedRenderer)->initWithFile(selected); + dynamic_cast(_buttonClickedRenderer)->setTexture(selected); break; case UI_TEX_TYPE_PLIST: - dynamic_cast(_buttonClickedRenderer)->initWithSpriteFrameName(selected); + dynamic_cast(_buttonClickedRenderer)->setSpriteFrame(selected); break; default: break; @@ -285,10 +285,10 @@ void UIButton::loadTextureDisabled(const char* disabled,TextureResType texType) switch (_disabledTexType) { case UI_TEX_TYPE_LOCAL: - dynamic_cast(_buttonDisableRenderer)->initWithFile(disabled); + dynamic_cast(_buttonDisableRenderer)->setTexture(disabled); break; case UI_TEX_TYPE_PLIST: - dynamic_cast(_buttonDisableRenderer)->initWithSpriteFrameName(disabled); + dynamic_cast(_buttonDisableRenderer)->setSpriteFrame(disabled); break; default: break; diff --git a/cocos/gui/UICheckBox.cpp b/cocos/gui/UICheckBox.cpp index 511d03a7ea..21d5be4f0a 100644 --- a/cocos/gui/UICheckBox.cpp +++ b/cocos/gui/UICheckBox.cpp @@ -112,10 +112,10 @@ void UICheckBox::loadTextureBackGround(const char *backGround,TextureResType tex switch (_backGroundTexType) { case UI_TEX_TYPE_LOCAL: - _backGroundBoxRenderer->initWithFile(backGround); + _backGroundBoxRenderer->setTexture(backGround); break; case UI_TEX_TYPE_PLIST: - _backGroundBoxRenderer->initWithSpriteFrameName(backGround); + _backGroundBoxRenderer->setSpriteFrame(backGround); break; default: break; @@ -136,10 +136,10 @@ void UICheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,Te switch (_backGroundSelectedTexType) { case UI_TEX_TYPE_LOCAL: - _backGroundSelectedBoxRenderer->initWithFile(backGroundSelected); + _backGroundSelectedBoxRenderer->setTexture(backGroundSelected); break; case UI_TEX_TYPE_PLIST: - _backGroundSelectedBoxRenderer->initWithSpriteFrameName(backGroundSelected); + _backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected); break; default: break; @@ -160,10 +160,10 @@ void UICheckBox::loadTextureFrontCross(const char *cross,TextureResType texType) switch (_frontCrossTexType) { case UI_TEX_TYPE_LOCAL: - _frontCrossRenderer->initWithFile(cross); + _frontCrossRenderer->setTexture(cross); break; case UI_TEX_TYPE_PLIST: - _frontCrossRenderer->initWithSpriteFrameName(cross); + _frontCrossRenderer->setSpriteFrame(cross); break; default: break; @@ -184,10 +184,10 @@ void UICheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,Te switch (_backGroundDisabledTexType) { case UI_TEX_TYPE_LOCAL: - _backGroundBoxDisabledRenderer->initWithFile(backGroundDisabled); + _backGroundBoxDisabledRenderer->setTexture(backGroundDisabled); break; case UI_TEX_TYPE_PLIST: - _backGroundBoxDisabledRenderer->initWithSpriteFrameName(backGroundDisabled); + _backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled); break; default: break; @@ -208,10 +208,10 @@ void UICheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,Te switch (_frontCrossDisabledTexType) { case UI_TEX_TYPE_LOCAL: - _frontCrossDisabledRenderer->initWithFile(frontCrossDisabled); + _frontCrossDisabledRenderer->setTexture(frontCrossDisabled); break; case UI_TEX_TYPE_PLIST: - _frontCrossDisabledRenderer->initWithSpriteFrameName(frontCrossDisabled); + _frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled); break; default: break; diff --git a/cocos/gui/UIImageView.cpp b/cocos/gui/UIImageView.cpp index 68d604f21a..6316663231 100644 --- a/cocos/gui/UIImageView.cpp +++ b/cocos/gui/UIImageView.cpp @@ -92,7 +92,7 @@ void UIImageView::loadTexture(const char *fileName, TextureResType texType) } else { - DYNAMIC_CAST_CCSPRITE->initWithFile(fileName); + DYNAMIC_CAST_CCSPRITE->setTexture(fileName); DYNAMIC_CAST_CCSPRITE->setColor(getColor()); DYNAMIC_CAST_CCSPRITE->setOpacity(getOpacity()); } @@ -107,7 +107,7 @@ void UIImageView::loadTexture(const char *fileName, TextureResType texType) } else { - DYNAMIC_CAST_CCSPRITE->initWithSpriteFrameName(fileName); + DYNAMIC_CAST_CCSPRITE->setSpriteFrame(fileName); DYNAMIC_CAST_CCSPRITE->setColor(getColor()); DYNAMIC_CAST_CCSPRITE->setOpacity(getOpacity()); } diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 9a25d57b13..756f25b9ca 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -214,10 +214,10 @@ void UILayout::setBackGroundImage(const char* fileName,TextureResType texType) switch (_bgImageTexType) { case UI_TEX_TYPE_LOCAL: - dynamic_cast(_backGroundImage)->initWithFile(fileName); + dynamic_cast(_backGroundImage)->setTexture(fileName); break; case UI_TEX_TYPE_PLIST: - dynamic_cast(_backGroundImage)->initWithSpriteFrameName(fileName); + dynamic_cast(_backGroundImage)->setSpriteFrame(fileName); break; default: break; diff --git a/cocos/gui/UILoadingBar.cpp b/cocos/gui/UILoadingBar.cpp index 09b78c7b25..11362d61bb 100644 --- a/cocos/gui/UILoadingBar.cpp +++ b/cocos/gui/UILoadingBar.cpp @@ -121,7 +121,7 @@ void UILoadingBar::loadTexture(const char* texture,TextureResType texType) } else { - dynamic_cast(_barRenderer)->initWithFile(texture); + dynamic_cast(_barRenderer)->setTexture(texture); } break; case UI_TEX_TYPE_PLIST: @@ -132,7 +132,7 @@ void UILoadingBar::loadTexture(const char* texture,TextureResType texType) } else { - dynamic_cast(_barRenderer)->initWithSpriteFrameName(texture); + dynamic_cast(_barRenderer)->setSpriteFrame(texture); } break; default: diff --git a/cocos/gui/UISlider.cpp b/cocos/gui/UISlider.cpp index d8f2f95e86..51333f1cee 100644 --- a/cocos/gui/UISlider.cpp +++ b/cocos/gui/UISlider.cpp @@ -111,7 +111,7 @@ void UISlider::loadBarTexture(const char* fileName, TextureResType texType) } else { - dynamic_cast(_barRenderer)->initWithFile(fileName); + dynamic_cast(_barRenderer)->setTexture(fileName); } break; case UI_TEX_TYPE_PLIST: @@ -121,7 +121,7 @@ void UISlider::loadBarTexture(const char* fileName, TextureResType texType) } else { - dynamic_cast(_barRenderer)->initWithSpriteFrameName(fileName); + dynamic_cast(_barRenderer)->setSpriteFrame(fileName); } break; default: @@ -157,7 +157,7 @@ void UISlider::loadProgressBarTexture(const char *fileName, TextureResType texTy } else { - dynamic_cast(_progressBarRenderer)->initWithFile(fileName); + dynamic_cast(_progressBarRenderer)->setTexture(fileName); } break; case UI_TEX_TYPE_PLIST: @@ -167,7 +167,7 @@ void UISlider::loadProgressBarTexture(const char *fileName, TextureResType texTy } else { - dynamic_cast(_progressBarRenderer)->initWithSpriteFrameName(fileName); + dynamic_cast(_progressBarRenderer)->setSpriteFrame(fileName); } break; default: @@ -281,10 +281,10 @@ void UISlider::loadSlidBallTextureNormal(const char* normal,TextureResType texTy switch (_ballNTexType) { case UI_TEX_TYPE_LOCAL: - _slidBallNormalRenderer->initWithFile(normal); + _slidBallNormalRenderer->setTexture(normal); break; case UI_TEX_TYPE_PLIST: - _slidBallNormalRenderer->initWithSpriteFrameName(normal); + _slidBallNormalRenderer->setSpriteFrame(normal); break; default: break; @@ -304,10 +304,10 @@ void UISlider::loadSlidBallTexturePressed(const char* pressed,TextureResType tex switch (_ballPTexType) { case UI_TEX_TYPE_LOCAL: - _slidBallPressedRenderer->initWithFile(pressed); + _slidBallPressedRenderer->setTexture(pressed); break; case UI_TEX_TYPE_PLIST: - _slidBallPressedRenderer->initWithSpriteFrameName(pressed); + _slidBallPressedRenderer->setSpriteFrame(pressed); break; default: break; @@ -327,10 +327,10 @@ void UISlider::loadSlidBallTextureDisabled(const char* disabled,TextureResType t switch (_ballDTexType) { case UI_TEX_TYPE_LOCAL: - _slidBallDisabledRenderer->initWithFile(disabled); + _slidBallDisabledRenderer->setTexture(disabled); break; case UI_TEX_TYPE_PLIST: - _slidBallDisabledRenderer->initWithSpriteFrameName(disabled); + _slidBallDisabledRenderer->setSpriteFrame(disabled); break; default: break; diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index 599bcb5f36..8ad857fd7c 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -245,48 +245,49 @@ bool Scale9Sprite::updateWithBatchNode(SpriteBatchNode* batchnode, const Rect& o centertopbounds = RectApplyAffineTransform(centertopbounds, t); // Centre - _centre = new Sprite(); - _centre->initWithTexture(_scale9Image->getTexture(), centerbounds); + _centre = Sprite::createWithTexture(_scale9Image->getTexture(), centerbounds); + _centre->retain(); _scale9Image->addChild(_centre, 0, pCentre); + // Top - _top = new Sprite(); - _top->initWithTexture(_scale9Image->getTexture(), centertopbounds); + _top = Sprite::createWithTexture(_scale9Image->getTexture(), centertopbounds); + _top->retain(); _scale9Image->addChild(_top, 1, pTop); // Bottom - _bottom = new Sprite(); - _bottom->initWithTexture(_scale9Image->getTexture(), centerbottombounds); + _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), centerbottombounds); + _bottom->retain(); _scale9Image->addChild(_bottom, 1, pBottom); // Left - _left = new Sprite(); - _left->initWithTexture(_scale9Image->getTexture(), leftcenterbounds); + _left = Sprite::createWithTexture(_scale9Image->getTexture(), leftcenterbounds); + _left->retain(); _scale9Image->addChild(_left, 1, pLeft); // Right - _right = new Sprite(); - _right->initWithTexture(_scale9Image->getTexture(), rightcenterbounds); + _right = Sprite::createWithTexture(_scale9Image->getTexture(), rightcenterbounds); + _right->retain(); _scale9Image->addChild(_right, 1, pRight); // Top left - _topLeft = new Sprite(); - _topLeft->initWithTexture(_scale9Image->getTexture(), lefttopbounds); + _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), lefttopbounds); + _topLeft->retain(); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right - _topRight = new Sprite(); - _topRight->initWithTexture(_scale9Image->getTexture(), righttopbounds); + _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), righttopbounds); + _topRight->retain(); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left - _bottomLeft = new Sprite(); - _bottomLeft->initWithTexture(_scale9Image->getTexture(), leftbottombounds); + _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), leftbottombounds); + _bottomLeft->retain(); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right - _bottomRight = new Sprite(); - _bottomRight->initWithTexture(_scale9Image->getTexture(), rightbottombounds); + _bottomRight = Sprite::createWithTexture(_scale9Image->getTexture(), rightbottombounds); + _bottomRight->retain(); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } else { // set up transformation of coordinates @@ -330,48 +331,48 @@ bool Scale9Sprite::updateWithBatchNode(SpriteBatchNode* batchnode, const Rect& o rotatedcentertopbounds.origin = centertopbounds.origin; // Centre - _centre = new Sprite(); - _centre->initWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); + _centre = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); + _centre->retain(); _scale9Image->addChild(_centre, 0, pCentre); // Top - _top = new Sprite(); - _top->initWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); + _top = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); + _top->retain(); _scale9Image->addChild(_top, 1, pTop); // Bottom - _bottom = new Sprite(); - _bottom->initWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); + _bottom = Sprite::Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); + _bottom->retain(); _scale9Image->addChild(_bottom, 1, pBottom); // Left - _left = new Sprite(); - _left->initWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); + _left = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); + _left->retain(); _scale9Image->addChild(_left, 1, pLeft); // Right - _right = new Sprite(); - _right->initWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); + _right = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); + _right->retain(); _scale9Image->addChild(_right, 1, pRight); // Top left - _topLeft = new Sprite(); - _topLeft->initWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); + _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); + _topLeft->retain(); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right - _topRight = new Sprite(); - _topRight->initWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); + _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); + _topRight->retain(); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left - _bottomLeft = new Sprite(); - _bottomLeft->initWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); + _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); + _bottomLeft->retain(); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right - _bottomRight = new Sprite(); - _bottomRight->initWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, true); + _bottomRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, true); + _bottomRight->retain(); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 703e8bf40b..66e8e6edb1 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -63,9 +63,6 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -77,18 +74,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index f67907ceba..9a601b5212 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -40,6 +40,8 @@ public: class ActionManual : public ActionsDemo { public: + CREATE_FUNC(ActionManual); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -47,6 +49,8 @@ public: class ActionMove : public ActionsDemo { public: + CREATE_FUNC(ActionMove); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -54,6 +58,8 @@ public: class ActionScale : public ActionsDemo { public: + CREATE_FUNC(ActionScale); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -61,6 +67,8 @@ public: class ActionSkew : public ActionsDemo { public: + CREATE_FUNC(ActionSkew); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -68,6 +76,8 @@ public: class ActionRotationalSkew : public ActionsDemo { public: + CREATE_FUNC(ActionRotationalSkew); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -75,6 +85,8 @@ public: class ActionRotationalSkewVSStandardSkew : public ActionsDemo { public: + CREATE_FUNC(ActionRotationalSkewVSStandardSkew); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -82,6 +94,8 @@ public: class ActionSkewRotateScale : public ActionsDemo { public: + CREATE_FUNC(ActionSkewRotateScale); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -89,6 +103,8 @@ public: class ActionRotate : public ActionsDemo { public: + CREATE_FUNC(ActionRotate); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -96,6 +112,8 @@ public: class ActionJump : public ActionsDemo { public: + CREATE_FUNC(ActionJump); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -103,6 +121,8 @@ public: class ActionBezier : public ActionsDemo { public: + CREATE_FUNC(ActionBezier); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -110,6 +130,8 @@ public: class ActionBlink : public ActionsDemo { public: + CREATE_FUNC(ActionBlink); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -117,6 +139,8 @@ public: class ActionFade : public ActionsDemo { public: + CREATE_FUNC(ActionFade); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -124,6 +148,8 @@ public: class ActionTint : public ActionsDemo { public: + CREATE_FUNC(ActionTint); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -131,6 +157,8 @@ public: class ActionAnimate : public ActionsDemo { public: + CREATE_FUNC(ActionAnimate); + virtual void onEnter(); virtual void onExit(); virtual std::string title(); @@ -140,6 +168,8 @@ public: class ActionSequence : public ActionsDemo { public: + CREATE_FUNC(ActionSequence); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -147,6 +177,8 @@ public: class ActionSequence2 : public ActionsDemo { public: + CREATE_FUNC(ActionSequence2); + virtual void onEnter(); virtual std::string subtitle(); @@ -158,6 +190,8 @@ public: class ActionSpawn : public ActionsDemo { public: + CREATE_FUNC(ActionSpawn); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -165,6 +199,8 @@ public: class ActionReverse : public ActionsDemo { public: + CREATE_FUNC(ActionReverse); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -172,6 +208,8 @@ public: class ActionRepeat : public ActionsDemo { public: + CREATE_FUNC(ActionRepeat); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -179,6 +217,8 @@ public: class ActionDelayTime : public ActionsDemo { public: + CREATE_FUNC(ActionDelayTime); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -186,6 +226,8 @@ public: class ActionReverseSequence : public ActionsDemo { public: + CREATE_FUNC(ActionReverseSequence); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -193,6 +235,8 @@ public: class ActionReverseSequence2 : public ActionsDemo { public: + CREATE_FUNC(ActionReverseSequence2); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -200,6 +244,8 @@ public: class ActionOrbit : public ActionsDemo { public: + CREATE_FUNC(ActionOrbit); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -207,6 +253,8 @@ public: class ActionRemoveSelf : public ActionsDemo { public: + CREATE_FUNC(ActionRemoveSelf); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -214,6 +262,8 @@ public: class ActionRepeatForever : public ActionsDemo { public: + CREATE_FUNC(ActionRepeatForever); + virtual void onEnter(); virtual std::string subtitle(); @@ -223,6 +273,8 @@ public: class ActionRotateToRepeat : public ActionsDemo { public: + CREATE_FUNC(ActionRotateToRepeat); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -230,6 +282,8 @@ public: class ActionRotateJerk : public ActionsDemo { public: + CREATE_FUNC(ActionRotateJerk); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -237,6 +291,8 @@ public: class ActionCallFuncN : public ActionsDemo { public: + CREATE_FUNC(ActionCallFuncN); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -246,6 +302,8 @@ public: class ActionCallFuncND : public ActionsDemo { public: + CREATE_FUNC(ActionCallFuncND); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -255,6 +313,8 @@ public: class ActionCallFuncO : public ActionsDemo { public: + CREATE_FUNC(ActionCallFuncO); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -264,6 +324,8 @@ public: class ActionCallFunction : public ActionsDemo { public: + CREATE_FUNC(ActionCallFunction); + virtual void onEnter(); virtual std::string subtitle(); @@ -276,6 +338,8 @@ public: class ActionFollow : public ActionsDemo { public: + CREATE_FUNC(ActionFollow); + virtual void onEnter(); virtual void draw(); virtual std::string subtitle(); @@ -284,6 +348,8 @@ public: class ActionTargeted : public ActionsDemo { public: + CREATE_FUNC(ActionTargeted); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -292,6 +358,8 @@ public: class ActionTargetedReverse : public ActionsDemo { public: + CREATE_FUNC(ActionTargetedReverse); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -300,6 +368,8 @@ public: class ActionStacked : public ActionsDemo { public: + CREATE_FUNC(ActionStacked); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -311,6 +381,8 @@ public: class ActionMoveStacked : public ActionStacked { public: + CREATE_FUNC(ActionMoveStacked); + virtual std::string title(); virtual void runActionsInSprite(Sprite* sprite); }; @@ -318,6 +390,8 @@ public: class ActionMoveJumpStacked : public ActionStacked { public: + CREATE_FUNC(ActionMoveJumpStacked); + virtual std::string title(); virtual void runActionsInSprite(Sprite* sprite); }; @@ -325,6 +399,8 @@ public: class ActionMoveBezierStacked : public ActionStacked { public: + CREATE_FUNC(ActionMoveBezierStacked); + virtual std::string title(); virtual void runActionsInSprite(Sprite* sprite); }; @@ -332,6 +408,8 @@ public: class ActionCatmullRomStacked : public ActionsDemo { public: + CREATE_FUNC(ActionCatmullRomStacked); + virtual ~ActionCatmullRomStacked(); virtual void draw(); virtual void onEnter(); @@ -345,6 +423,8 @@ private: class ActionCardinalSplineStacked : public ActionsDemo { public: + CREATE_FUNC(ActionCardinalSplineStacked); + virtual ~ActionCardinalSplineStacked(); virtual void draw(); virtual void onEnter(); @@ -357,6 +437,8 @@ private: class Issue1305 : public ActionsDemo { public: + CREATE_FUNC(Issue1305); + virtual void onEnter(); virtual void onExit(); void log(Node* sender); @@ -370,6 +452,8 @@ private: class Issue1305_2 : public ActionsDemo { public: + CREATE_FUNC(Issue1305_2); + virtual void onEnter(); void printLog1(); void printLog2(); @@ -382,6 +466,8 @@ public: class Issue1288 : public ActionsDemo { public: + CREATE_FUNC(Issue1288); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -390,6 +476,8 @@ public: class Issue1288_2 : public ActionsDemo { public: + CREATE_FUNC(Issue1288_2); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -398,6 +486,8 @@ public: class Issue1327 : public ActionsDemo { public: + CREATE_FUNC(Issue1327); + virtual void onEnter(); virtual std::string subtitle(); virtual std::string title(); @@ -407,6 +497,8 @@ public: class Issue1398 : public ActionsDemo { public: + CREATE_FUNC(Issue1398); + void incrementInteger(); void incrementIntegerCallback(void* data); virtual void onEnter(); @@ -419,6 +511,8 @@ private: class ActionCatmullRom : public ActionsDemo { public: + CREATE_FUNC(ActionCatmullRom); + ~ActionCatmullRom(); virtual void onEnter(); @@ -433,6 +527,8 @@ private: class ActionCardinalSpline : public ActionsDemo { public: + CREATE_FUNC(ActionCardinalSpline); + ~ActionCardinalSpline(); virtual void onEnter(); @@ -446,6 +542,8 @@ private: class PauseResumeActions : public ActionsDemo { public: + CREATE_FUNC(PauseResumeActions); + PauseResumeActions(); virtual ~PauseResumeActions(); virtual void onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index f69ba49240..bec4eddd83 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -57,9 +57,6 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -71,18 +68,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h index 042e51ddf6..4cf5d1bb0d 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h @@ -7,6 +7,8 @@ class BaseClippingNodeTest : public BaseTest { public: + CREATE_FUNC(BaseClippingNodeTest); + ~BaseClippingNodeTest(); virtual bool init(); @@ -22,6 +24,8 @@ public: class BasicTest : public BaseClippingNodeTest { public: + CREATE_FUNC(BasicTest); + virtual std::string title(); virtual std::string subtitle(); virtual void setup(); @@ -40,6 +44,8 @@ public: class ShapeTest : public BasicTest { public: + CREATE_FUNC(ShapeTest); + virtual std::string title(); virtual std::string subtitle(); @@ -50,6 +56,8 @@ public: class ShapeInvertedTest : public ShapeTest { public: + CREATE_FUNC(ShapeInvertedTest); + virtual std::string title(); virtual std::string subtitle(); virtual ClippingNode* clipper(); @@ -58,6 +66,8 @@ public: class SpriteTest : public BasicTest { public: + CREATE_FUNC(SpriteTest); + virtual std::string title(); virtual std::string subtitle(); @@ -69,6 +79,8 @@ public: class SpriteNoAlphaTest : public SpriteTest { public: + CREATE_FUNC(SpriteNoAlphaTest); + virtual std::string title(); virtual std::string subtitle(); virtual ClippingNode* clipper(); @@ -77,6 +89,8 @@ public: class SpriteInvertedTest : public SpriteTest { public: + CREATE_FUNC(SpriteInvertedTest); + virtual std::string title(); virtual std::string subtitle(); virtual ClippingNode* clipper(); @@ -85,6 +99,8 @@ public: class NestedTest : public BaseClippingNodeTest { public: + CREATE_FUNC(NestedTest); + virtual std::string title(); virtual std::string subtitle(); virtual void setup(); @@ -93,6 +109,8 @@ public: class HoleDemo : public BaseClippingNodeTest { public: + CREATE_FUNC(HoleDemo); + ~HoleDemo(); virtual void setup(); virtual std::string title(); @@ -108,6 +126,8 @@ private: class ScrollViewDemo : public BaseClippingNodeTest { public: + CREATE_FUNC(ScrollViewDemo); + virtual std::string title(); virtual std::string subtitle(); virtual void setup(); @@ -124,6 +144,8 @@ private: class RawStencilBufferTest : public BaseClippingNodeTest { public: + CREATE_FUNC(RawStencilBufferTest); + ~RawStencilBufferTest(); virtual std::string title(); @@ -141,6 +163,8 @@ protected: class RawStencilBufferTest2 : public RawStencilBufferTest { public: + CREATE_FUNC(RawStencilBufferTest2); + virtual std::string subtitle(); virtual void setupStencilForClippingOnPlane(GLint plane); virtual void setupStencilForDrawingOnPlane(GLint plane); @@ -149,6 +173,8 @@ public: class RawStencilBufferTest3 : public RawStencilBufferTest { public: + CREATE_FUNC(RawStencilBufferTest3); + virtual std::string subtitle(); virtual void setupStencilForClippingOnPlane(GLint plane); virtual void setupStencilForDrawingOnPlane(GLint plane); @@ -157,6 +183,8 @@ public: class RawStencilBufferTest4 : public RawStencilBufferTest { public: + CREATE_FUNC(RawStencilBufferTest4); + virtual std::string subtitle(); virtual void setupStencilForClippingOnPlane(GLint plane); virtual void setupStencilForDrawingOnPlane(GLint plane); @@ -165,6 +193,8 @@ public: class RawStencilBufferTest5 : public RawStencilBufferTest { public: + CREATE_FUNC(RawStencilBufferTest5); + virtual std::string subtitle(); virtual void setupStencilForClippingOnPlane(GLint plane); virtual void setupStencilForDrawingOnPlane(GLint plane); @@ -173,6 +203,8 @@ public: class RawStencilBufferTest6 : public RawStencilBufferTest { public: + CREATE_FUNC(RawStencilBufferTest6); + virtual std::string subtitle(); virtual void setup(); virtual void setupStencilForClippingOnPlane(GLint plane); @@ -184,6 +216,8 @@ public: class ClippingNodeTestScene : public TestScene { public: + CREATE_FUNC(ClippingNodeTestScene); + virtual void runThisTest(); }; diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp index 9ff65566a1..fa9b5b7a4c 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp @@ -26,9 +26,6 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -40,18 +37,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restartAction() { - auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - + auto layer = (createFunctions[sceneIdx])(); return layer; } diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h index 807719cea0..1075d19773 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h @@ -35,6 +35,8 @@ public: class ConfigurationLoadConfig : public ConfigurationBase { public: + CREATE_FUNC(ConfigurationLoadConfig); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -42,6 +44,8 @@ public: class ConfigurationQuery : public ConfigurationBase { public: + CREATE_FUNC(ConfigurationQuery); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -49,6 +53,8 @@ public: class ConfigurationInvalid : public ConfigurationBase { public: + CREATE_FUNC(ConfigurationInvalid); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -56,6 +62,8 @@ public: class ConfigurationDefault : public ConfigurationBase { public: + CREATE_FUNC(ConfigurationDefault); + virtual void onEnter(); virtual std::string subtitle(); }; @@ -63,6 +71,8 @@ public: class ConfigurationSet : public ConfigurationBase { public: + CREATE_FUNC(ConfigurationSet); + virtual void onEnter(); virtual std::string subtitle(); }; diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp index ee0bfe043b..ac05ac2e03 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp @@ -58,9 +58,6 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -72,18 +69,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h index 232d05419a..190d82c0ad 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h @@ -50,6 +50,8 @@ public: class S9BatchNodeBasic : public S9SpriteTestDemo { public: + CREATE_FUNC(S9BatchNodeBasic); + virtual void onEnter(); virtual std::string title(); @@ -61,6 +63,8 @@ public: class S9FrameNameSpriteSheet : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheet); + virtual void onEnter(); virtual std::string title(); @@ -72,6 +76,8 @@ public: class S9FrameNameSpriteSheetRotated : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetRotated); + virtual void onEnter(); virtual std::string title(); @@ -83,6 +89,8 @@ public: class S9BatchNodeScaledNoInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9BatchNodeScaledNoInsets); + virtual void onEnter(); virtual std::string title(); @@ -94,6 +102,8 @@ public: class S9FrameNameSpriteSheetScaledNoInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetScaledNoInsets); + virtual void onEnter(); virtual std::string title(); @@ -105,6 +115,8 @@ public: class S9FrameNameSpriteSheetRotatedScaledNoInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetRotatedScaledNoInsets); + virtual void onEnter(); virtual std::string title(); @@ -117,6 +129,8 @@ public: class S9BatchNodeScaleWithCapInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9BatchNodeScaleWithCapInsets); + virtual void onEnter(); virtual std::string title(); @@ -128,6 +142,8 @@ public: class S9FrameNameSpriteSheetInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetInsets); + virtual void onEnter(); virtual std::string title(); @@ -139,6 +155,8 @@ public: class S9FrameNameSpriteSheetInsetsScaled : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetInsetsScaled); + virtual void onEnter(); virtual std::string title(); @@ -150,6 +168,8 @@ public: class S9FrameNameSpriteSheetRotatedInsets : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetRotatedInsets); + virtual void onEnter(); virtual std::string title(); @@ -161,6 +181,8 @@ public: class S9_TexturePacker : public S9SpriteTestDemo { public: + CREATE_FUNC(S9_TexturePacker); + virtual void onEnter(); virtual std::string title(); @@ -172,6 +194,8 @@ public: class S9FrameNameSpriteSheetRotatedInsetsScaled : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetRotatedInsetsScaled); + virtual void onEnter(); virtual std::string title(); @@ -183,6 +207,8 @@ public: class S9FrameNameSpriteSheetRotatedSetCapInsetLater : public S9SpriteTestDemo { public: + CREATE_FUNC(S9FrameNameSpriteSheetRotatedSetCapInsetLater); + virtual void onEnter(); virtual std::string title(); @@ -194,6 +220,8 @@ public: class S9CascadeOpacityAndColor : public S9SpriteTestDemo { public: + CREATE_FUNC(S9CascadeOpacityAndColor); + virtual void onEnter(); virtual std::string title(); diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp index 4211828903..66d15719ce 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -24,9 +24,6 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -38,18 +35,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h index d524d81a4b..93d1a98df2 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h @@ -27,6 +27,8 @@ public: class TestResolutionDirectories : public FileUtilsDemo { public: + CREATE_FUNC(TestResolutionDirectories); + virtual void onEnter(); virtual void onExit(); virtual string title(); @@ -39,6 +41,8 @@ private: class TestSearchPath : public FileUtilsDemo { public: + CREATE_FUNC(TestSearchPath); + virtual void onEnter(); virtual void onExit(); virtual string title(); @@ -51,6 +55,8 @@ private: class TestFilenameLookup : public FileUtilsDemo { public: + CREATE_FUNC(TestFilenameLookup); + virtual void onEnter(); virtual void onExit(); virtual string title(); @@ -60,6 +66,8 @@ public: class TestIsFileExist : public FileUtilsDemo { public: + CREATE_FUNC(TestIsFileExist); + virtual void onEnter(); virtual void onExit(); virtual string title(); @@ -69,6 +77,8 @@ public: class TextWritePlist : public FileUtilsDemo { public: + CREATE_FUNC(TextWritePlist); + virtual void onEnter(); virtual void onExit(); virtual string title(); diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index 1828dbb03d..a9ff786e4a 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -227,6 +227,9 @@ std::string TouchableSpriteTest::subtitle() class TouchableSpriteWithFixedPriority : public Sprite { public: + + CREATE_FUNC(TouchableSpriteWithFixedPriority); + TouchableSpriteWithFixedPriority() : _listener(nullptr) , _fixedPriority(0) @@ -297,23 +300,20 @@ void FixedPriorityTest::onEnter() Point origin = Director::getInstance()->getVisibleOrigin(); Size size = Director::getInstance()->getVisibleSize(); - auto sprite1 = new TouchableSpriteWithFixedPriority(); - sprite1->initWithFile("Images/CyanSquare.png"); - sprite1->autorelease(); + auto sprite1 = TouchableSpriteWithFixedPriority::create(); + sprite1->setTexture("Images/CyanSquare.png"); sprite1->setPriority(30); sprite1->setPosition(origin+Point(size.width/2, size.height/2) + Point(-80, 40)); addChild(sprite1, 10); - auto sprite2 = new TouchableSpriteWithFixedPriority(); - sprite2->initWithFile("Images/MagentaSquare.png"); - sprite2->autorelease(); + auto sprite2 = TouchableSpriteWithFixedPriority::create(); + sprite2->setTexture("Images/MagentaSquare.png"); sprite2->setPriority(20); sprite2->setPosition(origin+Point(size.width/2, size.height/2)); addChild(sprite2, 20); - auto sprite3 = new TouchableSpriteWithFixedPriority(); - sprite3->initWithFile("Images/YellowSquare.png"); - sprite3->autorelease(); + auto sprite3 = TouchableSpriteWithFixedPriority::create(); + sprite3->setTexture("Images/YellowSquare.png"); sprite3->setPriority(10); sprite3->setPosition(Point(0, 0)); sprite2->addChild(sprite3, 1); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.cpp index 55da98b32d..af0ec78e7d 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.cpp @@ -292,8 +292,7 @@ void NodeDeallocTest::update(float dt) Node **nodes = new Node*[quantityOfNodes]; for( int i=0; iinit(); + nodes[i] = Node::create(); } CC_PROFILER_START(this->profilerName()); @@ -445,8 +444,8 @@ void SpriteDeallocTest::update(float dt) Sprite **sprites = new Sprite*[quantityOfNodes]; for( int i=0; iinit(); + sprites[i] = Sprite::create(); + sprites[i]->retain(); } CC_PROFILER_START(this->profilerName()); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.h index fcfdba36ec..aa8e5d5fff 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceAllocTest.h @@ -49,6 +49,8 @@ protected: class NodeCreateTest : public PerformceAllocScene { public: + CREATE_FUNC(NodeCreateTest); + virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt); @@ -61,6 +63,8 @@ public: class NodeDeallocTest : public PerformceAllocScene { public: + CREATE_FUNC(NodeDeallocTest); + virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt); @@ -73,6 +77,8 @@ public: class SpriteCreateEmptyTest : public PerformceAllocScene { public: + CREATE_FUNC(SpriteCreateEmptyTest); + virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt); @@ -85,6 +91,8 @@ public: class SpriteCreateTest : public PerformceAllocScene { public: + CREATE_FUNC(SpriteCreateTest); + virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt); @@ -97,6 +105,8 @@ public: class SpriteDeallocTest : public PerformceAllocScene { public: + CREATE_FUNC(SpriteDeallocTest); + virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h index 95ce5914b5..a82e5aba89 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h @@ -7,6 +7,8 @@ class NodeChildrenMenuLayer : public PerformBasicLayer { public: + CREATE_FUNC(NodeChildrenMenuLayer); + NodeChildrenMenuLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); virtual void showCurrentTest(); void dumpProfilerInfo(float dt); @@ -19,6 +21,8 @@ public: class NodeChildrenMainScene : public Scene { public: + CREATE_FUNC(NodeChildrenMainScene); + virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual std::string title(); virtual std::string subtitle(); @@ -44,6 +48,8 @@ protected: class IterateSpriteSheet : public NodeChildrenMainScene { public: + CREATE_FUNC(IterateSpriteSheet); + ~IterateSpriteSheet(); virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); @@ -57,6 +63,8 @@ protected: class IterateSpriteSheetForLoop : public IterateSpriteSheet { public: + CREATE_FUNC(IterateSpriteSheetForLoop); + virtual void update(float dt); virtual std::string title(); @@ -67,6 +75,8 @@ public: class IterateSpriteSheetIterator : public IterateSpriteSheet { public: + CREATE_FUNC(IterateSpriteSheetIterator); + virtual void update(float dt); virtual std::string title(); @@ -77,6 +87,8 @@ public: class IterateSpriteSheetCArray : public IterateSpriteSheet { public: + CREATE_FUNC(IterateSpriteSheetCArray); + virtual void update(float dt); virtual std::string title(); @@ -87,6 +99,8 @@ public: class AddRemoveSpriteSheet : public NodeChildrenMainScene { public: + CREATE_FUNC(AddRemoveSpriteSheet); + ~AddRemoveSpriteSheet(); virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); @@ -106,6 +120,8 @@ protected: class CallFuncsSpriteSheetForEach : public IterateSpriteSheet { public: + CREATE_FUNC(CallFuncsSpriteSheetForEach); + virtual void update(float dt); virtual std::string title(); @@ -116,6 +132,8 @@ public: class CallFuncsSpriteSheetCMacro : public IterateSpriteSheet { public: + CREATE_FUNC(CallFuncsSpriteSheetCMacro); + virtual void update(float dt); virtual std::string title(); @@ -128,6 +146,8 @@ public: class AddSprite : public AddRemoveSpriteSheet { public: + CREATE_FUNC(AddSprite); + virtual void update(float dt); virtual std::string title(); @@ -138,6 +158,8 @@ public: class AddSpriteSheet : public AddRemoveSpriteSheet { public: + CREATE_FUNC(AddSpriteSheet); + virtual void update(float dt); virtual std::string title(); @@ -148,6 +170,8 @@ public: class GetSpriteSheet : public AddRemoveSpriteSheet { public: + CREATE_FUNC(GetSpriteSheet); + virtual void update(float dt); virtual std::string title(); @@ -158,6 +182,8 @@ public: class RemoveSprite : public AddRemoveSpriteSheet { public: + CREATE_FUNC(RemoveSprite); + virtual void update(float dt); virtual std::string title(); @@ -168,6 +194,8 @@ public: class RemoveSpriteSheet : public AddRemoveSpriteSheet { public: + CREATE_FUNC(RemoveSpriteSheet); + virtual void update(float dt); virtual std::string title(); @@ -178,6 +206,8 @@ public: class ReorderSpriteSheet : public AddRemoveSpriteSheet { public: + CREATE_FUNC(ReorderSpriteSheet); + virtual void update(float dt); virtual std::string title(); @@ -188,6 +218,8 @@ public: class SortAllChildrenSpriteSheet : public AddRemoveSpriteSheet { public: + CREATE_FUNC(SortAllChildrenSpriteSheet); + virtual void update(float dt); virtual std::string title(); @@ -198,6 +230,8 @@ public: class VisitSceneGraph : public NodeChildrenMainScene { public: + CREATE_FUNC(VisitSceneGraph); + void initWithQuantityOfNodes(unsigned int nodes) override; virtual void update(float dt) override; diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index 29f4b68e6d..3ec1e47986 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -26,9 +26,6 @@ namespace sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -40,18 +37,12 @@ namespace sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } static Layer* restart() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h index a3ccc76e57..1abf321b59 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h @@ -11,6 +11,8 @@ class PhysicsTestScene : public TestScene { public: + CREATE_FUNC(PhysicsTestScene); + virtual bool initTest() override; virtual void runThisTest(); @@ -22,10 +24,9 @@ private: class PhysicsDemo : public BaseTest { -protected: - PhysicsTestScene* _scene; - public: + CREATE_FUNC(PhysicsDemo); + PhysicsDemo(); virtual ~PhysicsDemo(); @@ -48,6 +49,7 @@ public: void onTouchEnded(Touch* touch, Event* event); protected: + PhysicsTestScene* _scene; Texture2D* _spriteTexture; // weak ref SpriteBatchNode* _ball; std::map _mouses; @@ -56,6 +58,8 @@ protected: class PhysicsDemoClickAdd : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoClickAdd); + virtual ~PhysicsDemoClickAdd(); void onEnter() override; std::string subtitle() override; @@ -67,6 +71,8 @@ public: class PhysicsDemoLogoSmash : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoLogoSmash); + void onEnter() override; std::string title() override; }; @@ -74,6 +80,8 @@ public: class PhysicsDemoPlink : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoPlink); + void onEnter() override; std::string title() override; }; @@ -81,8 +89,10 @@ public: class PhysicsDemoRayCast : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoRayCast); + PhysicsDemoRayCast(); -public: + void onEnter() override; std::string title() override; void update(float delta) override; @@ -101,6 +111,8 @@ private: class PhysicsDemoJoints : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoJoints); + void onEnter() override; std::string title() override; }; @@ -108,6 +120,8 @@ public: class PhysicsDemoActions : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoActions); + void onEnter() override; std::string title() override; }; @@ -115,6 +129,8 @@ public: class PhysicsDemoPump : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoPump); + void onEnter() override; void update(float delta) override; std::string title() override; @@ -132,6 +148,8 @@ private: class PhysicsDemoOneWayPlatform : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoOneWayPlatform); + void onEnter() override; std::string title() override; @@ -141,6 +159,8 @@ public: class PhysicsDemoSlice : public PhysicsDemo { public: + CREATE_FUNC(PhysicsDemoSlice); + void onEnter() override; std::string title() override; std::string subtitle() override; diff --git a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp index d225e1c8f8..0ede17cec3 100644 --- a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp @@ -55,9 +55,6 @@ Layer* nextSchedulerTest() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -69,18 +66,12 @@ Layer* backSchedulerTest() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } Layer* restartSchedulerTest() { auto layer = (createFunctions[sceneIdx])(); - layer->init(); - layer->autorelease(); - return layer; } @@ -1098,6 +1089,8 @@ std::string TwoSchedulers::subtitle() class TestNode2 : public Node { public: + CREATE_FUNC(TestNode2); + ~TestNode2() { cocos2d::log("Delete TestNode (should not crash)"); this->unscheduleAllSelectors(); @@ -1111,9 +1104,7 @@ void SchedulerIssue2268::onEnter() { SchedulerTestLayer::onEnter(); - testNode = new TestNode2(); - testNode->init(); - testNode->autorelease(); + testNode = TestNode2::create(); testNode->retain(); testNode->schedule(SEL_SCHEDULE(&TestNode::update)); this->addChild(testNode); diff --git a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h index 3e5ba3c9ac..226136cb9c 100644 --- a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h +++ b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.h @@ -35,6 +35,8 @@ public: class SchedulerAutoremove : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerAutoremove); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -48,6 +50,8 @@ private: class SchedulerPauseResume : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerPauseResume); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -60,6 +64,8 @@ public: class SchedulerPauseResumeAll : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerPauseResumeAll); + SchedulerPauseResumeAll(); virtual ~SchedulerPauseResumeAll(); virtual void onEnter(); @@ -79,6 +85,8 @@ private: class SchedulerPauseResumeAllUser : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerPauseResumeAllUser); + SchedulerPauseResumeAllUser(); virtual ~SchedulerPauseResumeAllUser(); virtual void onEnter(); @@ -97,6 +105,8 @@ private: class SchedulerUnscheduleAll : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUnscheduleAll); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -111,6 +121,8 @@ public: class SchedulerUnscheduleAllHard : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUnscheduleAllHard); + virtual void onEnter(); virtual void onExit(); virtual std::string title(); @@ -128,6 +140,8 @@ private: class SchedulerUnscheduleAllUserLevel : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUnscheduleAllUserLevel); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -142,6 +156,8 @@ public: class SchedulerSchedulesAndRemove : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerSchedulesAndRemove); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -156,6 +172,8 @@ public: class SchedulerUpdate : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUpdate); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -166,6 +184,8 @@ public: class SchedulerUpdateAndCustom : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUpdateAndCustom); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -178,6 +198,8 @@ public: class SchedulerUpdateFromCustom : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerUpdateFromCustom); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -190,6 +212,8 @@ public: class TestNode : public Node { public: + CREATE_FUNC(TestNode); + ~TestNode(); void initWithString(String* pStr, int priority); @@ -201,6 +225,8 @@ private: class RescheduleSelector : public SchedulerTestLayer { public: + CREATE_FUNC(RescheduleSelector); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -214,6 +240,8 @@ private: class SchedulerDelayAndRepeat : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerDelayAndRepeat); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -223,6 +251,8 @@ public: class SchedulerTimeScale : public SchedulerTestLayer { public: + CREATE_FUNC(SchedulerTimeScale); + void onEnter(); void onExit(); virtual std::string title(); @@ -236,6 +266,8 @@ public: class TwoSchedulers : public SchedulerTestLayer { public: + CREATE_FUNC(TwoSchedulers); + virtual ~TwoSchedulers(); virtual std::string title(); virtual std::string subtitle(); @@ -253,19 +285,24 @@ public: class SchedulerIssue2268 : public SchedulerTestLayer { - public: - ~SchedulerIssue2268(); - std::string title(); - std::string subtitle(); - void onEnter(); - void update(float dt); - private: - Node *testNode; +public: + CREATE_FUNC(SchedulerIssue2268); + + ~SchedulerIssue2268(); + std::string title(); + std::string subtitle(); + void onEnter(); + void update(float dt); + +private: + Node *testNode; }; class SchedulerTestScene : public TestScene { public: + CREATE_FUNC(SchedulerTestScene); + virtual void runThisTest(); }; diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index 38ca0d01a3..5448c31251 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -101,18 +101,11 @@ template class ShaderSpriteCreator { public: - static spriteType* createSprite(const char* pszFileName) + static spriteType* createSprite(const std::string& fileName) { - spriteType* pRet = new spriteType(); - if (pRet && pRet->initWithFile(pszFileName)) - { - pRet->autorelease(); - } - else - { - CC_SAFE_DELETE(pRet); - } - return pRet; + spriteType* ret = spriteType::create(); + ret->setTexture(fileName); + return ret; } }; @@ -236,6 +229,7 @@ void ShaderSprite::draw() class NormalSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(NormalSprite); NormalSprite(); protected: virtual void buildCustomUniforms(); @@ -260,6 +254,7 @@ void NormalSprite::setCustomUniforms() class GreyScaleSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(GreyScaleSprite); GreyScaleSprite(); protected: virtual void buildCustomUniforms(); @@ -284,6 +279,7 @@ void GreyScaleSprite::setCustomUniforms() class BlurSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(BlurSprite); BlurSprite(); void setBlurSize(float f); protected: @@ -331,6 +327,7 @@ void BlurSprite::setBlurSize(float f) class NoiseSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(NoiseSprite); NoiseSprite(); private: @@ -362,6 +359,7 @@ void NoiseSprite::setCustomUniforms() class EdgeDetectionSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(EdgeDetectionSprite); EdgeDetectionSprite(); private: @@ -393,6 +391,7 @@ void EdgeDetectionSprite::setCustomUniforms() class BloomSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(BloomSprite); BloomSprite(); private: @@ -424,6 +423,7 @@ void BloomSprite::setCustomUniforms() class CelShadingSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(CelShadingSprite); CelShadingSprite(); private: @@ -455,6 +455,7 @@ void CelShadingSprite::setCustomUniforms() class LensFlareSprite : public ShaderSprite, public ShaderSpriteCreator { public: + CREATE_FUNC(LensFlareSprite); LensFlareSprite(); private: diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index cade29ab94..6a7ee63d7d 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -c37b913119295ed7f6bcbb7e04cce322722ea1a5 \ No newline at end of file +386b62dbb6c45199cb3d4e6a4f8528fa530e283c \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index 4f7614f701..80939911a5 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -40,17 +40,14 @@ void TestScene::onEnter() outside the scope. So I choose the (2) solution. Commented by James Chen. */ -// auto scene = Scene::create(); - auto scene = new Scene(); - if (scene && scene->init()) - { - auto layer = new TestController(); - scene->addChild(layer); - layer->release(); - Director::getInstance()->replaceScene(scene); - scene->release(); - } - + auto scene = Scene::create(); + + auto layer = new TestController(); + scene->addChild(layer); + layer->release(); + + Director::getInstance()->replaceScene(scene); + cocostudio::ArmatureDataManager::destoryInstance(); }); diff --git a/samples/Cpp/TestCpp/Classes/testBasic.h b/samples/Cpp/TestCpp/Classes/testBasic.h index 771fd1a5a5..68caa0d839 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.h +++ b/samples/Cpp/TestCpp/Classes/testBasic.h @@ -27,6 +27,6 @@ static Layer* create##className() \ // C++ 11 -#define CL(__className__) [](){ return new __className__();} +#define CL(__className__) [](){ return __className__::create();} #endif From 2ce2eaf4b32038a87a73c66642d893f091bd59d6 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 13 Nov 2013 17:36:33 -0800 Subject: [PATCH 02/28] More tests converted --- .../ClippingNodeTest/ClippingNodeTest.cpp | 9 +-- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 6 -- .../Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 67 +++++++++++++++- .../Classes/LabelTest/LabelTestNew.cpp | 6 -- .../TestCpp/Classes/LabelTest/LabelTestNew.h | 47 ++++++++++- .../TestCpp/Classes/LayerTest/LayerTest.cpp | 39 ++++----- .../Cpp/TestCpp/Classes/LayerTest/LayerTest.h | 18 +++++ .../MotionStreakTest/MotionStreakTest.cpp | 6 -- .../MotionStreakTest/MotionStreakTest.h | 4 + .../NewEventDispatcherTest.cpp | 8 +- .../NewEventDispatcherTest.h | 8 ++ .../PerformanceNodeChildrenTest.h | 9 +-- .../RenderTextureTest/RenderTextureTest.cpp | 6 -- .../RenderTextureTest/RenderTextureTest.h | 16 ++-- .../Classes/ShaderTest/ShaderTest2.cpp | 54 +++++-------- .../TestCpp/Classes/ShaderTest/ShaderTest2.h | 15 +++- .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- .../TestCpp/Classes/SpriteTest/SpriteTest.h | 79 +++++++++++++++++++ 18 files changed, 287 insertions(+), 112 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index bec4eddd83..84bbf9eb15 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -113,26 +113,23 @@ std::string BaseClippingNodeTest::subtitle() void BaseClippingNodeTest::restartCallback(Object* sender) { - Scene *s = new ClippingNodeTestScene(); + Scene *s = ClippingNodeTestScene::create(); s->addChild(restartAction()); Director::getInstance()->replaceScene(s); - s->release(); } void BaseClippingNodeTest::nextCallback(Object* sender) { - Scene *s = new ClippingNodeTestScene(); + Scene *s = ClippingNodeTestScene::create(); s->addChild(nextAction()); Director::getInstance()->replaceScene(s); - s->release(); } void BaseClippingNodeTest::backCallback(Object* sender) { - Scene *s = new ClippingNodeTestScene(); + Scene *s = ClippingNodeTestScene::create(); s->addChild(backAction()); Director::getInstance()->replaceScene(s); - s->release(); } void BaseClippingNodeTest::setup() diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index ea9405eabe..ea1333b172 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -82,8 +82,6 @@ Layer* nextAtlasAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } @@ -95,16 +93,12 @@ Layer* backAtlasAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } Layer* restartAtlasAction() { auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index 87ff938c97..eafe528cf8 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -10,6 +10,8 @@ class AtlasDemo : public BaseTest protected: public: + CREATE_FUNC(AtlasDemo); + AtlasDemo(void); ~AtlasDemo(void); @@ -27,6 +29,8 @@ class Atlas1 : public AtlasDemo { TextureAtlas* _textureAtlas; public: + CREATE_FUNC(Atlas1); + Atlas1(); ~Atlas1(); virtual std::string title(); @@ -38,6 +42,8 @@ class LabelAtlasTest : public AtlasDemo { float _time; public: + CREATE_FUNC(LabelAtlasTest); + LabelAtlasTest(); virtual void step(float dt); @@ -50,6 +56,8 @@ class LabelAtlasColorTest : public AtlasDemo { float _time; public: + CREATE_FUNC(LabelAtlasColorTest); + LabelAtlasColorTest(); virtual void step(float dt); virtual std::string title(); @@ -60,6 +68,8 @@ public: class LabelTTFAlignment : public AtlasDemo { public: + CREATE_FUNC(LabelTTFAlignment); + LabelTTFAlignment(); virtual std::string title(); virtual std::string subtitle(); @@ -70,6 +80,8 @@ class Atlas3 : public AtlasDemo { float _time; public: + CREATE_FUNC(Atlas3); + Atlas3(); virtual void step(float dt); @@ -82,6 +94,8 @@ class Atlas4 : public AtlasDemo { float _time; public: + CREATE_FUNC(Atlas4); + Atlas4(); virtual void step(float dt); virtual void draw(); @@ -93,6 +107,8 @@ public: class Atlas5 : public AtlasDemo { public: + CREATE_FUNC(Atlas5); + Atlas5(); virtual std::string title(); virtual std::string subtitle(); @@ -102,6 +118,8 @@ public: class Atlas6 : public AtlasDemo { public: + CREATE_FUNC(Atlas6); + Atlas6(); virtual std::string title(); virtual std::string subtitle(); @@ -110,6 +128,8 @@ public: class AtlasBitmapColor : public AtlasDemo { public: + CREATE_FUNC(AtlasBitmapColor); + AtlasBitmapColor(); virtual std::string title(); @@ -119,6 +139,8 @@ public: class AtlasFastBitmap : public AtlasDemo { public: + CREATE_FUNC(AtlasFastBitmap); + AtlasFastBitmap(); virtual std::string title(); virtual std::string subtitle(); @@ -127,6 +149,8 @@ public: class BitmapFontMultiLine : public AtlasDemo { public: + CREATE_FUNC(BitmapFontMultiLine); + BitmapFontMultiLine(); virtual std::string title(); virtual std::string subtitle(); @@ -135,6 +159,8 @@ public: class LabelsEmpty : public AtlasDemo { public: + CREATE_FUNC(LabelsEmpty); + LabelsEmpty(); void updateStrings(float dt); virtual std::string title(); @@ -147,6 +173,8 @@ private: class LabelBMFontHD : public AtlasDemo { public: + CREATE_FUNC(LabelBMFontHD); + LabelBMFontHD(); virtual std::string title(); virtual std::string subtitle(); @@ -155,6 +183,8 @@ public: class LabelAtlasHD : public AtlasDemo { public: + CREATE_FUNC(LabelAtlasHD); + LabelAtlasHD(); virtual std::string title(); virtual std::string subtitle(); @@ -163,6 +193,8 @@ public: class LabelGlyphDesigner : public AtlasDemo { public: + CREATE_FUNC(LabelGlyphDesigner); + LabelGlyphDesigner(); virtual std::string title(); virtual std::string subtitle(); @@ -171,12 +203,16 @@ public: class AtlasTestScene : public TestScene { public: + CREATE_FUNC(AtlasTestScene); + virtual void runThisTest(); }; class LabelTTFTest : public AtlasDemo { public: + CREATE_FUNC(LabelTTFTest); + LabelTTFTest(); virtual ~LabelTTFTest(); virtual std::string title(); @@ -199,6 +235,8 @@ private: class LabelTTFMultiline : public AtlasDemo { public: + CREATE_FUNC(LabelTTFMultiline); + LabelTTFMultiline(); virtual std::string title(); virtual std::string subtitle(); @@ -207,6 +245,8 @@ public: class LabelTTFChinese : public AtlasDemo { public: + CREATE_FUNC(LabelTTFChinese); + LabelTTFChinese(); virtual std::string title(); }; @@ -214,6 +254,8 @@ public: class LabelBMFontChinese : public AtlasDemo { public: + CREATE_FUNC(LabelBMFontChinese); + LabelBMFontChinese(); virtual std::string title(); }; @@ -221,6 +263,8 @@ public: class BitmapFontMultiLineAlignment : public AtlasDemo { public: + CREATE_FUNC(BitmapFontMultiLineAlignment); + BitmapFontMultiLineAlignment(); ~BitmapFontMultiLineAlignment(); void snapArrowsToEdge(); @@ -243,6 +287,8 @@ public: class LabelTTFA8Test : public AtlasDemo { public: + CREATE_FUNC(LabelTTFA8Test); + LabelTTFA8Test(); virtual std::string title(); @@ -252,6 +298,8 @@ public: class BMFontOneAtlas : public AtlasDemo { public: + CREATE_FUNC(BMFontOneAtlas); + BMFontOneAtlas(); virtual std::string title(); @@ -261,6 +309,8 @@ public: class BMFontUnicode : public AtlasDemo { public: + CREATE_FUNC(BMFontUnicode); + BMFontUnicode(); virtual std::string title(); @@ -270,6 +320,8 @@ public: class BMFontInit : public AtlasDemo { public: + CREATE_FUNC(BMFontInit); + BMFontInit(); virtual std::string title(); @@ -279,6 +331,8 @@ public: class TTFFontInit : public AtlasDemo { public: + CREATE_FUNC(TTFFontInit); + TTFFontInit(); virtual std::string title(); @@ -288,6 +342,8 @@ public: class TTFFontShadowAndStroke : public AtlasDemo { public: + CREATE_FUNC(TTFFontShadowAndStroke); + TTFFontShadowAndStroke(); virtual std::string title(); @@ -298,6 +354,8 @@ public: class Issue1343 : public AtlasDemo { public: + CREATE_FUNC(Issue1343); + Issue1343(); virtual std::string title(); @@ -307,6 +365,8 @@ public: class LabelBMFontBounds : public AtlasDemo { public: + CREATE_FUNC(LabelBMFontBounds); + LabelBMFontBounds(); virtual void draw(); @@ -319,7 +379,8 @@ private: class NewLabelTTFUnicode : public AtlasDemo { public: - + CREATE_FUNC(NewLabelTTFUnicode); + NewLabelTTFUnicode(); virtual std::string title(); @@ -329,6 +390,7 @@ public: class NewLabelBMFontTest : public AtlasDemo { public: + CREATE_FUNC(NewLabelBMFontTest); NewLabelBMFontTest(); @@ -341,6 +403,7 @@ private: class NewLabelFontDefTest : public AtlasDemo { public: + CREATE_FUNC(NewLabelFontDefTest); NewLabelFontDefTest(); @@ -353,6 +416,8 @@ private: class LabelBMFontCrashTest : public AtlasDemo { public: + CREATE_FUNC(LabelBMFontCrashTest); + virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index e329dafcbe..b6540c8ab8 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -74,8 +74,6 @@ Layer* nextAtlasActionNew() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } @@ -87,16 +85,12 @@ Layer* backAtlasActionNew() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } Layer* restartAtlasActionNew() { auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index d494858ffa..03e94cc682 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -10,6 +10,8 @@ class AtlasDemoNew : public BaseTest protected: public: + CREATE_FUNC(AtlasDemoNew); + AtlasDemoNew(void); ~AtlasDemoNew(void); @@ -25,6 +27,8 @@ public: class LabelTTFAlignmentNew : public AtlasDemoNew { public: + CREATE_FUNC(LabelTTFAlignmentNew); + LabelTTFAlignmentNew(); virtual std::string title(); virtual std::string subtitle(); @@ -34,6 +38,8 @@ class LabelFNTColorAndOpacity : public AtlasDemoNew { float _time; public: + CREATE_FUNC(LabelFNTColorAndOpacity); + LabelFNTColorAndOpacity(); virtual void step(float dt); @@ -46,6 +52,8 @@ class LabelFNTSpriteActions : public AtlasDemoNew { float _time; public: + CREATE_FUNC(LabelFNTSpriteActions); + LabelFNTSpriteActions(); virtual void step(float dt); virtual void draw(); @@ -57,6 +65,8 @@ public: class LabelFNTPadding : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTPadding); + LabelFNTPadding(); virtual std::string title(); virtual std::string subtitle(); @@ -66,6 +76,8 @@ public: class LabelFNTOffset : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTOffset); + LabelFNTOffset(); virtual std::string title(); virtual std::string subtitle(); @@ -74,6 +86,8 @@ public: class LabelFNTColor : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTColor); + LabelFNTColor(); virtual std::string title(); @@ -83,6 +97,8 @@ public: class LabelFNTHundredLabels : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTHundredLabels); + LabelFNTHundredLabels(); virtual std::string title(); virtual std::string subtitle(); @@ -91,6 +107,8 @@ public: class LabelFNTMultiLine : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTMultiLine); + LabelFNTMultiLine(); virtual std::string title(); virtual std::string subtitle(); @@ -99,6 +117,8 @@ public: class LabelFNTandTTFEmpty : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTandTTFEmpty); + LabelFNTandTTFEmpty(); void updateStrings(float dt); virtual std::string title(); @@ -111,6 +131,8 @@ private: class LabelFNTRetina : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTRetina); + LabelFNTRetina(); virtual std::string title(); virtual std::string subtitle(); @@ -119,6 +141,8 @@ public: class LabelFNTGlyphDesigner : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTGlyphDesigner); + LabelFNTGlyphDesigner(); virtual std::string title(); virtual std::string subtitle(); @@ -127,12 +151,16 @@ public: class AtlasTestSceneNew : public TestScene { public: + CREATE_FUNC(AtlasTestSceneNew); + virtual void runThisTest(); }; class LabelTTFUnicodeChinese : public AtlasDemoNew { public: + CREATE_FUNC(LabelTTFUnicodeChinese); + LabelTTFUnicodeChinese(); virtual std::string title(); virtual std::string subtitle(); @@ -141,6 +169,8 @@ public: class LabelFNTUnicodeChinese : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTUnicodeChinese); + LabelFNTUnicodeChinese(); virtual std::string title(); virtual std::string subtitle(); @@ -149,6 +179,8 @@ public: class LabelFNTMultiLineAlignment : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTMultiLineAlignment); + LabelFNTMultiLineAlignment(); ~LabelFNTMultiLineAlignment(); void snapArrowsToEdge(); @@ -171,6 +203,8 @@ public: class LabelFNTUNICODELanguages : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTUNICODELanguages); + LabelFNTUNICODELanguages(); virtual std::string title(); @@ -180,6 +214,8 @@ public: class LabelFNTBounds : public AtlasDemoNew { public: + CREATE_FUNC(LabelFNTBounds); + LabelFNTBounds(); virtual void draw(); @@ -192,6 +228,7 @@ private: class LabelTTFLongLineWrapping : public AtlasDemoNew { public: + CREATE_FUNC(LabelTTFLongLineWrapping); LabelTTFLongLineWrapping(); @@ -202,6 +239,7 @@ public: class LabelTTFColor : public AtlasDemoNew { public: + CREATE_FUNC(LabelTTFColor); LabelTTFColor(); @@ -212,7 +250,8 @@ public: class LabelTTFUnicodeNew : public AtlasDemoNew { public: - + CREATE_FUNC(LabelTTFUnicodeNew); + LabelTTFUnicodeNew(); virtual std::string title(); @@ -222,7 +261,8 @@ public: class LabelTTFDynamicAlignment : public AtlasDemoNew { public: - + CREATE_FUNC(LabelTTFDynamicAlignment); + LabelTTFDynamicAlignment(); virtual std::string title(); virtual std::string subtitle(); @@ -243,6 +283,7 @@ private: class LabelTTFFontsTestNew : public AtlasDemoNew { public: + CREATE_FUNC(LabelTTFFontsTestNew); LabelTTFFontsTestNew(); @@ -254,6 +295,7 @@ public: class LabelBMFontTestNew : public AtlasDemoNew { public: + CREATE_FUNC(LabelBMFontTestNew); LabelBMFontTestNew(); @@ -266,6 +308,7 @@ private: class LabelFontDefTestNew : public AtlasDemoNew { public: + CREATE_FUNC(LabelFontDefTestNew); LabelFontDefTestNew(); diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp index 581928a4f3..0d10234a62 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp @@ -33,9 +33,7 @@ static Layer* nextAction() sceneIdx++; sceneIdx = sceneIdx % MAX_LAYER; - auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - + auto layer = (createFunctions[sceneIdx])(); return layer; } @@ -47,16 +45,12 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } @@ -156,23 +150,22 @@ void LayerTestCascadingOpacityA::onEnter() label->setPosition( Point( s.width/2, s.height/2)); layer1->runAction( - RepeatForever::create( - Sequence::create( - FadeTo::create(4, 0), - FadeTo::create(4, 255), - DelayTime::create(1), - NULL))); - + RepeatForever::create( + Sequence::create( + FadeTo::create(4, 0), + FadeTo::create(4, 255), + DelayTime::create(1), + NULL))); + sister1->runAction( - RepeatForever::create( - Sequence::create( - FadeTo::create(2, 0), - FadeTo::create(2, 255), - FadeTo::create(2, 0), - FadeTo::create(2, 255), - DelayTime::create(1), - NULL))); - + RepeatForever::create( + Sequence::create( + FadeTo::create(2, 0), + FadeTo::create(2, 255), + FadeTo::create(2, 0), + FadeTo::create(2, 255), + DelayTime::create(1), + NULL))); // Enable cascading in scene setEnableRecursiveCascading(this, true); diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h index dd381b001f..f54173cea5 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h @@ -26,6 +26,7 @@ public: class LayerTestCascadingOpacityA : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingOpacityA); virtual void onEnter(); virtual std::string title(); }; @@ -33,6 +34,7 @@ public: class LayerTestCascadingOpacityB : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingOpacityB); virtual void onEnter(); virtual std::string title(); }; @@ -40,6 +42,7 @@ public: class LayerTestCascadingOpacityC : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingOpacityC); virtual void onEnter(); virtual std::string title(); }; @@ -47,6 +50,7 @@ public: class LayerTestCascadingColorA : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingColorA); virtual void onEnter(); virtual std::string title(); }; @@ -54,6 +58,7 @@ public: class LayerTestCascadingColorB : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingColorB); virtual void onEnter(); virtual std::string title(); }; @@ -61,6 +66,7 @@ public: class LayerTestCascadingColorC : public LayerTest { public: + CREATE_FUNC(LayerTestCascadingColorC); virtual void onEnter(); virtual std::string title(); }; @@ -69,6 +75,8 @@ public: class LayerTest1 : public LayerTest { public: + CREATE_FUNC(LayerTest1); + virtual void onEnter(); virtual std::string title(); @@ -82,6 +90,7 @@ public: class LayerTest2 : public LayerTest { public: + CREATE_FUNC(LayerTest2); virtual void onEnter(); virtual std::string title(); }; @@ -90,6 +99,8 @@ public: class LayerTestBlend : public LayerTest { public: + CREATE_FUNC(LayerTestBlend); + LayerTestBlend(); void newBlend(float dt); virtual std::string title(); @@ -98,6 +109,7 @@ public: class LayerGradientTest : public LayerTest { public: + CREATE_FUNC(LayerGradientTest); LayerGradientTest(); void onTouchesMoved(const std::vector& touches, Event *event); virtual std::string title(); @@ -108,6 +120,7 @@ public: class LayerGradientTest2 : public LayerTest { public: + CREATE_FUNC(LayerGradientTest2); LayerGradientTest2(); virtual std::string title(); virtual std::string subtitle(); @@ -116,6 +129,7 @@ public: class LayerGradientTest3 : public LayerTest { public: + CREATE_FUNC(LayerGradientTest3); LayerGradientTest3(); virtual std::string title(); virtual std::string subtitle(); @@ -124,6 +138,7 @@ public: class LayerIgnoreAnchorPointPos : public LayerTest { public: + CREATE_FUNC(LayerIgnoreAnchorPointPos); virtual void onEnter(); void onToggle(Object* pObject); virtual std::string title(); @@ -133,6 +148,7 @@ public: class LayerIgnoreAnchorPointRot : public LayerTest { public: + CREATE_FUNC(LayerIgnoreAnchorPointRot); virtual void onEnter(); void onToggle(Object* pObject); virtual std::string title(); @@ -142,6 +158,7 @@ public: class LayerIgnoreAnchorPointScale : public LayerTest { public: + CREATE_FUNC(LayerIgnoreAnchorPointScale); virtual void onEnter(); void onToggle(Object* pObject); virtual std::string title(); @@ -151,6 +168,7 @@ public: class LayerExtendedBlendOpacityTest : public LayerTest { public: + CREATE_FUNC(LayerExtendedBlendOpacityTest); LayerExtendedBlendOpacityTest(); virtual std::string title(); virtual std::string subtitle(); diff --git a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp index 9d9057c3e7..cdff3e3382 100644 --- a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp +++ b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp @@ -28,8 +28,6 @@ Layer* nextMotionAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } @@ -41,16 +39,12 @@ Layer* backMotionAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } Layer* restartMotionAction() { auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } //------------------------------------------------------------------ diff --git a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h index a45eccfc01..5030ec9f3d 100644 --- a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h +++ b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h @@ -32,6 +32,7 @@ protected: Node* _target; public: + CREATE_FUNC(MotionStreakTest1); virtual void onEnter(); void onUpdate(float delta); virtual std::string title(); @@ -44,6 +45,7 @@ protected: Node* _target; public: + CREATE_FUNC(MotionStreakTest2); virtual void onEnter(); void onTouchesMoved(const std::vector& touches, Event* event); virtual std::string title(); @@ -52,6 +54,8 @@ public: class Issue1358 : public MotionStreakTest { public: + CREATE_FUNC(Issue1358); + virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index a9ff786e4a..4b4904a847 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -28,13 +28,7 @@ unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[ int sceneIdx=-1; Layer* createTest(int index) { - auto layer = (createFunctions[index])();; - - if (layer) - { - layer->autorelease(); - } - + auto layer = (createFunctions[index])();; return layer; } diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h index 529813e7b8..c326e9446a 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h @@ -34,6 +34,7 @@ public: class TouchableSpriteTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(TouchableSpriteTest); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -42,6 +43,7 @@ public: class FixedPriorityTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(FixedPriorityTest); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -50,6 +52,7 @@ public: class RemoveListenerWhenDispatching : public EventDispatcherTestDemo { public: + CREATE_FUNC(RemoveListenerWhenDispatching); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -58,6 +61,7 @@ public: class CustomEventTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(CustomEventTest); virtual void onEnter() override; virtual void onExit() override; virtual std::string title() override; @@ -70,6 +74,7 @@ private: class LabelKeyboardEventTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(LabelKeyboardEventTest); virtual void onEnter() override; virtual std::string title() override; virtual std::string subtitle() override; @@ -78,6 +83,7 @@ public: class SpriteAccelerationEventTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(SpriteAccelerationEventTest); virtual void onEnter() override; virtual void onExit() override; virtual std::string title() override; @@ -87,6 +93,7 @@ public: class RemoveAndRetainNodeTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(RemoveAndRetainNodeTest); virtual void onEnter() override; virtual void onExit() override; virtual std::string title() override; @@ -99,6 +106,7 @@ private: class RemoveListenerAfterAddingTest : public EventDispatcherTestDemo { public: + CREATE_FUNC(RemoveListenerAfterAddingTest); virtual void onEnter() override; virtual void onExit() override; virtual std::string title() override; diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h index a82e5aba89..a38796635d 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h @@ -9,6 +9,7 @@ class NodeChildrenMenuLayer : public PerformBasicLayer public: CREATE_FUNC(NodeChildrenMenuLayer); + NodeChildrenMenuLayer(); NodeChildrenMenuLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); virtual void showCurrentTest(); void dumpProfilerInfo(float dt); @@ -21,8 +22,6 @@ public: class NodeChildrenMainScene : public Scene { public: - CREATE_FUNC(NodeChildrenMainScene); - virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual std::string title(); virtual std::string subtitle(); @@ -48,8 +47,6 @@ protected: class IterateSpriteSheet : public NodeChildrenMainScene { public: - CREATE_FUNC(IterateSpriteSheet); - ~IterateSpriteSheet(); virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); @@ -65,6 +62,7 @@ class IterateSpriteSheetForLoop : public IterateSpriteSheet public: CREATE_FUNC(IterateSpriteSheetForLoop); + IterateSpriteSheetForLoop() {} virtual void update(float dt); virtual std::string title(); @@ -77,6 +75,7 @@ class IterateSpriteSheetIterator : public IterateSpriteSheet public: CREATE_FUNC(IterateSpriteSheetIterator); + IterateSpriteSheetIterator() {} virtual void update(float dt); virtual std::string title(); @@ -99,8 +98,6 @@ public: class AddRemoveSpriteSheet : public NodeChildrenMainScene { public: - CREATE_FUNC(AddRemoveSpriteSheet); - ~AddRemoveSpriteSheet(); virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index 987d8b8f05..d305c0382b 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -24,8 +24,6 @@ static Layer* nextTestCase() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } @@ -37,16 +35,12 @@ static Layer* backTestCase() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } static Layer* restartTestCase() { auto layer = (createFunctions[sceneIdx])(); - layer->autorelease(); - return layer; } diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index afd985ec70..cedf516f3f 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -20,6 +20,7 @@ public: class RenderTextureSave : public RenderTextureTest { public: + CREATE_FUNC(RenderTextureSave); RenderTextureSave(); ~RenderTextureSave(); virtual std::string title(); @@ -36,6 +37,7 @@ private: class RenderTextureIssue937 : public RenderTextureTest { public: + CREATE_FUNC(RenderTextureIssue937); RenderTextureIssue937(); virtual std::string title(); virtual std::string subtitle(); @@ -50,6 +52,7 @@ public: class RenderTextureZbuffer : public RenderTextureTest { public: + CREATE_FUNC(RenderTextureZbuffer); RenderTextureZbuffer(); void onTouchesMoved(const std::vector& touches, Event* event); @@ -77,6 +80,7 @@ private: class RenderTextureTestDepthStencil : public RenderTextureTest { public: + CREATE_FUNC(RenderTextureTestDepthStencil); RenderTextureTestDepthStencil(); virtual std::string title(); virtual std::string subtitle(); @@ -88,6 +92,7 @@ private: cocos2d::Sprite *sprite1, *sprite2; cocos2d::RenderTexture *renderTexture; public: + CREATE_FUNC(RenderTextureTargetNode); RenderTextureTargetNode(); virtual void update(float t); @@ -101,19 +106,20 @@ class SpriteRenderTextureBug : public RenderTextureTest { public: -class SimpleSprite : public Sprite -{ + class SimpleSprite : public Sprite + { public: + static SimpleSprite* create(const char* filename, const Rect &rect); SimpleSprite(); virtual void draw(); - static SimpleSprite* create(const char* filename, const Rect &rect); - + public: RenderTexture *rt; -}; + }; public: + CREATE_FUNC(SpriteRenderTextureBug); SpriteRenderTextureBug(); void onTouchesEnded(const std::vector& touches, Event* event); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index 5448c31251..de753d2b18 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -23,12 +23,6 @@ namespace ShaderTest2 Layer* createTest(int index) { auto layer = (createFunctions[index])();; - - if (layer) - { - layer->autorelease(); - } - return layer; } @@ -67,27 +61,23 @@ ShaderTestDemo2::ShaderTestDemo2() void ShaderTestDemo2::backCallback(Object* sender) { - auto s = new ShaderTestScene2(); + auto s = ShaderTestScene2::create(); s->addChild( ShaderTest2::backAction() ); Director::getInstance()->replaceScene(s); - s->release(); } void ShaderTestDemo2::nextCallback(Object* sender) { - auto s = new ShaderTestScene2();//CCScene::create(); + auto s = ShaderTestScene2::create(); s->addChild( ShaderTest2::nextAction() ); Director::getInstance()->replaceScene(s); - s->release(); } void ShaderTestDemo2::restartCallback(Object* sender) { - auto s = new ShaderTestScene2(); - s->addChild(ShaderTest2::restartAction()); - + auto s = ShaderTestScene2::create(); + s->addChild(ShaderTest2::restartAction()); Director::getInstance()->replaceScene(s); - s->release(); } void ShaderTestScene2::runThisTest() @@ -101,10 +91,12 @@ template class ShaderSpriteCreator { public: - static spriteType* createSprite(const std::string& fileName) + static spriteType* createSprite(const std::string& filename) { spriteType* ret = spriteType::create(); - ret->setTexture(fileName); + ret->setTexture(filename); + ret->initShader(); + ret->setBackgroundNotification(); return ret; } }; @@ -115,9 +107,10 @@ public: ShaderSprite(); ~ShaderSprite(); - bool initWithTexture(Texture2D* texture, const Rect& rect); + virtual void initShader(); + void setBackgroundNotification(); + void draw(); - void initProgram(); void listenBackToForeground(Object *obj); protected: @@ -140,30 +133,21 @@ ShaderSprite::~ShaderSprite() void ShaderSprite::listenBackToForeground(Object *obj) { setShaderProgram(NULL); - initProgram(); + initShader(); } -bool ShaderSprite::initWithTexture(Texture2D* texture, const Rect& rect) +void ShaderSprite::setBackgroundNotification() { - if( Sprite::initWithTexture(texture, rect) ) - { - NotificationCenter::getInstance()->addObserver(this, - callfuncO_selector(ShaderSprite::listenBackToForeground), - EVNET_COME_TO_FOREGROUND, - NULL); - - this->initProgram(); - - return true; - } - - return false; + NotificationCenter::getInstance()->addObserver(this, + callfuncO_selector(ShaderSprite::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); } -void ShaderSprite::initProgram() +void ShaderSprite::initShader() { GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( - FileUtils::getInstance()->fullPathForFilename(_fragSourceFile.c_str()).c_str())->getCString(); + FileUtils::getInstance()->fullPathForFilename(_fragSourceFile).c_str())->getCString(); auto pProgram = new GLProgram(); pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); setShaderProgram(pProgram); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h index 95ddbc592d..7266b552e7 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -14,19 +14,19 @@ public: void restartCallback(Object* sender); void nextCallback(Object* sender); void backCallback(Object* sender); - - CREATE_FUNC(ShaderTestDemo2); }; class ShaderTestScene2 : public TestScene { public: + CREATE_FUNC(ShaderTestScene2); virtual void runThisTest(); }; class NormalSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(NormalSpriteTest); NormalSpriteTest(); virtual std::string subtitle() {return "NormalSpriteTest";} @@ -35,6 +35,7 @@ public: class GreyScaleSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(GreyScaleSpriteTest); GreyScaleSpriteTest(); virtual std::string subtitle() {return "GreyScaleSpriteTest";} @@ -43,6 +44,7 @@ public: class BlurSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(BlurSpriteTest); BlurSpriteTest(); virtual std::string subtitle() {return "BlurSpriteTest";} @@ -51,6 +53,7 @@ public: class NoiseSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(NoiseSpriteTest); NoiseSpriteTest(); virtual std::string subtitle() {return "NoiseSpriteTest";} }; @@ -58,6 +61,8 @@ public: class EdgeDetectionSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(EdgeDetectionSpriteTest); + EdgeDetectionSpriteTest(); virtual std::string subtitle() {return "EdgeDetectionSpriteTest";} }; @@ -65,6 +70,8 @@ public: class BloomSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(BloomSpriteTest); + BloomSpriteTest(); virtual std::string subtitle() {return "BloomSpriteTest";} }; @@ -72,6 +79,8 @@ public: class LensFlareSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(LensFlareSpriteTest); + LensFlareSpriteTest(); virtual std::string subtitle() {return "LensFlareSpriteTest";} }; @@ -79,6 +88,8 @@ public: class CelShadingSpriteTest : public ShaderTestDemo2 { public: + CREATE_FUNC(CelShadingSpriteTest); + CelShadingSpriteTest(); virtual std::string subtitle() {return "CelShadingSpriteTest";} }; diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index 6a7ee63d7d..8786750620 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -386b62dbb6c45199cb3d4e6a4f8528fa530e283c \ No newline at end of file +406ff5d69f664d6e2b597c4f54a0db775087fb65 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h index ca08fb64e3..f09a9091f5 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h @@ -27,6 +27,7 @@ public: class Sprite1 : public SpriteTestDemo { public: + CREATE_FUNC(Sprite1); Sprite1(); virtual std::string title(); @@ -37,6 +38,7 @@ public: class SpriteBatchNode1: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNode1); SpriteBatchNode1(); void addNewSpriteWithCoords(Point p); void onTouchesEnded(const std::vector& touches, Event* event); @@ -46,6 +48,7 @@ public: class SpriteColorOpacity : public SpriteTestDemo { public: + CREATE_FUNC(SpriteColorOpacity); SpriteColorOpacity(); void removeAndAddSprite(float dt); virtual std::string title(); @@ -54,6 +57,8 @@ public: class SpriteBatchNodeColorOpacity : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeColorOpacity); + SpriteBatchNodeColorOpacity(); void removeAndAddSprite(float dt); virtual std::string title(); @@ -63,6 +68,8 @@ class SpriteZOrder : public SpriteTestDemo { int _dir; public: + CREATE_FUNC(SpriteZOrder); + SpriteZOrder(); void reorderSprite(float dt); virtual std::string title(); @@ -72,6 +79,8 @@ class SpriteBatchNodeZOrder: public SpriteTestDemo { int _dir; public: + CREATE_FUNC(SpriteBatchNodeZOrder); + SpriteBatchNodeZOrder(); void reorderSprite(float dt); virtual std::string title(); @@ -80,6 +89,8 @@ public: class SpriteBatchNodeReorder : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorder); + SpriteBatchNodeReorder(); virtual std::string title(); std::string subtitle(); @@ -88,6 +99,8 @@ public: class SpriteBatchNodeReorderIssue744: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorderIssue744); + SpriteBatchNodeReorderIssue744(); virtual std::string title(); std::string subtitle(); @@ -96,6 +109,8 @@ public: class SpriteBatchNodeReorderIssue766 : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorderIssue766); + SpriteBatchNodeReorderIssue766(); virtual std::string title(); virtual std::string subtitle(); @@ -112,6 +127,8 @@ private: class SpriteBatchNodeReorderIssue767 : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorderIssue767); + SpriteBatchNodeReorderIssue767(); virtual std::string title(); virtual std::string subtitle(); @@ -123,6 +140,8 @@ class SpriteZVertex: public SpriteTestDemo int _dir; float _time; public: + CREATE_FUNC(SpriteZVertex); + virtual void onEnter(); virtual void onExit(); SpriteZVertex(); @@ -134,6 +153,8 @@ class SpriteBatchNodeZVertex: public SpriteTestDemo int _dir; float _time; public: + CREATE_FUNC(SpriteBatchNodeZVertex); + virtual void onEnter(); virtual void onExit(); SpriteBatchNodeZVertex(); @@ -143,6 +164,8 @@ public: class SpriteAnchorPoint : public SpriteTestDemo { public: + CREATE_FUNC(SpriteAnchorPoint); + SpriteAnchorPoint(); virtual std::string title(); }; @@ -150,6 +173,8 @@ public: class SpriteBatchNodeAnchorPoint : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeAnchorPoint); + SpriteBatchNodeAnchorPoint(); virtual std::string title(); }; @@ -157,6 +182,8 @@ public: class Sprite6 : public SpriteTestDemo { public: + CREATE_FUNC(Sprite6); + Sprite6(); virtual std::string title(); }; @@ -164,6 +191,8 @@ public: class SpriteFlip : public SpriteTestDemo { public: + CREATE_FUNC(SpriteFlip); + SpriteFlip(); void flipSprites(float dt); virtual std::string title(); @@ -172,6 +201,7 @@ public: class SpriteBatchNodeFlip : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeFlip); SpriteBatchNodeFlip(); void flipSprites(float dt); virtual std::string title(); @@ -180,6 +210,7 @@ public: class SpriteAliased : public SpriteTestDemo { public: + CREATE_FUNC(SpriteAliased); SpriteAliased(); virtual void onEnter(); virtual void onExit(); @@ -189,6 +220,7 @@ public: class SpriteBatchNodeAliased : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeAliased); SpriteBatchNodeAliased(); virtual void onEnter(); virtual void onExit(); @@ -202,6 +234,7 @@ class SpriteNewTexture : public SpriteTestDemo Texture2D* _texture2; public: + CREATE_FUNC(SpriteNewTexture); SpriteNewTexture(); virtual ~SpriteNewTexture(); void addNewSprite(); @@ -215,6 +248,7 @@ class SpriteBatchNodeNewTexture : public SpriteTestDemo Texture2D* _texture2; public: + CREATE_FUNC(SpriteBatchNodeNewTexture); SpriteBatchNodeNewTexture(); virtual ~SpriteBatchNodeNewTexture(); void addNewSprite(); @@ -225,6 +259,7 @@ public: class SpriteFrameTest: public SpriteTestDemo { public: + CREATE_FUNC(SpriteFrameTest); virtual void onEnter(); virtual void onExit(); virtual std::string title(); @@ -233,6 +268,7 @@ public: void startIn05Secs(float dt); void flipSprites(float dt); private: + Sprite *_sprite1; Sprite *_sprite2; int _counter; @@ -241,6 +277,8 @@ private: class SpriteFrameAliasNameTest : public SpriteTestDemo { public: + CREATE_FUNC(SpriteFrameAliasNameTest); + virtual void onEnter(); virtual void onExit(); virtual std::string title(); @@ -250,6 +288,8 @@ public: class SpriteOffsetAnchorRotation: public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorRotation); + SpriteOffsetAnchorRotation(); virtual void onExit(); virtual std::string title(); @@ -258,6 +298,7 @@ public: class SpriteBatchNodeOffsetAnchorRotation: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotation); SpriteBatchNodeOffsetAnchorRotation(); virtual void onExit(); virtual std::string title(); @@ -266,6 +307,7 @@ public: class SpriteOffsetAnchorScale: public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorScale); SpriteOffsetAnchorScale(); virtual void onExit(); virtual std::string title(); @@ -274,6 +316,7 @@ public: class SpriteBatchNodeOffsetAnchorScale: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorScale); SpriteBatchNodeOffsetAnchorScale(); virtual void onExit(); virtual std::string title(); @@ -282,6 +325,7 @@ public: class SpriteOffsetAnchorSkew : public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorSkew); SpriteOffsetAnchorSkew(); ~SpriteOffsetAnchorSkew(); virtual std::string title(); @@ -290,6 +334,7 @@ public: class SpriteOffsetAnchorRotationalSkew : public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorRotationalSkew); SpriteOffsetAnchorRotationalSkew(); ~SpriteOffsetAnchorRotationalSkew(); virtual std::string title(); @@ -298,6 +343,7 @@ public: class SpriteBatchNodeOffsetAnchorSkew : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorSkew); SpriteBatchNodeOffsetAnchorSkew(); ~SpriteBatchNodeOffsetAnchorSkew(); virtual std::string title(); @@ -306,6 +352,7 @@ public: class SpriteOffsetAnchorRotationalSkewScale : public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorRotationalSkewScale); SpriteOffsetAnchorRotationalSkewScale(); ~SpriteOffsetAnchorRotationalSkewScale(); virtual std::string title(); @@ -314,6 +361,7 @@ public: class SpriteBatchNodeOffsetAnchorRotationalSkew : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotationalSkew); SpriteBatchNodeOffsetAnchorRotationalSkew(); ~SpriteBatchNodeOffsetAnchorRotationalSkew(); virtual std::string title(); @@ -322,6 +370,7 @@ public: class SpriteOffsetAnchorSkewScale : public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorSkewScale); SpriteOffsetAnchorSkewScale(); ~SpriteOffsetAnchorSkewScale(); virtual std::string title(); @@ -330,6 +379,7 @@ public: class SpriteBatchNodeOffsetAnchorSkewScale : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorSkewScale); SpriteBatchNodeOffsetAnchorSkewScale(); ~SpriteBatchNodeOffsetAnchorSkewScale(); virtual std::string title(); @@ -338,6 +388,7 @@ public: class SpriteBatchNodeOffsetAnchorRotationalSkewScale : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorRotationalSkewScale); SpriteBatchNodeOffsetAnchorRotationalSkewScale(); ~SpriteBatchNodeOffsetAnchorRotationalSkewScale(); virtual std::string title(); @@ -346,6 +397,7 @@ public: class SpriteOffsetAnchorFlip : public SpriteTestDemo { public: + CREATE_FUNC(SpriteOffsetAnchorFlip); SpriteOffsetAnchorFlip(); ~SpriteOffsetAnchorFlip(); virtual std::string title(); @@ -355,6 +407,7 @@ public: class SpriteBatchNodeOffsetAnchorFlip : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeOffsetAnchorFlip); SpriteBatchNodeOffsetAnchorFlip(); ~SpriteBatchNodeOffsetAnchorFlip(); virtual std::string title(); @@ -364,6 +417,7 @@ public: class SpriteAnimationSplit : public SpriteTestDemo { public: + CREATE_FUNC(SpriteAnimationSplit); SpriteAnimationSplit(); virtual void onExit(); virtual std::string title(); @@ -373,6 +427,8 @@ class SpriteHybrid: public SpriteTestDemo { bool _usingSpriteBatchNode; public: + CREATE_FUNC(SpriteHybrid); + SpriteHybrid(); void reparentSprite(float dt); virtual std::string title(); @@ -382,6 +438,7 @@ public: class SpriteBatchNodeChildren: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeChildren); SpriteBatchNodeChildren(); virtual void onExit(); virtual std::string title(); @@ -390,6 +447,7 @@ public: class SpriteBatchNodeChildrenZ : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeChildrenZ); SpriteBatchNodeChildrenZ(); virtual void onExit(); virtual std::string title(); @@ -398,6 +456,7 @@ public: class SpriteChildrenVisibility: public SpriteTestDemo { public: + CREATE_FUNC(SpriteChildrenVisibility); SpriteChildrenVisibility(); virtual void onExit(); virtual std::string title(); @@ -406,6 +465,7 @@ public: class SpriteChildrenVisibilityIssue665 : public SpriteTestDemo { public: + CREATE_FUNC(SpriteChildrenVisibilityIssue665); SpriteChildrenVisibilityIssue665(); ~SpriteChildrenVisibilityIssue665(); virtual std::string title(); @@ -415,6 +475,7 @@ public: class SpriteChildrenAnchorPoint: public SpriteTestDemo { public: + CREATE_FUNC(SpriteChildrenAnchorPoint); SpriteChildrenAnchorPoint(); virtual void onExit(); virtual std::string title(); @@ -423,6 +484,7 @@ public: class SpriteBatchNodeChildrenAnchorPoint: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeChildrenAnchorPoint); SpriteBatchNodeChildrenAnchorPoint(); virtual void onExit(); virtual std::string title(); @@ -431,6 +493,7 @@ public: class SpriteBatchNodeChildrenScale: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeChildrenScale); SpriteBatchNodeChildrenScale(); virtual std::string title(); }; @@ -438,6 +501,7 @@ public: class SpriteChildrenChildren: public SpriteTestDemo { public: + CREATE_FUNC(SpriteChildrenChildren); SpriteChildrenChildren(); virtual std::string title(); }; @@ -446,6 +510,7 @@ public: class SpriteBatchNodeChildrenChildren: public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeChildrenChildren); SpriteBatchNodeChildrenChildren(); virtual std::string title(); }; @@ -453,6 +518,7 @@ public: class SpriteNilTexture: public SpriteTestDemo { public: + CREATE_FUNC(SpriteNilTexture); SpriteNilTexture(); virtual std::string title(); std::string subtitle(); @@ -461,6 +527,7 @@ public: class SpriteSubclass : public SpriteTestDemo { public: + CREATE_FUNC(SpriteSubclass); SpriteSubclass(); virtual std::string title(); virtual std::string subtitle(); @@ -469,6 +536,7 @@ public: class AnimationCacheTest : public SpriteTestDemo { public: + CREATE_FUNC(AnimationCacheTest); AnimationCacheTest(); virtual std::string title(); virtual std::string subtitle(); @@ -477,6 +545,7 @@ public: class NodeSort : public SpriteTestDemo { public: + CREATE_FUNC(NodeSort); NodeSort(); virtual std::string title(); @@ -495,6 +564,7 @@ private: class SpriteBatchNodeReorderSameIndex : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorderSameIndex); SpriteBatchNodeReorderSameIndex(); virtual std::string title(); @@ -513,6 +583,7 @@ private: class SpriteBatchNodeReorderOneChild : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeReorderOneChild); SpriteBatchNodeReorderOneChild(); void reorderSprite(float dt); virtual std::string title(); @@ -524,6 +595,7 @@ private: class SpriteBatchNodeSkewNegativeScaleChildren : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeSkewNegativeScaleChildren); SpriteBatchNodeSkewNegativeScaleChildren(); ~SpriteBatchNodeSkewNegativeScaleChildren(); virtual std::string title(); @@ -533,6 +605,7 @@ public: class SpriteBatchNodeRotationalSkewNegativeScaleChildren : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchNodeRotationalSkewNegativeScaleChildren); SpriteBatchNodeRotationalSkewNegativeScaleChildren(); ~SpriteBatchNodeRotationalSkewNegativeScaleChildren(); virtual std::string title(); @@ -541,6 +614,7 @@ public: class SpriteSkewNegativeScaleChildren : public SpriteTestDemo { public: + CREATE_FUNC(SpriteSkewNegativeScaleChildren); SpriteSkewNegativeScaleChildren(); ~SpriteSkewNegativeScaleChildren(); virtual std::string title(); @@ -550,6 +624,7 @@ public: class SpriteRotationalSkewNegativeScaleChildren : public SpriteTestDemo { public: + CREATE_FUNC(SpriteRotationalSkewNegativeScaleChildren); SpriteRotationalSkewNegativeScaleChildren(); ~SpriteRotationalSkewNegativeScaleChildren(); virtual std::string title(); @@ -558,6 +633,7 @@ public: class SpriteDoubleResolution : public SpriteTestDemo { public: + CREATE_FUNC(SpriteDoubleResolution); SpriteDoubleResolution(); virtual std::string title(); virtual std::string subtitle(); @@ -566,6 +642,8 @@ public: class AnimationCacheFile : public SpriteTestDemo { public: + CREATE_FUNC(AnimationCacheFile); + AnimationCacheFile(); virtual std::string title(); virtual std::string subtitle(); @@ -574,6 +652,7 @@ public: class SpriteBatchBug1217 : public SpriteTestDemo { public: + CREATE_FUNC(SpriteBatchBug1217); SpriteBatchBug1217(); virtual std::string title(); virtual std::string subtitle(); From 0189f91480a2ae48686814ee961fc74d084f5ed3 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 13 Nov 2013 17:47:26 -0800 Subject: [PATCH 03/28] More tests working [x]: Texture2D test working OK --- .../Classes/Texture2dTest/Texture2dTest.cpp | 15 +--- .../Classes/Texture2dTest/Texture2dTest.h | 75 +++++++++++++++---- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index 6245237ca8..206f3f086a 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -85,12 +85,6 @@ static int sceneIdx=-1; Layer* createTextureTest(int index) { auto layer = (createFunctions[index])();; - - if (layer) - { - layer->autorelease(); - } - return layer; } @@ -145,26 +139,23 @@ TextureDemo::~TextureDemo() void TextureDemo::restartCallback(Object* sender) { - auto s = new TextureTestScene(); + auto s = TextureTestScene::create(); s->addChild(restartTextureTest()); Director::getInstance()->replaceScene(s); - s->autorelease(); } void TextureDemo::nextCallback(Object* sender) { - auto s = new TextureTestScene(); + auto s = TextureTestScene::create(); s->addChild(nextTextureTest()); Director::getInstance()->replaceScene(s); - s->autorelease(); } void TextureDemo::backCallback(Object* sender) { - auto s = new TextureTestScene(); + auto s = TextureTestScene::create(); s->addChild(backTextureTest()); Director::getInstance()->replaceScene(s); - s->autorelease(); } std::string TextureDemo::title() diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h index e590f25bef..7de47425a3 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h @@ -21,6 +21,7 @@ public: class TextureTIFF : public TextureDemo { public: + CREATE_FUNC(TextureTIFF); virtual std::string title(); virtual void onEnter(); }; @@ -28,6 +29,7 @@ public: class TexturePNG : public TextureDemo { public: + CREATE_FUNC(TexturePNG); virtual std::string title(); virtual void onEnter(); }; @@ -35,22 +37,23 @@ public: class TextureJPEG : public TextureDemo { public: + CREATE_FUNC(TextureJPEG); virtual std::string title(); - virtual void onEnter(); }; class TextureWEBP : public TextureDemo { public: + CREATE_FUNC(TextureWEBP); virtual std::string title(); - virtual void onEnter(); }; class TextureMipMap : public TextureDemo { public: + CREATE_FUNC(TextureMipMap); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -59,54 +62,55 @@ public: class TexturePVRTest : public TextureDemo { public: + CREATE_FUNC(TexturePVRTest); virtual std::string title(); - virtual void onEnter(); }; class TexturePVR2BPP : public TextureDemo { public: + CREATE_FUNC(TexturePVR2BPP); virtual std::string title(); - virtual void onEnter(); }; class TexturePVR4BPP : public TextureDemo { public: + CREATE_FUNC(TexturePVR4BPP); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRRGBA8888 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA8888); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRBGRA8888 : public TextureDemo { public: + CREATE_FUNC(TexturePVRBGRA8888); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRRGBA4444 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA4444); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRRGBA4444GZ : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA4444GZ); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -115,6 +119,7 @@ public: class TexturePVRRGBA4444CCZ : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA4444CCZ); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -123,22 +128,23 @@ public: class TexturePVRRGBA5551 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA5551); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRRGB565 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGB565); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRRGB888 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGB888); virtual std::string title(); virtual void onEnter(); }; @@ -146,30 +152,31 @@ public: class TexturePVRA8 : public TextureDemo { public: + CREATE_FUNC(TexturePVRA8); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRI8 : public TextureDemo { public: + CREATE_FUNC(TexturePVRI8); virtual std::string title(); - virtual void onEnter(); }; class TexturePVRAI88 : public TextureDemo { public: + CREATE_FUNC(TexturePVRAI88); virtual std::string title(); - virtual void onEnter(); }; class TexturePVR2BPPv3 : public TextureDemo { public: + CREATE_FUNC(TexturePVR2BPPv3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -178,6 +185,7 @@ public: class TexturePVRII2BPPv3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRII2BPPv3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -186,6 +194,7 @@ public: class TexturePVR4BPPv3 : public TextureDemo { public: + CREATE_FUNC(TexturePVR4BPPv3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -194,6 +203,7 @@ public: class TexturePVRII4BPPv3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRII4BPPv3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -202,6 +212,7 @@ public: class TexturePVRRGBA8888v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA8888v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -210,6 +221,7 @@ public: class TexturePVRBGRA8888v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRBGRA8888v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -218,6 +230,7 @@ public: class TexturePVRRGBA4444v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA4444v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -226,6 +239,7 @@ public: class TexturePVRRGBA5551v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGBA5551v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -234,6 +248,7 @@ public: class TexturePVRRGB565v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGB565v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -242,6 +257,7 @@ public: class TexturePVRRGB888v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRRGB888v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -250,6 +266,7 @@ public: class TexturePVRA8v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRA8v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -258,6 +275,7 @@ public: class TexturePVRI8v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRI8v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -266,6 +284,7 @@ public: class TexturePVRAI88v3 : public TextureDemo { public: + CREATE_FUNC(TexturePVRAI88v3); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -274,6 +293,7 @@ public: class TexturePVRBadEncoding : public TextureDemo { public: + CREATE_FUNC(TexturePVRBadEncoding); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -282,6 +302,7 @@ public: class TexturePVRMipMap : public TextureDemo { public: + CREATE_FUNC(TexturePVRMipMap); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -290,6 +311,7 @@ public: class TexturePVRMipMap2 : public TextureDemo { public: + CREATE_FUNC(TexturePVRMipMap2); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -298,6 +320,7 @@ public: class TexturePVRNonSquare : public TextureDemo { public: + CREATE_FUNC(TexturePVRNonSquare); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -306,6 +329,7 @@ public: class TexturePVRNPOT4444 : public TextureDemo { public: + CREATE_FUNC(TexturePVRNPOT4444); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -314,6 +338,7 @@ public: class TexturePVRNPOT8888 : public TextureDemo { public: + CREATE_FUNC(TexturePVRNPOT8888); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -322,6 +347,7 @@ public: class TextureAlias : public TextureDemo { public: + CREATE_FUNC(TextureAlias); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -330,6 +356,7 @@ public: class TexturePixelFormat : public TextureDemo { public: + CREATE_FUNC(TexturePixelFormat); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -338,6 +365,7 @@ public: class TextureBlend : public TextureDemo { public: + CREATE_FUNC(TextureBlend); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -346,6 +374,7 @@ public: class TextureAsync : public TextureDemo { public: + CREATE_FUNC(TextureAsync); virtual ~TextureAsync(); void loadImages(float dt); void imageLoaded(Object* pObj); @@ -359,6 +388,7 @@ private: class TextureGlRepeat : public TextureDemo { public: + CREATE_FUNC(TextureGlRepeat); virtual ~TextureGlRepeat(); virtual std::string title(); @@ -368,6 +398,7 @@ public: class TextureGlClamp : public TextureDemo { public: + CREATE_FUNC(TextureGlClamp); virtual ~TextureGlClamp(); virtual std::string title(); @@ -377,6 +408,7 @@ public: class TextureSizeTest : public TextureDemo { public: + CREATE_FUNC(TextureSizeTest); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -385,6 +417,7 @@ public: class TextureCache1 : public TextureDemo { public: + CREATE_FUNC(TextureCache1); virtual std::string title(); virtual std::string subtitle(); virtual void onEnter(); @@ -393,6 +426,7 @@ public: class TextureDrawAtPoint : public TextureDemo { public: + CREATE_FUNC(TextureDrawAtPoint); ~TextureDrawAtPoint(); virtual std::string title(); virtual std::string subtitle(); @@ -405,6 +439,7 @@ private: class TextureDrawInRect : public TextureDemo { public: + CREATE_FUNC(TextureDrawInRect); ~TextureDrawInRect(); virtual std::string title(); virtual std::string subtitle(); @@ -417,12 +452,14 @@ private: class TextureTestScene : public TestScene { public: + CREATE_FUNC(TextureTestScene); virtual void runThisTest(); }; class TextureMemoryAlloc : public TextureDemo { public: + CREATE_FUNC(TextureMemoryAlloc); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -435,6 +472,7 @@ private: class TexturePVRv3Premult : public TextureDemo { public: + CREATE_FUNC(TexturePVRv3Premult); TexturePVRv3Premult(); virtual std::string title(); @@ -447,6 +485,7 @@ public: class TextureETC1 : public TextureDemo { public: + CREATE_FUNC(TextureETC1); TextureETC1(); virtual std::string title(); @@ -457,6 +496,7 @@ public: class TextureS3TCDxt1 : public TextureDemo { public: + CREATE_FUNC(TextureS3TCDxt1); TextureS3TCDxt1(); virtual std::string title(); @@ -467,6 +507,7 @@ public: class TextureS3TCDxt3 : public TextureDemo { public: + CREATE_FUNC(TextureS3TCDxt3); TextureS3TCDxt3(); virtual std::string title(); @@ -477,6 +518,7 @@ public: class TextureS3TCDxt5 : public TextureDemo { public: + CREATE_FUNC(TextureS3TCDxt5); TextureS3TCDxt5(); virtual std::string title(); @@ -487,6 +529,7 @@ public: class TextureATITCRGB : public TextureDemo { public: + CREATE_FUNC(TextureATITCRGB); TextureATITCRGB(); virtual std::string title(); @@ -497,6 +540,7 @@ public: class TextureATITCExplicit : public TextureDemo { public: + CREATE_FUNC(TextureATITCExplicit); TextureATITCExplicit(); virtual std::string title(); @@ -507,6 +551,7 @@ public: class TextureATITCInterpolated : public TextureDemo { public: + CREATE_FUNC(TextureATITCInterpolated); TextureATITCInterpolated(); virtual std::string title(); @@ -518,6 +563,7 @@ public: class TextureConvertRGB888 : public TextureDemo { public: + CREATE_FUNC(TextureConvertRGB888); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -527,6 +573,7 @@ public: class TextureConvertRGBA8888 : public TextureDemo { public: + CREATE_FUNC(TextureConvertRGBA8888); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -536,6 +583,7 @@ public: class TextureConvertI8 : public TextureDemo { public: + CREATE_FUNC(TextureConvertI8); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); @@ -545,6 +593,7 @@ public: class TextureConvertAI88 : public TextureDemo { public: + CREATE_FUNC(TextureConvertAI88); virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); From b87684c02200cb88ccfe8408330b88c7c3f4a9b6 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 14 Nov 2013 15:37:43 -0800 Subject: [PATCH 04/28] fixes Sprite::setTexture() Sprite::setTexture(std::string&) works as expected. It sets the texture rect of the sprite --- cocos/2d/CCSprite.cpp | 277 ++++++++++++++++++++++-------------------- cocos/2d/CCSprite.h | 25 ++-- 2 files changed, 159 insertions(+), 143 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 60f86ff429..7fb20d95df 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -145,7 +145,74 @@ Sprite* Sprite::create() bool Sprite::init(void) { - return initWithTexture(NULL, Rect::ZERO); + return initWithTexture(NULL, Rect::ZERO ); +} + +bool Sprite::initWithTexture(Texture2D *texture) +{ + CCASSERT(texture != NULL, "Invalid texture for sprite"); + + Rect rect = Rect::ZERO; + rect.size = texture->getContentSize(); + + return initWithTexture(texture, rect); +} + +bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect) +{ + return initWithTexture(texture, rect, false); +} + +bool Sprite::initWithFile(const std::string& filename) +{ + CCASSERT(filename.size()>0, "Invalid filename for sprite"); + + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + if (texture) + { + Rect rect = Rect::ZERO; + rect.size = texture->getContentSize(); + return initWithTexture(texture, rect); + } + + // don't release here. + // when load texture failed, it's better to get a "transparent" sprite then a crashed program + // this->release(); + return false; +} + +bool Sprite::initWithFile(const std::string &filename, const Rect& rect) +{ + CCASSERT(filename.size()>0, "Invalid filename"); + + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + if (texture) + { + return initWithTexture(texture, rect); + } + + // don't release here. + // when load texture failed, it's better to get a "transparent" sprite then a crashed program + // this->release(); + return false; +} + +bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) +{ + CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName"); + + SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); + return initWithSpriteFrame(frame); +} + +bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) +{ + CCASSERT(spriteFrame != NULL, ""); + + bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect()); + setSpriteFrame(spriteFrame); + + return bRet; } // designated initializer @@ -200,73 +267,6 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) } } -bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect) -{ - return initWithTexture(texture, rect, false); -} - -bool Sprite::initWithTexture(Texture2D *texture) -{ - CCASSERT(texture != NULL, "Invalid texture for sprite"); - - Rect rect = Rect::ZERO; - rect.size = texture->getContentSize(); - - return initWithTexture(texture, rect); -} - -bool Sprite::initWithFile(const std::string& filename) -{ - CCASSERT(filename.size()>0, "Invalid filename for sprite"); - - Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); - if (texture) - { - Rect rect = Rect::ZERO; - rect.size = texture->getContentSize(); - return initWithTexture(texture, rect); - } - - // don't release here. - // when load texture failed, it's better to get a "transparent" sprite then a crashed program - // this->release(); - return false; -} - -bool Sprite::initWithFile(const std::string &filename, const Rect& rect) -{ - CCASSERT(filename.size()>0, "Invalid filename"); - - Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); - if (texture) - { - return initWithTexture(texture, rect); - } - - // don't release here. - // when load texture failed, it's better to get a "transparent" sprite then a crashed program - // this->release(); - return false; -} - -bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) -{ - CCASSERT(spriteFrame != NULL, ""); - - bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect()); - setDisplayFrame(spriteFrame); - - return bRet; -} - -bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) -{ - CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName"); - - SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); - return initWithSpriteFrame(frame); -} - // XXX: deprecated /* Sprite* Sprite::initWithCGImage(CGImageRef pImage) @@ -304,11 +304,76 @@ Sprite::~Sprite(void) CC_SAFE_RELEASE(_texture); } +/* + * Texture methods + */ + +/* + * This array is the data of a white image with 2 by 2 dimension. + * It's used for creating a default texture when sprite's texture is set to NULL. + * Supposing codes as follows: + * + * auto sp = new Sprite(); + * sp->init(); // Texture was set to NULL, in order to make opacity and color to work correctly, we need to create a 2x2 white texture. + * + * The test is in "TestCpp/SpriteTest/Sprite without texture". + */ +static unsigned char cc_2x2_white_image[] = { + // RGBA8888 + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF +}; + +#define CC_2x2_WHITE_IMAGE_KEY "/cc_2x2_white_image" void Sprite::setTexture(const std::string &filename) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); setTexture(texture); + + Rect rect = Rect::ZERO; + rect.size = texture->getContentSize(); + setTextureRect(rect); +} + +void Sprite::setTexture(Texture2D *texture) +{ + // If batchnode, then texture id should be the same + CCASSERT(! _batchNode || texture->getName() == _batchNode->getTexture()->getName(), "CCSprite: Batched sprites should use the same texture as the batchnode"); + // accept texture==nil as argument + CCASSERT( !texture || dynamic_cast(texture), "setTexture expects a Texture2D. Invalid argument"); + + if (texture == nullptr) + { + // Gets the texture by key firstly. + texture = Director::getInstance()->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY); + + // If texture wasn't in cache, create it from RAW data. + if (texture == nullptr) + { + Image* image = new Image(); + bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8); + CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); + + texture = Director::getInstance()->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); + CC_SAFE_RELEASE(image); + } + } + + if (!_batchNode && _texture != texture) + { + CC_SAFE_RETAIN(texture); + CC_SAFE_RELEASE(_texture); + _texture = texture; + updateBlendFunc(); + } +} + +Texture2D* Sprite::getTexture() const +{ + return _texture; } void Sprite::setTextureRect(const Rect& rect) @@ -998,20 +1063,20 @@ void Sprite::setSpriteFrame(const std::string &spriteFrameName) setSpriteFrame(spriteFrame); } -void Sprite::setSpriteFrame(SpriteFrame *pNewFrame) +void Sprite::setSpriteFrame(SpriteFrame *spriteFrame) { - _unflippedOffsetPositionFromCenter = pNewFrame->getOffset(); + _unflippedOffsetPositionFromCenter = spriteFrame->getOffset(); - Texture2D *pNewTexture = pNewFrame->getTexture(); + Texture2D *texture = spriteFrame->getTexture(); // update texture before updating texture rect - if (pNewTexture != _texture) + if (texture != _texture) { - setTexture(pNewTexture); + setTexture(texture); } // update rect - _rectRotated = pNewFrame->isRotated(); - setTextureRect(pNewFrame->getRect(), _rectRotated, pNewFrame->getOriginalSize()); + _rectRotated = spriteFrame->isRotated(); + setTextureRect(spriteFrame->getRect(), _rectRotated, spriteFrame->getOriginalSize()); } void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex) @@ -1026,7 +1091,7 @@ void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, CCASSERT(frame, "CCSprite#setDisplayFrame. Invalid frame"); - setDisplayFrame(frame->getSpriteFrame()); + setSpriteFrame(frame->getSpriteFrame()); } bool Sprite::isFrameDisplayed(SpriteFrame *frame) const @@ -1038,7 +1103,7 @@ bool Sprite::isFrameDisplayed(SpriteFrame *frame) const frame->getOffset().equals(_unflippedOffsetPositionFromCenter)); } -SpriteFrame* Sprite::getDisplayFrame() +SpriteFrame* Sprite::getSpriteFrame() const { return SpriteFrame::createWithTexture(_texture, CC_RECT_POINTS_TO_PIXELS(_rect), @@ -1099,62 +1164,4 @@ void Sprite::updateBlendFunc(void) } } -/* - * This array is the data of a white image with 2 by 2 dimension. - * It's used for creating a default texture when sprite's texture is set to NULL. - * Supposing codes as follows: - * - * auto sp = new Sprite(); - * sp->init(); // Texture was set to NULL, in order to make opacity and color to work correctly, we need to create a 2x2 white texture. - * - * The test is in "TestCpp/SpriteTest/Sprite without texture". - */ -static unsigned char cc_2x2_white_image[] = { - // RGBA8888 - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF -}; - -#define CC_2x2_WHITE_IMAGE_KEY "/cc_2x2_white_image" - -void Sprite::setTexture(Texture2D *texture) -{ - // If batchnode, then texture id should be the same - CCASSERT(! _batchNode || texture->getName() == _batchNode->getTexture()->getName(), "CCSprite: Batched sprites should use the same texture as the batchnode"); - // accept texture==nil as argument - CCASSERT( !texture || dynamic_cast(texture), "setTexture expects a Texture2D. Invalid argument"); - - if (NULL == texture) - { - // Gets the texture by key firstly. - texture = Director::getInstance()->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY); - - // If texture wasn't in cache, create it from RAW data. - if (NULL == texture) - { - Image* image = new Image(); - bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8); - CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); - - texture = Director::getInstance()->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); - CC_SAFE_RELEASE(image); - } - } - - if (!_batchNode && _texture != texture) - { - CC_SAFE_RETAIN(texture); - CC_SAFE_RELEASE(_texture); - _texture = texture; - updateBlendFunc(); - } -} - -Texture2D* Sprite::getTexture(void) const -{ - return _texture; -} - NS_CC_END diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index a0c70d4705..ac70a17c6d 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -194,9 +194,19 @@ public: /// @{ /// @name Texture / Frame methods - /** Sets a new texture (from a filename) to the sprite */ + /** Sets a new texture (from a filename) to the sprite. + It will call `setTextureRect()` with the texture's content size. + */ virtual void setTexture(const std::string &filename ); + /** Sets a new texture to the sprite. + The Texture's rect is not changed. + */ + virtual void setTexture(Texture2D *texture) override; + + /** returns the Texture2D object used by the sprite */ + virtual Texture2D* getTexture() const override; + /** * Updates the texture rect of the Sprite in points. * It will call setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) with \p rotated = false, and \p utrimmedSize = rect.size. @@ -224,20 +234,21 @@ public: virtual void setSpriteFrame(const std::string &spriteFrameName); /** @deprecated Use `setSpriteFrame()` instead. */ - virtual void setDisplayFrame(SpriteFrame *newFrame) CC_DEPRECATED_ATTRIBUTE { setSpriteFrame(newFrame); } + CC_DEPRECATED_ATTRIBUTE virtual void setDisplayFrame(SpriteFrame *newFrame) { setSpriteFrame(newFrame); } /** * Returns whether or not a SpriteFrame is being displayed */ virtual bool isFrameDisplayed(SpriteFrame *pFrame) const; - /** @deprecated Use getDisplayFrame() instead */ - CC_DEPRECATED_ATTRIBUTE virtual SpriteFrame* displayFrame() { return getDisplayFrame(); }; - /** * Returns the current displayed frame. */ - virtual SpriteFrame* getDisplayFrame(); + virtual SpriteFrame* getSpriteFrame() const; + /** @deprecated Use `getSpriteFrame()` instead */ + CC_DEPRECATED_ATTRIBUTE virtual SpriteFrame* getDisplayFrame() const { return getSpriteFrame(); } + /** @deprecated Use `getSpriteFrame()` instead */ + CC_DEPRECATED_ATTRIBUTE virtual SpriteFrame* displayFrame() const { return getSpriteFrame(); }; /// @} End of frames methods @@ -367,8 +378,6 @@ public: // /// @{ /// @name Functions inherited from TextureProtocol - virtual void setTexture(Texture2D *texture) override; - virtual Texture2D* getTexture() const override; /** *@code *When this function bound into js or lua,the parameter will be changed From c52dc4ff5f0a167fccd24325b18ccbdf11f6abd1 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 14 Nov 2013 15:44:22 -0800 Subject: [PATCH 05/28] Adds love to ShaderTest2 test Improves the code in ShaderTest2 --- .../Classes/ShaderTest/ShaderTest2.cpp | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index de753d2b18..89fddc5be0 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -148,24 +148,24 @@ void ShaderSprite::initShader() { GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( FileUtils::getInstance()->fullPathForFilename(_fragSourceFile).c_str())->getCString(); - auto pProgram = new GLProgram(); - pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); - setShaderProgram(pProgram); - pProgram->release(); + auto program = new GLProgram(); + program->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); + setShaderProgram(program); + program->release(); CHECK_GL_ERROR_DEBUG(); - getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); - getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); - getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); + program->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); + program->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); + program->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); CHECK_GL_ERROR_DEBUG(); - getShaderProgram()->link(); + program->link(); CHECK_GL_ERROR_DEBUG(); - getShaderProgram()->updateUniforms(); + program->updateUniforms(); CHECK_GL_ERROR_DEBUG(); @@ -176,14 +176,12 @@ void ShaderSprite::initShader() void ShaderSprite::draw() { - GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); - BlendFunc blend = getBlendFunc(); - GL::blendFunc(blend.src, blend.dst); - - getShaderProgram()->use(); - getShaderProgram()->setUniformsForBuiltins(); + CC_NODE_DRAW_SETUP(); + setCustomUniforms(); - + + GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); + GL::blendFunc(_blendFunc.src, _blendFunc.dst); GL::bindTexture2D( getTexture()->getName()); // From dd68eb47966792e1724c666bb1e60c553dbd5f26 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 14 Nov 2013 16:21:49 -0800 Subject: [PATCH 06/28] ParticleSystem uses protected constructors --- cocos/2d/CCAtlasNode.h | 34 ++-- cocos/2d/CCDrawNode.h | 18 +-- cocos/2d/CCParticleSystem.cpp | 4 +- cocos/2d/CCParticleSystem.h | 72 +++++---- cocos/2d/CCParticleSystemQuad.cpp | 30 ++-- cocos/2d/CCParticleSystemQuad.h | 45 +++--- cocos/2d/CCSprite.h | 1 + cocos/2d/CCTransition.h | 147 +++++++++--------- .../Classes/ParticleTest/ParticleTest.cpp | 45 +++--- .../Classes/ParticleTest/ParticleTest.h | 2 +- .../PerformanceParticleTest.cpp | 4 +- 11 files changed, 197 insertions(+), 205 deletions(-) diff --git a/cocos/2d/CCAtlasNode.h b/cocos/2d/CCAtlasNode.h index 8c31496d41..b196f45a1d 100644 --- a/cocos/2d/CCAtlasNode.h +++ b/cocos/2d/CCAtlasNode.h @@ -53,22 +53,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol public: /** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ static AtlasNode * create(const std::string& filename, long tileWidth, long tileHeight, long itemsToRender); - /** - * @js ctor - */ - AtlasNode(); - /** - * @js NA - * @lua NA - */ - virtual ~AtlasNode(); - /** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ - bool initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender); - - /** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/ - bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender); - /** updates the Atlas (indexed vertex array). * Shall be overridden in subclasses */ @@ -104,15 +89,24 @@ public: */ virtual const BlendFunc& getBlendFunc() const override; -private : + +protected: + AtlasNode(); + virtual ~AtlasNode(); + + /** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ + bool initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender); + + /** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/ + bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender); + void calculateMaxItems(); void updateBlendFunc(); void updateOpacityModifyRGB(); - + friend class Director; void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor); -protected: //! chars per row long _itemsPerRow; //! chars per column @@ -136,6 +130,10 @@ protected: GLint _uniformColor; // This varible is only used for LabelAtlas FPS display. So plz don't modify its value. bool _ignoreContentScaleFactor; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(AtlasNode); + }; // end of base_node group diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index fe7312ade8..7636cf7326 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -46,17 +46,6 @@ class CC_DLL DrawNode : public Node public: /** creates and initialize a DrawNode node */ static DrawNode* create(); - /** - * @js ctor - */ - DrawNode(); - /** - * @js NA - * @lua NA - */ - virtual ~DrawNode(); - - virtual bool init(); /** draw a dot at a position, with a given radius and color */ void drawDot(const Point &pos, float radius, const Color4F &color); @@ -99,6 +88,10 @@ public: virtual void draw() override; protected: + DrawNode(); + virtual ~DrawNode(); + virtual bool init(); + void ensureCapacity(long count); void render(); @@ -112,6 +105,9 @@ protected: BlendFunc _blendFunc; bool _dirty; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(DrawNode); }; NS_CC_END diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index ce34d18be1..19e0fb1cd0 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -148,7 +148,7 @@ ParticleSystem * ParticleSystem::create(const std::string& plistFile) return pRet; } -ParticleSystem* ParticleSystem::createWithTotalParticles(unsigned int numberOfParticles) +ParticleSystem* ParticleSystem::createWithTotalParticles(int numberOfParticles) { ParticleSystem *pRet = new ParticleSystem(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -425,7 +425,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin return bRet; } -bool ParticleSystem::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSystem::initWithTotalParticles(int numberOfParticles) { _totalParticles = numberOfParticles; diff --git a/cocos/2d/CCParticleSystem.h b/cocos/2d/CCParticleSystem.h index 1cd30b56c8..7300c90ca9 100644 --- a/cocos/2d/CCParticleSystem.h +++ b/cocos/2d/CCParticleSystem.h @@ -170,38 +170,7 @@ public: static ParticleSystem * create(const std::string& plistFile); //! create a system with a fixed number of particles - static ParticleSystem* createWithTotalParticles(unsigned int numberOfParticles); - /** - * @js ctor - */ - ParticleSystem(); - /** - * @js NA - * @lua NA - */ - virtual ~ParticleSystem(); - - /** initializes a ParticleSystem*/ - bool init(); - /** initializes a ParticleSystem from a plist file. - This plist files can be created manually or with Particle Designer: - http://particledesigner.71squared.com/ - @since v0.99.3 - */ - bool initWithFile(const std::string& plistFile); - - /** initializes a QuadParticleSystem from a Dictionary. - @since v0.99.3 - */ - bool initWithDictionary(Dictionary *dictionary); - - /** initializes a particle system from a NSDictionary and the path from where to load the png - @since v2.1 - */ - bool initWithDictionary(Dictionary *dictionary, const std::string& dirname); - - //! Initializes a system with a fixed number of particles - virtual bool initWithTotalParticles(unsigned int numberOfParticles); + static ParticleSystem* createWithTotalParticles(int numberOfParticles); //! Add a particle to the emitter bool addParticle(); @@ -393,10 +362,42 @@ public: * @lua NA */ virtual const BlendFunc &getBlendFunc() const override; -protected: - virtual void updateBlendFunc(); protected: + /** + * @js ctor + */ + ParticleSystem(); + /** + * @js NA + * @lua NA + */ + virtual ~ParticleSystem(); + + /** initializes a ParticleSystem*/ + bool init(); + /** initializes a ParticleSystem from a plist file. + This plist files can be created manually or with Particle Designer: + http://particledesigner.71squared.com/ + @since v0.99.3 + */ + bool initWithFile(const std::string& plistFile); + + /** initializes a QuadParticleSystem from a Dictionary. + @since v0.99.3 + */ + bool initWithDictionary(Dictionary *dictionary); + + /** initializes a particle system from a NSDictionary and the path from where to load the png + @since v2.1 + */ + bool initWithDictionary(Dictionary *dictionary, const std::string& dirname); + + //! Initializes a system with a fixed number of particles + virtual bool initWithTotalParticles(int numberOfParticles); + + virtual void updateBlendFunc(); + /** whether or not the particles are using blend additive. If enabled, the following blending function will be used. @code @@ -551,6 +552,9 @@ protected: @since v0.8 */ PositionType _positionType; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem); }; // end of particle_nodes group diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 36d2567809..89d287bf38 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -46,7 +46,7 @@ NS_CC_BEGIN //implementation ParticleSystemQuad // overriding the init method -bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles) { // base initialization if( ParticleSystem::initWithTotalParticles(numberOfParticles) ) @@ -111,27 +111,27 @@ ParticleSystemQuad::~ParticleSystemQuad() // implementation ParticleSystemQuad -ParticleSystemQuad * ParticleSystemQuad::create(const char *plistFile) +ParticleSystemQuad * ParticleSystemQuad::create(const std::string& filename) { - ParticleSystemQuad *pRet = new ParticleSystemQuad(); - if (pRet && pRet->initWithFile(plistFile)) + ParticleSystemQuad *ret = new ParticleSystemQuad(); + if (ret && ret->initWithFile(filename)) { - pRet->autorelease(); - return pRet; + ret->autorelease(); + return ret; } - CC_SAFE_DELETE(pRet); - return pRet; + CC_SAFE_DELETE(ret); + return ret; } -ParticleSystemQuad * ParticleSystemQuad::createWithTotalParticles(unsigned int numberOfParticles) { - ParticleSystemQuad *pRet = new ParticleSystemQuad(); - if (pRet && pRet->initWithTotalParticles(numberOfParticles)) +ParticleSystemQuad * ParticleSystemQuad::createWithTotalParticles(int numberOfParticles) { + ParticleSystemQuad *ret = new ParticleSystemQuad(); + if (ret && ret->initWithTotalParticles(numberOfParticles)) { - pRet->autorelease(); - return pRet; + ret->autorelease(); + return ret; } - CC_SAFE_DELETE(pRet); - return pRet; + CC_SAFE_DELETE(ret); + return ret; } diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 594810cf96..5f11dd1533 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -57,26 +57,11 @@ public: /** creates a Particle Emitter */ static ParticleSystemQuad * create(); /** creates a Particle Emitter with a number of particles */ - static ParticleSystemQuad * createWithTotalParticles(unsigned int numberOfParticles); + static ParticleSystemQuad * createWithTotalParticles(int numberOfParticles); /** creates an initializes a ParticleSystemQuad from a plist file. This plist files can be created manually or with Particle Designer: */ - static ParticleSystemQuad * create(const char *plistFile); - /** - * @js ctor - */ - ParticleSystemQuad(); - /** - * @js NA - * @lua NA - */ - virtual ~ParticleSystemQuad(); - - /** initializes the indices for the vertices*/ - void initIndices(); - - /** initializes the texture with a rectangle measured Points */ - void initTexCoordsWithRect(const Rect& rect); + static ParticleSystemQuad * create(const std::string& filename); /** Sets a new SpriteFrame as particle. WARNING: this method is experimental. Use setTextureWithRect instead. @@ -102,7 +87,7 @@ public: * @js NA * @lua NA */ - virtual bool initWithTotalParticles(unsigned int numberOfParticles) override; + virtual bool initWithTotalParticles(int numberOfParticles) override; /** * @js NA * @lua NA @@ -134,18 +119,36 @@ public: */ virtual void setTotalParticles(int tp) override; -private: +protected: + /** + * @js ctor + */ + ParticleSystemQuad(); + /** + * @js NA + * @lua NA + */ + virtual ~ParticleSystemQuad(); + + /** initializes the indices for the vertices*/ + void initIndices(); + + /** initializes the texture with a rectangle measured Points */ + void initTexCoordsWithRect(const Rect& rect); + void setupVBOandVAO(); void setupVBO(); bool allocMemory(); - -protected: + V3F_C4B_T2F_Quad *_quads; // quads to be rendered GLushort *_indices; // indices GLuint _VAOname; GLuint _buffersVBO[2]; //0: vertex 1: indices + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad); }; // end of particle_nodes group diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index ac70a17c6d..878ef94e51 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -196,6 +196,7 @@ public: /** Sets a new texture (from a filename) to the sprite. It will call `setTextureRect()` with the texture's content size. + TODO: The whole Sprite API needs to be reviewed. */ virtual void setTexture(const std::string &filename ); diff --git a/cocos/2d/CCTransition.h b/cocos/2d/CCTransition.h index bdcd8b58e7..74885302a6 100644 --- a/cocos/2d/CCTransition.h +++ b/cocos/2d/CCTransition.h @@ -77,18 +77,6 @@ public: /** creates a base transition with duration and incoming scene */ static TransitionScene * create(float t, Scene *scene); - /** - * @js ctor - */ - TransitionScene(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionScene(); - - /** initializes a transition with duration and incoming scene */ - bool initWithDuration(float t,Scene* scene); /** called after the transition finishes */ void finish(void); @@ -113,17 +101,23 @@ public: virtual void cleanup() override; protected: - virtual void sceneOrder(); + TransitionScene(); + virtual ~TransitionScene(); -private: + /** initializes a transition with duration and incoming scene */ + bool initWithDuration(float t,Scene* scene); + + virtual void sceneOrder(); void setNewScene(float dt); -protected: Scene * _inScene; Scene * _outScene; float _duration; bool _isInSceneOnTop; bool _isSendCleanupToScene; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionScene); }; /** @brief A Transition that supports orientation like. @@ -134,21 +128,18 @@ class CC_DLL TransitionSceneOriented : public TransitionScene public: /** creates a base transition with duration and incoming scene */ static TransitionSceneOriented * create(float t,Scene* scene, Orientation orientation); - /** - * @js ctor - */ + +protected: TransitionSceneOriented(); - /** - * @js NA - * @lua NA - */ virtual ~TransitionSceneOriented(); /** initializes a transition with duration and incoming scene */ bool initWithDuration(float t,Scene* scene,Orientation orientation); -protected: Orientation _orientation; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSceneOriented); }; /** @brief TransitionRotoZoom: @@ -159,12 +150,6 @@ class CC_DLL TransitionRotoZoom : public TransitionScene public: static TransitionRotoZoom* create(float t, Scene* scene); - TransitionRotoZoom(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionRotoZoom(); // // Overrides @@ -174,6 +159,14 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionRotoZoom(); + virtual ~TransitionRotoZoom(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionRotoZoom); + }; /** @brief TransitionJumpZoom: @@ -183,15 +176,6 @@ class CC_DLL TransitionJumpZoom : public TransitionScene { public: static TransitionJumpZoom* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionJumpZoom(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionJumpZoom(); // // Overrides @@ -201,6 +185,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionJumpZoom(); + virtual ~TransitionJumpZoom(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionJumpZoom); }; /** @brief TransitionMoveInL: @@ -210,15 +201,7 @@ class CC_DLL TransitionMoveInL : public TransitionScene, public TransitionEaseSc { public: static TransitionMoveInL* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionMoveInL(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionMoveInL(); + /** initializes the scenes */ virtual void initScenes(void); /** returns the action that will be performed */ @@ -234,6 +217,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionMoveInL(); + virtual ~TransitionMoveInL(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInL); }; /** @brief TransitionMoveInR: @@ -243,16 +233,14 @@ class CC_DLL TransitionMoveInR : public TransitionMoveInL { public: static TransitionMoveInR* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionMoveInR(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionMoveInR(); virtual void initScenes(); + +protected: + TransitionMoveInR(); + virtual ~TransitionMoveInR(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInR); }; /** @brief TransitionMoveInT: @@ -262,16 +250,14 @@ class CC_DLL TransitionMoveInT : public TransitionMoveInL { public: static TransitionMoveInT* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionMoveInT(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionMoveInT(); virtual void initScenes(); + +protected: + TransitionMoveInT(); + virtual ~TransitionMoveInT(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInT); }; /** @brief TransitionMoveInB: @@ -281,6 +267,9 @@ class CC_DLL TransitionMoveInB : public TransitionMoveInL { public: static TransitionMoveInB* create(float t, Scene* scene); + virtual void initScenes(); + +protected: /** * @js ctor */ @@ -290,7 +279,9 @@ public: * @lua NA */ virtual ~TransitionMoveInB(); - virtual void initScenes(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInB); }; /** @brief TransitionSlideInL: @@ -300,15 +291,6 @@ class CC_DLL TransitionSlideInL : public TransitionScene, public TransitionEaseS { public: static TransitionSlideInL* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSlideInL(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSlideInL(); virtual ActionInterval* easeActionWithAction(ActionInterval * action); @@ -325,9 +307,22 @@ public: * @lua NA */ virtual void onEnter() override; - + protected: + /** + * @js ctor + */ + TransitionSlideInL(); + /** + * @js NA + * @lua NA + */ + virtual ~TransitionSlideInL(); + virtual void sceneOrder() override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSlideInL); }; /** @brief TransitionSlideInR: diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp index c4e3b15bad..88fd2cebd2 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp @@ -135,9 +135,8 @@ void DemoBigFlower::onEnter() { ParticleDemo::onEnter(); - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(50); - //_emitter->autorelease(); + _emitter = ParticleSystemQuad::createWithTotalParticles(50); + _emitter->retain(); _background->addChild(_emitter, 10); ////_emitter->release(); // win32 : use this line or remove this line and use autorelease() @@ -219,9 +218,8 @@ void DemoRotFlower::onEnter() { ParticleDemo::onEnter(); - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(300); - //_emitter->autorelease(); + _emitter = ParticleSystemQuad::createWithTotalParticles(300); + _emitter->retain(); _background->addChild(_emitter, 10); ////_emitter->release(); // win32 : Remove this line @@ -477,10 +475,8 @@ void DemoModernArt::onEnter() //FIXME: If use ParticleSystemPoint, bada 1.0 device will crash. // Crash place: ParticleSystemPoint.cpp Line 149, function: glDrawArrays(GL_POINTS, 0, _particleIdx); -// _emitter = new ParticleSystemPoint(); - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(1000); - //_emitter->autorelease(); + _emitter = ParticleSystemQuad::createWithTotalParticles(1000); + _emitter->retain(); _background->addChild(_emitter, 10); ////_emitter->release(); @@ -638,8 +634,8 @@ void RadiusMode1::onEnter() removeChild(_background, true); _background = NULL; - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(200); + _emitter = ParticleSystemQuad::createWithTotalParticles(200); + _emitter->retain(); addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png")); @@ -722,8 +718,8 @@ void RadiusMode2::onEnter() removeChild(_background, true); _background = NULL; - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(200); + _emitter = ParticleSystemQuad::createWithTotalParticles(200); + _emitter->retain(); addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/stars-grayscale.png")); @@ -806,8 +802,8 @@ void Issue704::onEnter() removeChild(_background, true); _background = NULL; - _emitter = new ParticleSystemQuad(); - _emitter->initWithTotalParticles(100); + _emitter = ParticleSystemQuad::createWithTotalParticles(100); + _emitter->retain(); addChild(_emitter, 10); _emitter->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); @@ -898,11 +894,10 @@ void Issue870::onEnter() removeChild(_background, true); _background = NULL; - auto system = new ParticleSystemQuad(); - system->initWithFile("Particles/SpinningPeas.plist"); - system->setTextureWithRect(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"), Rect(0,0,32,32)); - addChild(system, 10); - _emitter = system; + _emitter = ParticleSystemQuad::create("Particles/SpinningPeas.plist"); + _emitter->setTextureWithRect(Director::getInstance()->getTextureCache()->addImage("Images/particles.png"), Rect(0,0,32,32)); + addChild(_emitter, 10); + _emitter->retain(); _index = 0; schedule(schedule_selector(Issue870::updateQuads), 2.0f); @@ -939,9 +934,9 @@ void DemoParticleFromFile::onEnter() removeChild(_background, true); _background = NULL; - _emitter = new ParticleSystemQuad(); std::string filename = "Particles/" + _title + ".plist"; - _emitter->initWithFile(filename.c_str()); + _emitter = ParticleSystemQuad::create(filename); + _emitter->retain(); addChild(_emitter, 10); setEmitterPosition(); @@ -1717,8 +1712,8 @@ void ReorderParticleSystems::onEnter() for (int i = 0; i<3; i++) { - auto particleSystem = new ParticleSystemQuad(); - particleSystem->initWithTotalParticles(200); + auto particleSystem = ParticleSystemQuad::createWithTotalParticles(200); + particleSystem->retain(); particleSystem->setTexture(_batchNode->getTexture()); // duration diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h index 4c9e63047f..f5fe206faf 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h @@ -16,7 +16,7 @@ public: class ParticleDemo : public BaseTest { protected: - ParticleSystem* _emitter; + ParticleSystemQuad* _emitter; Sprite* _background; LayerColor* _color; diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp index b6878a5b22..12cacb6421 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp @@ -170,7 +170,7 @@ void ParticleMainScene::step(float dt) void ParticleMainScene::createParticleSystem() { - ParticleSystem *particleSystem = NULL; + ParticleSystemQuad *particleSystem = nullptr; /* * Tests: @@ -196,7 +196,7 @@ void ParticleMainScene::createParticleSystem() // } // else { - particleSystem = new ParticleSystemQuad(); + particleSystem = ParticleSystemQuad::create(); } switch( subtestNumber) From 17a6575bd3fbf9e12f08803e70a013fd72e9407c Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 14 Nov 2013 16:33:43 -0800 Subject: [PATCH 07/28] more protected constructors Adds protected constructors for: * ClippingNode * ParallaxNode * RenderTexture * TMXTiledMap --- cocos/2d/CCClippingNode.h | 42 ++++++++++--------- cocos/2d/CCMotionStreak.h | 34 ++++++++------- cocos/2d/CCParallaxNode.h | 27 ++++++------ cocos/2d/CCProgressTimer.h | 28 +++++++------ cocos/2d/CCRenderTexture.h | 38 +++++++++-------- cocos/2d/CCTMXTiledMap.h | 39 +++++++++-------- .../RenderTextureTest/RenderTextureTest.cpp | 12 +++--- .../RenderTextureTest/RenderTextureTest.h | 2 +- 8 files changed, 121 insertions(+), 101 deletions(-) diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index ca2a17b8d7..7c18e99e01 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -49,21 +49,7 @@ public: The stencil node will be retained. */ static ClippingNode* create(Node *pStencil); - /** - * @js NA - * @lua NA - */ - virtual ~ClippingNode(); - - /** Initializes a clipping node without a stencil. - */ - virtual bool init(); - - /** Initializes a clipping node with an other node as its stencil. - The stencil node will be retained, and its parent will be set to this clipping node. - */ - virtual bool init(Node *pStencil); - + /** The Node to use as a stencil to do the clipping. The stencil node will be retained. This default to nil. @@ -109,18 +95,34 @@ public: virtual void onExit() override; virtual void visit() override; -private: +protected: + ClippingNode(); + + /** + * @js NA + * @lua NA + */ + virtual ~ClippingNode(); + + /** Initializes a clipping node without a stencil. + */ + virtual bool init(); + + /** Initializes a clipping node with an other node as its stencil. + The stencil node will be retained, and its parent will be set to this clipping node. + */ + virtual bool init(Node *pStencil); + /**draw fullscreen quad to clear stencil bits */ void drawFullScreenQuadClearStencil(); -protected: - ClippingNode(); - -protected: Node* _stencil; GLfloat _alphaThreshold; bool _inverted; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode); }; NS_CC_END diff --git a/cocos/2d/CCMotionStreak.h b/cocos/2d/CCMotionStreak.h index c0fc986c73..ec454b0abc 100644 --- a/cocos/2d/CCMotionStreak.h +++ b/cocos/2d/CCMotionStreak.h @@ -53,20 +53,6 @@ public: static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const char* 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); - /** - * @js ctor - */ - MotionStreak(); - /** - * @js NA - * @lua NA - */ - 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); - /** 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); /** color used for the tint */ void tintWithColor(const Color3B& colors); @@ -114,9 +100,24 @@ public: virtual bool isOpacityModifyRGB() const override; protected: + /** + * @js ctor + */ + MotionStreak(); + /** + * @js NA + * @lua NA + */ + 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); + /** 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); + bool _fastMode; bool _startingPositionInitialized; -private: + /** texture used for the motion streak */ Texture2D* _texture; BlendFunc _blendFunc; @@ -138,6 +139,9 @@ private: Vertex2F* _vertices; GLubyte* _colorPointer; Tex2F* _texCoords; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MotionStreak); }; // end of misc_nodes group diff --git a/cocos/2d/CCParallaxNode.h b/cocos/2d/CCParallaxNode.h index 36c3a192a9..e7770d7282 100644 --- a/cocos/2d/CCParallaxNode.h +++ b/cocos/2d/CCParallaxNode.h @@ -48,18 +48,6 @@ class CC_DLL ParallaxNode : public Node public: // Create a Parallax node static ParallaxNode * create(); - - /** Adds a child to the container with a z-order, a parallax ratio and a position offset - It returns self, so you can chain several addChilds. - @since v0.8 - * @js ctor - */ - ParallaxNode(); - /** - * @js NA - * @lua NA - */ - virtual ~ParallaxNode(); // prevents compiler warning: "Included function hides overloaded virtual functions" using Node::addChild; @@ -81,10 +69,25 @@ public: virtual void visit(void) override; protected: + /** Adds a child to the container with a z-order, a parallax ratio and a position offset + It returns self, so you can chain several addChilds. + @since v0.8 + * @js ctor + */ + ParallaxNode(); + /** + * @js NA + * @lua NA + */ + virtual ~ParallaxNode(); + Point absolutePosition(); Point _lastPosition; struct _ccArray* _parallaxArray; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParallaxNode); }; // end of tilemap_parallax_nodes group diff --git a/cocos/2d/CCProgressTimer.h b/cocos/2d/CCProgressTimer.h index e09e34be0f..04c4e55246 100644 --- a/cocos/2d/CCProgressTimer.h +++ b/cocos/2d/CCProgressTimer.h @@ -62,18 +62,6 @@ public: /** Creates a progress timer with the sprite as the shape the timer goes through */ static ProgressTimer* create(Sprite* sp); - /** - * @js ctor - */ - ProgressTimer(); - /** - * @js NA - * @lua NA - */ - virtual ~ProgressTimer(); - - /** Initializes a progress timer with the sprite as the shape the timer goes through */ - bool initWithSprite(Sprite* sp); /** Change the percentage to change progress. */ inline Type getType() const { return _type; } @@ -129,6 +117,19 @@ public: virtual void setOpacity(GLubyte opacity) override; protected: + /** + * @js ctor + */ + ProgressTimer(); + /** + * @js NA + * @lua NA + */ + virtual ~ProgressTimer(); + + /** Initializes a progress timer with the sprite as the shape the timer goes through */ + bool initWithSprite(Sprite* sp); + Tex2F textureCoordFromAlphaPoint(Point alpha); Vertex2F vertexFromAlphaPoint(Point alpha); void updateProgress(void); @@ -146,6 +147,9 @@ protected: V2F_C4B_T2F *_vertexData; bool _reverseDirection; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ProgressTimer); }; // end of misc_nodes group diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 5318e83fdf..04d30dd4dc 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -58,21 +58,6 @@ public: /** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */ static RenderTexture * create(int w, int h); - /** - * @js ctor - */ - RenderTexture(); - /** - * @js NA - * @lua NA - */ - virtual ~RenderTexture(); - - /** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ - bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat); - - /** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format*/ - bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat); /** starts grabbing */ void begin(); @@ -167,10 +152,25 @@ public: virtual void visit() override; virtual void draw() override; -private: +protected: + /** + * @js ctor + */ + RenderTexture(); + /** + * @js NA + * @lua NA + */ + virtual ~RenderTexture(); + + /** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ + bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat); + + /** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format*/ + bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat); + void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); -protected: GLuint _FBO; GLuint _depthRenderBufffer; GLint _oldFBO; @@ -192,6 +192,10 @@ protected: - [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; */ Sprite* _sprite; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(RenderTexture); + }; // end of textures group diff --git a/cocos/2d/CCTMXTiledMap.h b/cocos/2d/CCTMXTiledMap.h index f870938174..7148711e56 100644 --- a/cocos/2d/CCTMXTiledMap.h +++ b/cocos/2d/CCTMXTiledMap.h @@ -109,28 +109,12 @@ object->getProperty(name_of_the_property); class CC_DLL TMXTiledMap : public Node { public: - /** - * @js ctor - */ - TMXTiledMap(); - /** - * @js NA - * @lua NA - */ - virtual ~TMXTiledMap(); - /** creates a TMX Tiled Map with a TMX file.*/ static TMXTiledMap* create(const std::string& tmxFile); /** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */ static TMXTiledMap* createWithXML(const std::string& tmxString, const std::string& resourcePath); - /** initializes a TMX Tiled Map with a TMX file */ - bool initWithTMXFile(const std::string& tmxFile); - - /** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */ - bool initWithXML(const std::string& tmxString, const std::string& resourcePath); - /** return the TMXLayer for the specific layer */ TMXLayer* getLayer(const std::string& layerName) const; /** @@ -187,11 +171,27 @@ public: _properties = properties; }; -private: +protected: + /** + * @js ctor + */ + TMXTiledMap(); + /** + * @js NA + * @lua NA + */ + virtual ~TMXTiledMap(); + + /** initializes a TMX Tiled Map with a TMX file */ + bool initWithTMXFile(const std::string& tmxFile); + + /** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */ + bool initWithXML(const std::string& tmxString, const std::string& resourcePath); + TMXLayer * parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo); TMXTilesetInfo * tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo); void buildWithMapInfo(TMXMapInfo* mapInfo); -protected: + /** the map's size property measured in tiles */ Size _mapSize; /** the tiles's size property measured in pixels */ @@ -206,6 +206,9 @@ protected: //! tile properties Dictionary* _tileProperties; +private: + CC_DISALLOW_COPY_AND_ASSIGN(TMXTiledMap); + }; // end of tilemap_parallax_nodes group diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index d305c0382b..ff4edc2b0a 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -568,7 +568,7 @@ string RenderTextureTargetNode::subtitle() // SpriteRenderTextureBug -SpriteRenderTextureBug::SimpleSprite::SimpleSprite() : rt(NULL) {} +SpriteRenderTextureBug::SimpleSprite::SimpleSprite() : _rt(nullptr) {} SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::create(const char* filename, const Rect &rect) { @@ -587,14 +587,14 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea void SpriteRenderTextureBug::SimpleSprite::draw() { - if (rt == NULL) + if (_rt == nullptr) { auto s = Director::getInstance()->getWinSize(); - rt = new RenderTexture(); - rt->initWithWidthAndHeight(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _rt = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _rt->retain(); } - rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); - rt->end(); + _rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); + _rt->end(); CC_NODE_DRAW_SETUP(); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index cedf516f3f..47fde11c59 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -115,7 +115,7 @@ public: public: - RenderTexture *rt; + RenderTexture *_rt; }; public: From a583ad461f11c50723a17515421e092abc9f270a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 14 Nov 2013 17:19:16 -0800 Subject: [PATCH 08/28] CCControlButton has protected constructor --- cocos/2d/CCAnimation.cpp | 2 +- cocos/2d/CCAnimation.h | 4 +- cocos/2d/CCLabelBMFont.cpp | 8 ++-- cocos/2d/CCLabelBMFont.h | 4 +- cocos/2d/CCParticleBatchNode.cpp | 8 ++-- cocos/2d/CCParticleBatchNode.h | 8 ++-- cocos/2d/CCRenderTexture.cpp | 6 +-- cocos/2d/CCRenderTexture.h | 4 +- cocos/2d/platform/CCImage.h | 6 +-- cocos/2d/platform/CCImageCommon_cpp.h | 26 +++++------- cocos/2d/platform/ios/CCImage.mm | 4 +- .../CCControlExtension/CCControlButton.cpp | 24 +++++------ .../GUI/CCControlExtension/CCControlButton.h | 40 ++++++++++--------- 13 files changed, 70 insertions(+), 74 deletions(-) diff --git a/cocos/2d/CCAnimation.cpp b/cocos/2d/CCAnimation.cpp index ca1c949882..fad60c6533 100644 --- a/cocos/2d/CCAnimation.cpp +++ b/cocos/2d/CCAnimation.cpp @@ -175,7 +175,7 @@ void Animation::addSpriteFrame(SpriteFrame *pFrame) _totalDelayUnits++; } -void Animation::addSpriteFrameWithFile(const char *filename) +void Animation::addSpriteFrameWithFile(const std::string& filename) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); Rect rect = Rect::ZERO; diff --git a/cocos/2d/CCAnimation.h b/cocos/2d/CCAnimation.h index cc38ca6d84..13cf3b1fdc 100644 --- a/cocos/2d/CCAnimation.h +++ b/cocos/2d/CCAnimation.h @@ -173,11 +173,11 @@ public: The frame will be added with one "delay unit". Added to facilitate the migration from v0.8 to v0.9. */ - void addSpriteFrameWithFile(const char *filename); + void addSpriteFrameWithFile(const std::string& filename); /** @deprecated. Use addSpriteFrameWithFile() instead */ - CC_DEPRECATED_ATTRIBUTE void addSpriteFrameWithFileName(const char *filename){ addSpriteFrameWithFile(filename);} + CC_DEPRECATED_ATTRIBUTE void addSpriteFrameWithFileName(const std::string& filename){ addSpriteFrameWithFile(filename);} /** Adds a frame with a texture and a rect. Internally it will create a SpriteFrame and it will add it. The frame will be added with one "delay unit". diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index a6c416eb50..88fb154770 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -1197,9 +1197,9 @@ float LabelBMFont::getLetterPosXRight( Sprite* sp ) } // LabelBMFont - FntFile -void LabelBMFont::setFntFile(const char* fntFile) +void LabelBMFont::setFntFile(const std::string& fntFile) { - if (fntFile != NULL && strcmp(fntFile, _fntFile.c_str()) != 0 ) + if (_fntFile.compare(fntFile) != 0) { CCBMFontConfiguration *newConf = FNTConfigLoadFile(fntFile); @@ -1216,9 +1216,9 @@ void LabelBMFont::setFntFile(const char* fntFile) } } -const char* LabelBMFont::getFntFile() +const std::string& LabelBMFont::getFntFile() const { - return _fntFile.c_str(); + return _fntFile; } diff --git a/cocos/2d/CCLabelBMFont.h b/cocos/2d/CCLabelBMFont.h index a825d28ed6..41bd2c46bc 100644 --- a/cocos/2d/CCLabelBMFont.h +++ b/cocos/2d/CCLabelBMFont.h @@ -258,8 +258,8 @@ public: virtual bool isCascadeColorEnabled() const; virtual void setCascadeColorEnabled(bool cascadeColorEnabled); - void setFntFile(const char* fntFile); - const char* getFntFile(); + void setFntFile(const std::string& fntFile); + const std::string& getFntFile() const; #if CC_LABELBMFONT_DEBUG_DRAW virtual void draw(); #endif // CC_LABELBMFONT_DEBUG_DRAW diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index cd473bf097..0d1eccae48 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -59,7 +59,7 @@ ParticleBatchNode::~ParticleBatchNode() * creation with Texture2D */ -ParticleBatchNode* ParticleBatchNode::createWithTexture(Texture2D *tex, unsigned int capacity/* = kParticleDefaultCapacity*/) +ParticleBatchNode* ParticleBatchNode::createWithTexture(Texture2D *tex, int capacity/* = kParticleDefaultCapacity*/) { ParticleBatchNode * p = new ParticleBatchNode(); if( p && p->initWithTexture(tex, capacity)) @@ -75,7 +75,7 @@ ParticleBatchNode* ParticleBatchNode::createWithTexture(Texture2D *tex, unsigned * creation with File Image */ -ParticleBatchNode* ParticleBatchNode::create(const char* imageFile, unsigned int capacity/* = kParticleDefaultCapacity*/) +ParticleBatchNode* ParticleBatchNode::create(const std::string& imageFile, int capacity/* = kParticleDefaultCapacity*/) { ParticleBatchNode * p = new ParticleBatchNode(); if( p && p->initWithFile(imageFile, capacity)) @@ -90,7 +90,7 @@ ParticleBatchNode* ParticleBatchNode::create(const char* imageFile, unsigned int /* * init with Texture2D */ -bool ParticleBatchNode::initWithTexture(Texture2D *tex, unsigned int capacity) +bool ParticleBatchNode::initWithTexture(Texture2D *tex, int capacity) { _textureAtlas = new TextureAtlas(); _textureAtlas->initWithTexture(tex, capacity); @@ -109,7 +109,7 @@ bool ParticleBatchNode::initWithTexture(Texture2D *tex, unsigned int capacity) /* * init with FileImage */ -bool ParticleBatchNode::initWithFile(const char* fileImage, unsigned int capacity) +bool ParticleBatchNode::initWithFile(const std::string& fileImage, int capacity) { Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(fileImage); return initWithTexture(tex, capacity); diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index 9b5808be45..937c348500 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -68,10 +68,10 @@ class CC_DLL ParticleBatchNode : public Node, public TextureProtocol { public: /** initializes the particle system with Texture2D, a capacity of particles, which particle system to use */ - static ParticleBatchNode* createWithTexture(Texture2D *tex, unsigned int capacity = kParticleDefaultCapacity); + static ParticleBatchNode* createWithTexture(Texture2D *tex, int capacity = kParticleDefaultCapacity); /** initializes the particle system with the name of a file on disk (for a list of supported formats look at the Texture2D class), a capacity of particles */ - static ParticleBatchNode* create(const char* fileImage, unsigned int capacity = kParticleDefaultCapacity); + static ParticleBatchNode* create(const std::string& fileImage, int capacity = kParticleDefaultCapacity); /** * @js ctor */ @@ -83,10 +83,10 @@ public: virtual ~ParticleBatchNode(); /** initializes the particle system with Texture2D, a capacity of particles */ - bool initWithTexture(Texture2D *tex, unsigned int capacity); + bool initWithTexture(Texture2D *tex, int capacity); /** initializes the particle system with the name of a file on disk (for a list of supported formats look at the Texture2D class), a capacity of particles */ - bool initWithFile(const char* fileImage, unsigned int capacity); + bool initWithFile(const std::string& fileImage, int capacity); /** Inserts a child into the ParticleBatchNode */ void insertChild(ParticleSystem* system, int index); diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 8fa56c282d..a35a564f85 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -543,20 +543,20 @@ void RenderTexture::draw() } } -bool RenderTexture::saveToFile(const char *szFilePath) +bool RenderTexture::saveToFile(const std::string& filename) { bool ret = false; Image *image = newImage(true); if (image) { - ret = image->saveToFile(szFilePath); + ret = image->saveToFile(filename); } CC_SAFE_DELETE(image); return ret; } -bool RenderTexture::saveToFile(const char *fileName, Image::Format format) +bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format) { bool bRet = false; CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 04d30dd4dc..90b2ba1784 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -99,12 +99,12 @@ public: /** saves the texture into a file using JPEG format. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const char *szFilePath); + bool saveToFile(const std::string& filename); /** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const char *name, Image::Format format); + bool saveToFile(const std::string& filename, Image::Format format); /** Listen "come to background" message, and save render texture. It only has effect on Android. diff --git a/cocos/2d/platform/CCImage.h b/cocos/2d/platform/CCImage.h index 1f2e04ced7..781689f238 100644 --- a/cocos/2d/platform/CCImage.h +++ b/cocos/2d/platform/CCImage.h @@ -193,7 +193,7 @@ public: @param filePath the file's absolute path, including file suffix. @param isToRGB whether the image is saved as RGB format. */ - bool saveToFile(const char *filePath, bool isToRGB = true); + bool saveToFile(const std::string &filename, bool isToRGB = true); protected: bool initWithJpgData(const unsigned char * data, int dataLen); @@ -207,8 +207,8 @@ protected: bool initWithS3TCData(const unsigned char * data, int dataLen); bool initWithATITCData(const unsigned char *data, int dataLen); - bool saveImageToPNG(const char *filePath, bool isToRGB = true); - bool saveImageToJPG(const char *filePath); + bool saveImageToPNG(const std::string& filePath, bool isToRGB = true); + bool saveImageToJPG(const std::string& filePath); private: /** diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index 09b73ea421..eca8c685cc 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -1784,7 +1784,7 @@ bool Image::initWithRawData(const unsigned char * data, long dataLen, long width #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) -bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) +bool Image::saveToFile(const std::string& filename, bool bIsToRGB) { //only support for Texture2D::PixelFormat::RGB888 or Texture2D::PixelFormat::RGBA8888 uncompressed data if (isCompressed() || (_renderFormat != Texture2D::PixelFormat::RGB888 && _renderFormat != Texture2D::PixelFormat::RGBA8888)) @@ -1801,24 +1801,22 @@ bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) do { - CC_BREAK_IF(NULL == pszFilePath); - std::string strFilePath(pszFilePath); - CC_BREAK_IF(strFilePath.size() <= 4); + CC_BREAK_IF(filename.size() <= 4); - std::string strLowerCasePath(strFilePath); + std::string strLowerCasePath(filename); for (unsigned int i = 0; i < strLowerCasePath.length(); ++i) { - strLowerCasePath[i] = tolower(strFilePath[i]); + strLowerCasePath[i] = tolower(filename[i]); } if (std::string::npos != strLowerCasePath.find(".png")) { - CC_BREAK_IF(!saveImageToPNG(pszFilePath, bIsToRGB)); + CC_BREAK_IF(!saveImageToPNG(filename, bIsToRGB)); } else if (std::string::npos != strLowerCasePath.find(".jpg")) { - CC_BREAK_IF(!saveImageToJPG(pszFilePath)); + CC_BREAK_IF(!saveImageToJPG(filename)); } else { @@ -1833,20 +1831,18 @@ bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) } #endif -bool Image::saveImageToPNG(const char * filePath, bool isToRGB) +bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) { bool bRet = false; do { - CC_BREAK_IF(NULL == filePath); - FILE *fp; png_structp png_ptr; png_infop info_ptr; png_colorp palette; png_bytep *row_pointers; - fp = fopen(filePath, "wb"); + fp = fopen(filePath.c_str(), "wb"); CC_BREAK_IF(NULL == fp); png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -1973,13 +1969,11 @@ bool Image::saveImageToPNG(const char * filePath, bool isToRGB) } while (0); return bRet; } -bool Image::saveImageToJPG(const char * filePath) +bool Image::saveImageToJPG(const std::string& filePath) { bool bRet = false; do { - CC_BREAK_IF(NULL == filePath); - struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE * outfile; /* target file */ @@ -1990,7 +1984,7 @@ bool Image::saveImageToJPG(const char * filePath) /* Now we can initialize the JPEG compression object. */ jpeg_create_compress(&cinfo); - CC_BREAK_IF((outfile = fopen(filePath, "wb")) == NULL); + CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == NULL); jpeg_stdio_dest(&cinfo, outfile); diff --git a/cocos/2d/platform/ios/CCImage.mm b/cocos/2d/platform/ios/CCImage.mm index 556a4abcba..ff902b6bb5 100644 --- a/cocos/2d/platform/ios/CCImage.mm +++ b/cocos/2d/platform/ios/CCImage.mm @@ -380,11 +380,11 @@ bool Image::initWithStringShadowStroke( return true; } -bool Image::saveToFile(const char *pszFilePath, bool bIsToRGB) +bool Image::saveToFile(const std::string& filename, bool bIsToRGB) { bool saveToPNG = false; bool needToCopyPixels = false; - std::string filePath(pszFilePath); + if (std::string::npos != filePath.find(".png")) { saveToPNG = true; diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index e747dfe24c..db18da4cdd 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -388,7 +388,7 @@ void ControlButton::setTitleLabelForState(Node* titleLabel, State state) } } -void ControlButton::setTitleTTFForState(const char * fntFile, State state) +void ControlButton::setTitleTTFForState(const std::string& fntFile, State state) { String * title = this->getTitleForState(state); if (!title) @@ -398,18 +398,17 @@ void ControlButton::setTitleTTFForState(const char * fntFile, State state) this->setTitleLabelForState(LabelTTF::create(title->getCString(), fntFile, 12), state); } -const char * ControlButton::getTitleTTFForState(State state) +const std::string& ControlButton::getTitleTTFForState(State state) { LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); LabelTTF* labelTTF = dynamic_cast(label); if(labelTTF != 0) { - return labelTTF->getFontName().c_str(); - } - else - { - return ""; + return labelTTF->getFontName(); } + + static std::string ret(""); + return ret; } void ControlButton::setTitleTTFSizeForState(float size, State state) @@ -439,7 +438,7 @@ float ControlButton::getTitleTTFSizeForState(State state) } } -void ControlButton::setTitleBMFontForState(const char * fntFile, State state) +void ControlButton::setTitleBMFontForState(const std::string& fntFile, State state) { String * title = this->getTitleForState(state); if (!title) @@ -449,7 +448,7 @@ void ControlButton::setTitleBMFontForState(const char * fntFile, State state) this->setTitleLabelForState(LabelBMFont::create(title->getCString(), fntFile), state); } -const char * ControlButton::getTitleBMFontForState(State state) +const std::string& ControlButton::getTitleBMFontForState(State state) { LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); LabelBMFont* labelBMFont = dynamic_cast(label); @@ -457,10 +456,9 @@ const char * ControlButton::getTitleBMFontForState(State state) { return labelBMFont->getFntFile(); } - else - { - return ""; - } + + static std::string ret(""); + return ret; } diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 5a30c64f4c..1da0d5c74d 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -57,20 +57,6 @@ public: static ControlButton* create(Scale9Sprite* sprite); static ControlButton* create(Node* label, Scale9Sprite* backgroundSprite); static ControlButton* create(std::string title, const char * fontName, float fontSize); - /** - * @js ctor - */ - ControlButton(); - /** - * @js NA - * @lua NA - */ - virtual ~ControlButton(); - - virtual bool init(); - virtual bool initWithLabelAndBackgroundSprite(Node* label, Scale9Sprite* backgroundSprite); - virtual bool initWithBackgroundSprite(Scale9Sprite* sprite); - virtual bool initWithTitleAndFontNameAndFontSize(std::string title, const char * fontName, float fontSize); virtual void needsLayout(void); @@ -140,8 +126,8 @@ public: */ virtual void setTitleLabelForState(Node* label, State state); - virtual void setTitleTTFForState(const char * fntFile, State state); - virtual const char * getTitleTTFForState(State state); + virtual void setTitleTTFForState(const std::string& fntFile, State state); + virtual const std::string& getTitleTTFForState(State state); virtual void setTitleTTFSizeForState(float size, State state); virtual float getTitleTTFSizeForState(State state); @@ -152,8 +138,8 @@ public: * @param state The state that uses the specified fntFile. The values are described * in "CCControlState". */ - virtual void setTitleBMFontForState(const char * fntFile, State state); - virtual const char * getTitleBMFontForState(State state); + virtual void setTitleBMFontForState(const std::string& fntFile, State state); + virtual const std::string& getTitleBMFontForState(State state); /** * Returns the background sprite used for a state. @@ -209,6 +195,21 @@ public: void setAdjustBackgroundImage(bool adjustBackgroundImage); protected: + /** + * @js ctor + */ + ControlButton(); + /** + * @js NA + * @lua NA + */ + virtual ~ControlButton(); + + virtual bool init(); + virtual bool initWithLabelAndBackgroundSprite(Node* label, Scale9Sprite* backgroundSprite); + virtual bool initWithBackgroundSprite(Scale9Sprite* sprite); + virtual bool initWithTitleAndFontNameAndFontSize(std::string title, const char * fontName, float fontSize); + bool _isPushed; bool _parentInited; bool _doesAdjustBackgroundImage; @@ -246,6 +247,9 @@ protected: CC_SYNTHESIZE_READONLY(int, _marginV, VerticalMargin); /* Define the button margin for Left/Right edge */ CC_SYNTHESIZE_READONLY(int, _marginH, HorizontalOrigin); + +protected: + CC_DISALLOW_COPY_AND_ASSIGN(ControlButton); }; // end of GUI group From 208d25bdff9179f18ee62de730942d795c109233 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 15 Nov 2013 12:04:47 -0800 Subject: [PATCH 09/28] ControlSwitch compies Uses procted constructor --- cocos/2d/CCActionTween.cpp | 4 +- cocos/2d/CCActionTween.h | 6 +- cocos/2d/platform/ios/CCImage.mm | 4 +- .../CCControlExtension/CCControlSwitch.cpp | 92 ++++++++++++------- 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/cocos/2d/CCActionTween.cpp b/cocos/2d/CCActionTween.cpp index bd615eb599..67a4f3ce38 100644 --- a/cocos/2d/CCActionTween.cpp +++ b/cocos/2d/CCActionTween.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. NS_CC_BEGIN -ActionTween* ActionTween::create(float aDuration, const char* key, float from, float to) +ActionTween* ActionTween::create(float aDuration, const std::string& key, float from, float to) { ActionTween* pRet = new ActionTween(); if (pRet && pRet->initWithDuration(aDuration, key, from, to)) @@ -41,7 +41,7 @@ ActionTween* ActionTween::create(float aDuration, const char* key, float from, f return pRet; } -bool ActionTween::initWithDuration(float aDuration, const char* key, float from, float to) +bool ActionTween::initWithDuration(float aDuration, const std::string& key, float from, float to) { if (ActionInterval::initWithDuration(aDuration)) { diff --git a/cocos/2d/CCActionTween.h b/cocos/2d/CCActionTween.h index 2ed389d810..b5c1553f31 100644 --- a/cocos/2d/CCActionTween.h +++ b/cocos/2d/CCActionTween.h @@ -42,7 +42,7 @@ public: * @lua NA */ virtual ~ActionTweenDelegate() {} - virtual void updateTweenAction(float value, const char* key) = 0; + virtual void updateTweenAction(float value, const std::string& key) = 0; }; /** ActionTween @@ -69,9 +69,9 @@ class CC_DLL ActionTween : public ActionInterval { public: /** creates an initializes the action with the property name (key), and the from and to parameters. */ - static ActionTween* create(float duration, const char* key, float from, float to); + static ActionTween* create(float duration, const std::string& key, float from, float to); /** initializes the action with the property name (key), and the from and to parameters. */ - bool initWithDuration(float duration, const char* key, float from, float to); + bool initWithDuration(float duration, const std::string& key, float from, float to); // Overrides void startWithTarget(Node *target) override; diff --git a/cocos/2d/platform/ios/CCImage.mm b/cocos/2d/platform/ios/CCImage.mm index ff902b6bb5..2d65540a71 100644 --- a/cocos/2d/platform/ios/CCImage.mm +++ b/cocos/2d/platform/ios/CCImage.mm @@ -385,7 +385,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) bool saveToPNG = false; bool needToCopyPixels = false; - if (std::string::npos != filePath.find(".png")) + if (std::string::npos != filename.find(".png")) { saveToPNG = true; } @@ -453,7 +453,7 @@ bool Image::saveToFile(const std::string& filename, bool bIsToRGB) data = UIImageJPEGRepresentation(image, 1.0f); } - [data writeToFile:[NSString stringWithUTF8String:pszFilePath] atomically:YES]; + [data writeToFile:[NSString stringWithUTF8String:filename.c_str()] atomically:YES]; [image release]; diff --git a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp index fe67a3f905..8a7d046593 100644 --- a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp +++ b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp @@ -34,32 +34,20 @@ NS_CC_EXT_BEGIN class ControlSwitchSprite : public Sprite, public ActionTweenDelegate { public: + /** creates an autorelease instance of ControlSwitchSprite */ + static ControlSwitchSprite* createWithMaskSprite( + Sprite *maskSprite, + Sprite *onSprite, + Sprite *offSprite, + Sprite *thumbSprite, + LabelTTF* onLabel, + LabelTTF* offLabel); + /** * @js NA * @lua NA */ - ControlSwitchSprite(); - /** - * @js NA - * @lua NA - */ - virtual ~ControlSwitchSprite(); - /** - * @js NA - * @lua NA - */ - bool initWithMaskSprite( - Sprite *maskSprite, - Sprite *onSprite, - Sprite *offSprite, - Sprite *thumbSprite, - LabelTTF* onLabel, - LabelTTF* offLabel); - /** - * @js NA - * @lua NA - */ - void draw(); + void draw() override; /** * @js NA * @lua NA @@ -89,7 +77,8 @@ public: * @js NA * @lua NA */ - virtual void updateTweenAction(float value, const char* key); + virtual void updateTweenAction(float value, const std::string& key) override; + /** Contains the position (in x-axis) of the slider inside the receiver. */ float _sliderXPosition; CC_SYNTHESIZE(float, _onPosition, OnPosition) @@ -104,8 +93,47 @@ public: CC_SYNTHESIZE_RETAIN(Sprite*, _thumbSprite, ThumbSprite) CC_SYNTHESIZE_RETAIN(LabelTTF*, _onLabel, OnLabel) CC_SYNTHESIZE_RETAIN(LabelTTF*, _offLabel, OffLabel) + +protected: + /** + * @js NA + * @lua NA + */ + ControlSwitchSprite(); + /** + * @js NA + * @lua NA + */ + virtual ~ControlSwitchSprite(); + /** + * @js NA + * @lua NA + */ + bool initWithMaskSprite( + Sprite *maskSprite, + Sprite *onSprite, + Sprite *offSprite, + Sprite *thumbSprite, + LabelTTF* onLabel, + LabelTTF* offLabel); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ControlSwitchSprite); }; +ControlSwitchSprite* ControlSwitchSprite::createWithMaskSprite(Sprite *maskSprite, + Sprite *onSprite, + Sprite *offSprite, + Sprite *thumbSprite, + LabelTTF* onLabel, + LabelTTF* offLabel) +{ + auto ret = new ControlSwitchSprite(); + ret->initWithMaskSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel); + ret->autorelease(); + return ret; +} + ControlSwitchSprite::ControlSwitchSprite() : _sliderXPosition(0.0f) , _onPosition(0.0f) @@ -187,9 +215,9 @@ bool ControlSwitchSprite::initWithMaskSprite( return false; } -void ControlSwitchSprite::updateTweenAction(float value, const char* key) +void ControlSwitchSprite::updateTweenAction(float value, const std::string& key) { - CCLOG("key = %s, value = %f", key, value); + CCLOG("key = %s, value = %f", key.c_str(), value); setSliderXPosition(value); } @@ -348,13 +376,13 @@ bool ControlSwitch::initWithMaskSprite(Sprite *maskSprite, Sprite * onSprite, Sp _on = true; - _switchSprite = new ControlSwitchSprite(); - _switchSprite->initWithMaskSprite(maskSprite, - onSprite, - offSprite, - thumbSprite, - onLabel, - offLabel); + _switchSprite = ControlSwitchSprite::createWithMaskSprite(maskSprite, + onSprite, + offSprite, + thumbSprite, + onLabel, + offLabel); + _switchSprite->retain(); _switchSprite->setPosition(Point(_switchSprite->getContentSize().width / 2, _switchSprite->getContentSize().height / 2)); addChild(_switchSprite); From 7c2ed2743ce9389990342a15c4e3d25a8aa91d73 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 15 Nov 2013 13:14:12 -0800 Subject: [PATCH 10/28] Menu + MenuItem `Menu` and `MenuItem` have protected constructors --- cocos/2d/CCMenu.h | 26 +- cocos/2d/CCMenuItem.h | 243 ++++++++++-------- cocos/2d/CCParticleExamples.cpp | 44 ++-- cocos/2d/CCParticleExamples.h | 134 ++++++---- .../cocostudio/CCActionObject.cpp | 4 +- .../Classes/ParticleTest/ParticleTest.cpp | 6 +- 6 files changed, 269 insertions(+), 188 deletions(-) diff --git a/cocos/2d/CCMenu.h b/cocos/2d/CCMenu.h index 64c275841a..04aeb831a4 100644 --- a/cocos/2d/CCMenu.h +++ b/cocos/2d/CCMenu.h @@ -73,17 +73,6 @@ public: /** creates a Menu with MenuItem objects */ static Menu* createWithItems(MenuItem *firstItem, va_list args); - /** - * @js ctor - */ - Menu() : _selectedItem(NULL) {} - virtual ~Menu(); - - /** initializes an empty Menu */ - bool init(); - - /** initializes a Menu with a NSArray of MenuItem objects */ - bool initWithArray(Array* pArrayOfItems); /** align items vertically */ void alignItemsVertically(); @@ -130,12 +119,27 @@ public: virtual bool isOpacityModifyRGB(void) const override { return false;} protected: + /** + * @js ctor + */ + Menu() : _selectedItem(NULL) {} + virtual ~Menu(); + + /** initializes an empty Menu */ + bool init(); + + /** initializes a Menu with a NSArray of MenuItem objects */ + bool initWithArray(Array* pArrayOfItems); + /** whether or not the menu will receive events */ bool _enabled; MenuItem* itemForTouch(Touch * touch); State _state; MenuItem *_selectedItem; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Menu); }; // end of GUI group diff --git a/cocos/2d/CCMenuItem.h b/cocos/2d/CCMenuItem.h index d0fcda9a50..fb44773d27 100644 --- a/cocos/2d/CCMenuItem.h +++ b/cocos/2d/CCMenuItem.h @@ -65,31 +65,6 @@ public: CC_DEPRECATED_ATTRIBUTE static MenuItem* create(Object *rec, SEL_MenuHandler selector); /** Creates a MenuItem with a target/selector */ static MenuItem* create(const ccMenuCallback& callback); - /** - * @js ctor - */ - MenuItem() - : _selected(false) - , _enabled(false) - , _callback(nullptr) - , _target(NULL) - {} - /** - * @js NA - * @lua NA - */ - virtual ~MenuItem(); - - /** Initializes a MenuItem with a target/selector - * @js NA - * @lua NA - */ - bool initWithCallback(const ccMenuCallback& callback); - /** Initializes a MenuItem with a target/selector - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE bool initWithTarget( Object *rec, SEL_MenuHandler selector); /** Returns the outside box */ Rect rect() const; @@ -120,12 +95,41 @@ public: CC_DEPRECATED_ATTRIBUTE void setTarget(Object *rec, SEL_MenuHandler selector); protected: + /** + * @js ctor + */ + MenuItem() + : _selected(false) + , _enabled(false) + , _callback(nullptr) + , _target(NULL) + {} + /** + * @js NA + * @lua NA + */ + virtual ~MenuItem(); + + /** Initializes a MenuItem with a target/selector + * @js NA + * @lua NA + */ + bool initWithCallback(const ccMenuCallback& callback); + /** Initializes a MenuItem with a target/selector + * @js NA + * @lua NA + */ + CC_DEPRECATED_ATTRIBUTE bool initWithTarget( Object *rec, SEL_MenuHandler selector); + bool _selected; bool _enabled; // callback ccMenuCallback _callback; // If using the old API, the _target needs to be retained / released Object *_target; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItem); }; /** @brief An abstract class for "label" MenuItemLabel items @@ -146,24 +150,6 @@ public: /** creates a MenuItemLabel with a Label. Target and selector will be nil */ static MenuItemLabel* create(Node *label); - /** - * @js ctor - */ - MenuItemLabel() - : _originalScale(0.0) - , _label(NULL) - {} - /** - * @js NA - * @lua NA - */ - virtual ~MenuItemLabel(); - - /** initializes a MenuItemLabel with a Label, target and selector */ - bool initWithLabel(Node* label, const ccMenuCallback& callback); - - /** initializes a MenuItemLabel with a Label, target and selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithLabel(Node* label, Object* target, SEL_MenuHandler selector); /** sets a new string to the inner label */ void setString(const std::string& label); @@ -187,6 +173,25 @@ public: virtual void setEnabled(bool enabled) override; protected: + /** + * @js ctor + */ + MenuItemLabel() + : _originalScale(0.0) + , _label(NULL) + {} + /** + * @js NA + * @lua NA + */ + virtual ~MenuItemLabel(); + + /** initializes a MenuItemLabel with a Label, target and selector */ + bool initWithLabel(Node* label, const ccMenuCallback& callback); + + /** initializes a MenuItemLabel with a Label, target and selector */ + CC_DEPRECATED_ATTRIBUTE bool initWithLabel(Node* label, Object* target, SEL_MenuHandler selector); + Color3B _colorBackup; float _originalScale; @@ -194,6 +199,9 @@ protected: Color3B _disabledColor; /** Label that is rendered. It can be any Node that implements the LabelProtocol */ Node* _label; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemLabel); }; @@ -209,6 +217,8 @@ public: CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, long itemWidth, long 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, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback); + +protected: /** * @js ctor */ @@ -223,6 +233,9 @@ public: CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, long itemWidth, long 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, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemAtlasFont); }; @@ -238,20 +251,6 @@ public: CC_DEPRECATED_ATTRIBUTE static MenuItemFont * create(const char *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); - /** - * @js ctor - */ - MenuItemFont(); - /** - * @js NA - * @lua NA - */ - 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); - /** initializes a menu item from a string with a target/selector */ - bool initWithString(const std::string& value, const ccMenuCallback& callback); /** set default font size */ static void setFontSize(long size); @@ -293,10 +292,28 @@ public: CC_DEPRECATED_ATTRIBUTE const std::string& fontNameObj() const { return getFontNameObj(); } protected: + /** + * @js ctor + */ + MenuItemFont(); + /** + * @js NA + * @lua NA + */ + 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); + /** initializes a menu item from a string with a target/selector */ + bool initWithString(const std::string& value, const ccMenuCallback& callback); + void recreateLabel(); long _fontSize; std::string _fontName; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemFont); }; @@ -322,17 +339,6 @@ public: /** creates a menu item with a normal,selected and disabled image with target/selector */ static MenuItemSprite * create(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback); - MenuItemSprite() - :_normalImage(NULL) - ,_selectedImage(NULL) - ,_disabledImage(NULL) - {} - - /** initializes a menu item with a normal, selected and disabled image with target/selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Object* target, SEL_MenuHandler selector); - /** initializes a menu item with a normal, selected and disabled image with a callable object */ - bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback); - /** Gets the image used when the item is not selected */ inline Node* getNormalImage() const { return _normalImage; }; @@ -359,6 +365,17 @@ public: virtual void setEnabled(bool bEnabled); protected: + MenuItemSprite() + :_normalImage(NULL) + ,_selectedImage(NULL) + ,_disabledImage(NULL) + {} + + /** initializes a menu item with a normal, selected and disabled image with target/selector */ + CC_DEPRECATED_ATTRIBUTE bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Object* target, SEL_MenuHandler selector); + /** initializes a menu item with a normal, selected and disabled image with a callable object */ + bool initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback); + virtual void updateImagesVisibility(); /** the image used when the item is not selected */ @@ -367,6 +384,9 @@ protected: Node* _selectedImage; /** the image used when the item is disabled */ Node* _disabledImage; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemSprite); }; @@ -396,6 +416,15 @@ public: CC_DEPRECATED_ATTRIBUTE static MenuItemImage* create(const char *normalImage, const char *selectedImage, const char *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); + + /** sets the sprite frame for the normal image */ + void setNormalSpriteFrame(SpriteFrame* frame); + /** sets the sprite frame for the selected image */ + void setSelectedSpriteFrame(SpriteFrame* frame); + /** sets the sprite frame for the disabled image */ + void setDisabledSpriteFrame(SpriteFrame* frame); + +protected: /** * @js ctor */ @@ -412,12 +441,8 @@ public: /** 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); - /** sets the sprite frame for the normal image */ - void setNormalSpriteFrame(SpriteFrame* frame); - /** sets the sprite frame for the selected image */ - void setSelectedSpriteFrame(SpriteFrame* frame); - /** sets the sprite frame for the disabled image */ - void setDisabledSpriteFrame(SpriteFrame* frame); +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemImage); }; @@ -436,39 +461,6 @@ public: static MenuItemToggle* create(); /** creates a menu item with a item */ static MenuItemToggle* create(MenuItem *item); - /** creates a menu item from a Array with a target selector - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Object* target, SEL_MenuHandler selector, Array* menuItems); - /** creates a menu item from a list of items with a target/selector - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION; - /** - * @js ctor - */ - MenuItemToggle() - : _selectedIndex(0) - , _subItems(NULL) - {} - /** - * @js NA - * @lua NA - */ - virtual ~MenuItemToggle(); - - /** initializes a menu item from a list of items with a target selector - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, va_list args); - /** initializes a menu item from a list of items with a callable object */ - bool initWithCallback(const ccMenuCallback& callback, MenuItem* item, va_list args); - - /** initializes a menu item with a item */ - bool initWithItem(MenuItem *item); /** add more menu item */ void addSubItem(MenuItem *item); @@ -506,6 +498,40 @@ public: virtual void setEnabled(bool var) override; protected: + /** creates a menu item from a Array with a target selector + * @js NA + * @lua NA + */ + CC_DEPRECATED_ATTRIBUTE static MenuItemToggle * createWithTarget(Object* target, SEL_MenuHandler selector, Array* menuItems); + /** creates a menu item from a list of items with a target/selector + * @js NA + * @lua NA + */ + CC_DEPRECATED_ATTRIBUTE static MenuItemToggle* createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)CC_REQUIRES_NULL_TERMINATION; + /** + * @js ctor + */ + MenuItemToggle() + : _selectedIndex(0) + , _subItems(NULL) + {} + /** + * @js NA + * @lua NA + */ + virtual ~MenuItemToggle(); + + /** initializes a menu item from a list of items with a target selector + * @js NA + * @lua NA + */ + CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, va_list args); + /** initializes a menu item from a list of items with a callable object */ + bool initWithCallback(const ccMenuCallback& callback, MenuItem* item, va_list args); + + /** initializes a menu item with a item */ + bool initWithItem(MenuItem *item); + /** returns the selected item */ unsigned int _selectedIndex; /** Array that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one. @@ -513,6 +539,9 @@ protected: */ Array* _subItems; +private: + CC_DISALLOW_COPY_AND_ASSIGN(MenuItemToggle); + }; diff --git a/cocos/2d/CCParticleExamples.cpp b/cocos/2d/CCParticleExamples.cpp index 7120c4b821..2da24c129f 100644 --- a/cocos/2d/CCParticleExamples.cpp +++ b/cocos/2d/CCParticleExamples.cpp @@ -72,7 +72,7 @@ ParticleFire* ParticleFire::create() return pRet; } -ParticleFire* ParticleFire::createWithTotalParticles(unsigned int numberOfParticles) +ParticleFire* ParticleFire::createWithTotalParticles(int numberOfParticles) { ParticleFire* pRet = new ParticleFire(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -86,7 +86,7 @@ ParticleFire* ParticleFire::createWithTotalParticles(unsigned int numberOfPartic return pRet; } -bool ParticleFire::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleFire::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -177,7 +177,7 @@ ParticleFireworks* ParticleFireworks::create() return pRet; } -ParticleFireworks* ParticleFireworks::createWithTotalParticles(unsigned int numberOfParticles) +ParticleFireworks* ParticleFireworks::createWithTotalParticles(int numberOfParticles) { ParticleFireworks* pRet = new ParticleFireworks(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -191,7 +191,7 @@ ParticleFireworks* ParticleFireworks::createWithTotalParticles(unsigned int numb return pRet; } -bool ParticleFireworks::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleFireworks::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -278,7 +278,7 @@ ParticleSun* ParticleSun::create() return pRet; } -ParticleSun* ParticleSun::createWithTotalParticles(unsigned int numberOfParticles) +ParticleSun* ParticleSun::createWithTotalParticles(int numberOfParticles) { ParticleSun* pRet = new ParticleSun(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -292,7 +292,7 @@ ParticleSun* ParticleSun::createWithTotalParticles(unsigned int numberOfParticle return pRet; } -bool ParticleSun::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSun::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -385,7 +385,7 @@ ParticleGalaxy* ParticleGalaxy::create() return pRet; } -ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(unsigned int numberOfParticles) +ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(int numberOfParticles) { ParticleGalaxy* pRet = new ParticleGalaxy(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -399,7 +399,7 @@ ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(unsigned int numberOfPa return pRet; } -bool ParticleGalaxy::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleGalaxy::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -494,7 +494,7 @@ ParticleFlower* ParticleFlower::create() return pRet; } -ParticleFlower* ParticleFlower::createWithTotalParticles(unsigned int numberOfParticles) +ParticleFlower* ParticleFlower::createWithTotalParticles(int numberOfParticles) { ParticleFlower* pRet = new ParticleFlower(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -508,7 +508,7 @@ ParticleFlower* ParticleFlower::createWithTotalParticles(unsigned int numberOfPa return pRet; } -bool ParticleFlower::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleFlower::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -602,7 +602,7 @@ ParticleMeteor * ParticleMeteor::create() return pRet; } -ParticleMeteor* ParticleMeteor::createWithTotalParticles(unsigned int numberOfParticles) +ParticleMeteor* ParticleMeteor::createWithTotalParticles(int numberOfParticles) { ParticleMeteor* pRet = new ParticleMeteor(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -616,7 +616,7 @@ ParticleMeteor* ParticleMeteor::createWithTotalParticles(unsigned int numberOfPa return pRet; } -bool ParticleMeteor::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleMeteor::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -711,7 +711,7 @@ ParticleSpiral* ParticleSpiral::create() return pRet; } -ParticleSpiral* ParticleSpiral::createWithTotalParticles(unsigned int numberOfParticles) +ParticleSpiral* ParticleSpiral::createWithTotalParticles(int numberOfParticles) { ParticleSpiral* pRet = new ParticleSpiral(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -725,7 +725,7 @@ ParticleSpiral* ParticleSpiral::createWithTotalParticles(unsigned int numberOfPa return pRet; } -bool ParticleSpiral::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSpiral::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -820,7 +820,7 @@ ParticleExplosion* ParticleExplosion::create() return pRet; } -ParticleExplosion* ParticleExplosion::createWithTotalParticles(unsigned int numberOfParticles) +ParticleExplosion* ParticleExplosion::createWithTotalParticles(int numberOfParticles) { ParticleExplosion* pRet = new ParticleExplosion(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -834,7 +834,7 @@ ParticleExplosion* ParticleExplosion::createWithTotalParticles(unsigned int numb return pRet; } -bool ParticleExplosion::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleExplosion::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -928,7 +928,7 @@ ParticleSmoke* ParticleSmoke::create() return pRet; } -ParticleSmoke* ParticleSmoke::createWithTotalParticles(unsigned int numberOfParticles) +ParticleSmoke* ParticleSmoke::createWithTotalParticles(int numberOfParticles) { ParticleSmoke* pRet = new ParticleSmoke(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -942,7 +942,7 @@ ParticleSmoke* ParticleSmoke::createWithTotalParticles(unsigned int numberOfPart return pRet; } -bool ParticleSmoke::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSmoke::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -1033,7 +1033,7 @@ ParticleSnow* ParticleSnow::create() return pRet; } -ParticleSnow* ParticleSnow::createWithTotalParticles(unsigned int numberOfParticles) +ParticleSnow* ParticleSnow::createWithTotalParticles(int numberOfParticles) { ParticleSnow* pRet = new ParticleSnow(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -1047,7 +1047,7 @@ ParticleSnow* ParticleSnow::createWithTotalParticles(unsigned int numberOfPartic return pRet; } -bool ParticleSnow::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleSnow::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { @@ -1141,7 +1141,7 @@ ParticleRain* ParticleRain::create() return pRet; } -ParticleRain* ParticleRain::createWithTotalParticles(unsigned int numberOfParticles) +ParticleRain* ParticleRain::createWithTotalParticles(int numberOfParticles) { ParticleRain* pRet = new ParticleRain(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) @@ -1155,7 +1155,7 @@ ParticleRain* ParticleRain::createWithTotalParticles(unsigned int numberOfPartic return pRet; } -bool ParticleRain::initWithTotalParticles(unsigned int numberOfParticles) +bool ParticleRain::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { diff --git a/cocos/2d/CCParticleExamples.h b/cocos/2d/CCParticleExamples.h index f8d36d28d4..325bcd59f9 100644 --- a/cocos/2d/CCParticleExamples.h +++ b/cocos/2d/CCParticleExamples.h @@ -39,6 +39,10 @@ NS_CC_BEGIN class CC_DLL ParticleFire : public ParticleSystemQuad { public: + static ParticleFire* create(); + static ParticleFire* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -49,16 +53,20 @@ public: */ virtual ~ParticleFire(){} bool init(){ return initWithTotalParticles(250); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleFire* create(); - static ParticleFire* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles) override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleFire); }; //! @brief A fireworks particle system class CC_DLL ParticleFireworks : public ParticleSystemQuad { public: + static ParticleFireworks* create(); + static ParticleFireworks* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -69,16 +77,21 @@ public: */ virtual ~ParticleFireworks(){} bool init(){ return initWithTotalParticles(1500); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleFireworks* create(); - static ParticleFireworks* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleFireworks); + }; //! @brief A sun particle system class CC_DLL ParticleSun : public ParticleSystemQuad { public: + static ParticleSun* create(); + static ParticleSun* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -89,16 +102,21 @@ public: */ virtual ~ParticleSun(){} bool init(){ return initWithTotalParticles(350); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleSun* create(); - static ParticleSun* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSun); + }; //! @brief A galaxy particle system class CC_DLL ParticleGalaxy : public ParticleSystemQuad { public: + static ParticleGalaxy* create(); + static ParticleGalaxy* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -109,16 +127,21 @@ public: */ virtual ~ParticleGalaxy(){} bool init(){ return initWithTotalParticles(200); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleGalaxy* create(); - static ParticleGalaxy* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleGalaxy); + }; //! @brief A flower particle system class CC_DLL ParticleFlower : public ParticleSystemQuad { public: + static ParticleFlower* create(); + static ParticleFlower* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -129,16 +152,20 @@ public: */ virtual ~ParticleFlower(){} bool init(){ return initWithTotalParticles(250); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleFlower* create(); - static ParticleFlower* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleFlower); }; //! @brief A meteor particle system class CC_DLL ParticleMeteor : public ParticleSystemQuad { public: + static ParticleMeteor * create(); + static ParticleMeteor* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -149,16 +176,20 @@ public: */ virtual ~ParticleMeteor(){} bool init(){ return initWithTotalParticles(150); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); - static ParticleMeteor * create(); - static ParticleMeteor* createWithTotalParticles(unsigned int numberOfParticles); +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleMeteor); }; //! @brief An spiral particle system class CC_DLL ParticleSpiral : public ParticleSystemQuad { public: + static ParticleSpiral* create(); + static ParticleSpiral* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -169,16 +200,21 @@ public: */ virtual ~ParticleSpiral(){} bool init(){ return initWithTotalParticles(500); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleSpiral* create(); - static ParticleSpiral* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSpiral); + }; //! @brief An explosion particle system class CC_DLL ParticleExplosion : public ParticleSystemQuad { public: + static ParticleExplosion* create(); + static ParticleExplosion* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -189,16 +225,20 @@ public: */ virtual ~ParticleExplosion(){} bool init(){ return initWithTotalParticles(700); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleExplosion* create(); - static ParticleExplosion* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleExplosion); }; //! @brief An smoke particle system class CC_DLL ParticleSmoke : public ParticleSystemQuad { public: + static ParticleSmoke* create(); + static ParticleSmoke* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -209,16 +249,20 @@ public: */ virtual ~ParticleSmoke(){} bool init(){ return initWithTotalParticles(200); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleSmoke* create(); - static ParticleSmoke* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSmoke); }; //! @brief An snow particle system class CC_DLL ParticleSnow : public ParticleSystemQuad { public: + static ParticleSnow* create(); + static ParticleSnow* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -229,16 +273,20 @@ public: */ virtual ~ParticleSnow(){} bool init(){ return initWithTotalParticles(700); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleSnow* create(); - static ParticleSnow* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleSnow); }; //! @brief A rain particle system class CC_DLL ParticleRain : public ParticleSystemQuad { public: + static ParticleRain* create(); + static ParticleRain* createWithTotalParticles(int numberOfParticles); + +protected: /** * @js ctor */ @@ -249,10 +297,10 @@ public: */ virtual ~ParticleRain(){} bool init(){ return initWithTotalParticles(1000); } - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - - static ParticleRain* create(); - static ParticleRain* createWithTotalParticles(unsigned int numberOfParticles); + virtual bool initWithTotalParticles(int numberOfParticles); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ParticleRain); }; // end of particle_nodes group diff --git a/cocos/editor-support/cocostudio/CCActionObject.cpp b/cocos/editor-support/cocostudio/CCActionObject.cpp index ba12778510..5d9a85e587 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.cpp +++ b/cocos/editor-support/cocostudio/CCActionObject.cpp @@ -42,7 +42,7 @@ ActionObject::ActionObject() _actionNodeList = Array::create(); _actionNodeList->retain(); _pScheduler = new Scheduler(); - Director::sharedDirector()->getScheduler()->scheduleUpdateForTarget(_pScheduler, 0, false); + Director::getInstance()->getScheduler()->scheduleUpdateForTarget(_pScheduler, 0, false); } ActionObject::~ActionObject() @@ -193,7 +193,7 @@ void ActionObject::simulationActionUpdate(float dt) for ( int i = 0; i < nodeNum; i++ ) { - ActionNode* actionNode = (ActionNode*)_actionNodeList->objectAtIndex(i); + ActionNode* actionNode = static_cast(_actionNodeList->getObjectAtIndex(i)); if (actionNode->isActionDoneOnce() == false) { diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp index 88fd2cebd2..f8bfc895af 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp @@ -1379,8 +1379,8 @@ class RainbowEffect : public ParticleSystemQuad { public: bool init(); - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - virtual void update(float dt); + virtual bool initWithTotalParticles(int numberOfParticles) override; + virtual void update(float dt) override; }; bool RainbowEffect::init() @@ -1388,7 +1388,7 @@ bool RainbowEffect::init() return initWithTotalParticles(150); } -bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles) +bool RainbowEffect::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { From a3fabd6b6df77571b2b37b280daafcafc43426f3 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 15 Nov 2013 16:37:57 -0800 Subject: [PATCH 11/28] TiledMap uses std::string --- cocos/2d/CCTileMapAtlas.cpp | 8 +++----- cocos/2d/CCTileMapAtlas.h | 11 ++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCTileMapAtlas.cpp b/cocos/2d/CCTileMapAtlas.cpp index 9b7bc85ad3..8dc22d8244 100644 --- a/cocos/2d/CCTileMapAtlas.cpp +++ b/cocos/2d/CCTileMapAtlas.cpp @@ -36,7 +36,7 @@ NS_CC_BEGIN // implementation TileMapAtlas -TileMapAtlas * TileMapAtlas::create(const char *tile, const char *mapFile, int tileWidth, int tileHeight) +TileMapAtlas * TileMapAtlas::create(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight) { TileMapAtlas *pRet = new TileMapAtlas(); if (pRet->initWithTileFile(tile, mapFile, tileWidth, tileHeight)) @@ -48,7 +48,7 @@ TileMapAtlas * TileMapAtlas::create(const char *tile, const char *mapFile, int t return NULL; } -bool TileMapAtlas::initWithTileFile(const char *tile, const char *mapFile, int tileWidth, int tileHeight) +bool TileMapAtlas::initWithTileFile(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight) { this->loadTGAfile(mapFile); this->calculateItemsToRender(); @@ -111,10 +111,8 @@ void TileMapAtlas::calculateItemsToRender() } } -void TileMapAtlas::loadTGAfile(const char *file) +void TileMapAtlas::loadTGAfile(const std::string& file) { - CCASSERT( file != NULL, "file must be non-nil"); - std::string fullPath = FileUtils::getInstance()->fullPathForFilename(file); // //Find the path of the file diff --git a/cocos/2d/CCTileMapAtlas.h b/cocos/2d/CCTileMapAtlas.h index 865f47295a..e9899366d4 100644 --- a/cocos/2d/CCTileMapAtlas.h +++ b/cocos/2d/CCTileMapAtlas.h @@ -60,7 +60,7 @@ public: /** creates a TileMap with a tile file (atlas) with a map file and the width and height of each tile in points. The tile file will be loaded using the TextureMgr. */ - static TileMapAtlas * create(const char *tile, const char *mapFile, int tileWidth, int tileHeight); + static TileMapAtlas * create(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight); /** * @js ctor */ @@ -74,7 +74,7 @@ public: /** initializes a TileMap with a tile file (atlas) with a map file and the width and height of each tile in points. The file will be loaded using the TextureMgr. */ - bool initWithTileFile(const char *tile, const char *mapFile, int tileWidth, int tileHeight); + bool initWithTileFile(const std::string& tile, const std::string& mapFile, int tileWidth, int tileHeight); /** returns a tile from position x,y. For the moment only channel R is used */ @@ -89,13 +89,14 @@ public: inline struct sImageTGA* getTGAInfo() const { return _TGAInfo; }; inline void setTGAInfo(struct sImageTGA* TGAInfo) { _TGAInfo = TGAInfo; }; -private: - void loadTGAfile(const char *file); + +protected: + void loadTGAfile(const std::string& file); void calculateItemsToRender(); void updateAtlasValueAt(const Point& pos, const Color3B& value, int index); void updateAtlasValues(); -protected: + //! x,y to atlas dictionary Dictionary* _posToAtlasIndex; //! numbers of tiles to render From b6ddc6d048b15712cd25e3dbd99ea7596615ca90 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 21 Nov 2013 13:43:59 -0800 Subject: [PATCH 12/28] Uses std::unordered_map<> instead of std::map<> and more fixes. --- cocos/2d/CCTMXXMLParser.cpp | 8 ++--- cocos/2d/CCTexture2D.h | 1 + cocos/2d/ZipUtils.cpp | 2 +- cocos/2d/platform/CCFileUtils.h | 4 +-- cocos/2d/platform/mac/CCEGLView.mm | 6 +++- cocos/network/SocketIO.h | 2 +- .../chipmunk/CCPhysicsJointInfo_chipmunk.cpp | 5 ++- .../chipmunk/CCPhysicsJointInfo_chipmunk.h | 9 +++--- .../chipmunk/CCPhysicsShapeInfo_chipmunk.cpp | 5 ++- .../chipmunk/CCPhysicsShapeInfo_chipmunk.h | 12 +++---- .../javascript/bindings/ScriptingCore.cpp | 6 ++-- .../javascript/bindings/cocos2d_specifics.hpp | 2 +- .../bindings/network/XMLHTTPRequest.h | 4 +-- extensions/GUI/CCControlExtension/CCControl.h | 28 +++++++++------- .../CCControlExtension/CCControlButton.cpp | 24 +++++++------- .../GUI/CCControlExtension/CCControlButton.h | 32 +++++++------------ .../TestCpp/Classes/PhysicsTest/PhysicsTest.h | 2 +- 17 files changed, 78 insertions(+), 74 deletions(-) diff --git a/cocos/2d/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp index 5abe1e6f31..06a25e3e37 100644 --- a/cocos/2d/CCTMXXMLParser.cpp +++ b/cocos/2d/CCTMXXMLParser.cpp @@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include +#include #include #include "CCTMXXMLParser.h" #include "CCTMXTiledMap.h" @@ -38,11 +38,11 @@ using namespace std; NS_CC_BEGIN -static const char* valueForKey(const char *key, std::map* dict) +static const char* valueForKey(const char *key, std::unordered_map* dict) { if (dict) { - std::map::iterator it = dict->find(key); + std::unordered_map::iterator it = dict->find(key); return it!=dict->end() ? it->second.c_str() : ""; } return ""; @@ -244,7 +244,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) CC_UNUSED_PARAM(ctx); TMXMapInfo *pTMXMapInfo = this; std::string elementName = (char*)name; - std::map *attributeDict = new std::map(); + std::unordered_map *attributeDict = new std::unordered_map(); if (atts && atts[0]) { for(int i = 0; atts[i]; i += 2) diff --git a/cocos/2d/CCTexture2D.h b/cocos/2d/CCTexture2D.h index bdb28ce582..96c861c341 100644 --- a/cocos/2d/CCTexture2D.h +++ b/cocos/2d/CCTexture2D.h @@ -28,6 +28,7 @@ THE SOFTWARE. #include #include +#include #include "CCObject.h" #include "CCGeometry.h" diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index 26681d7bca..ebde2f9963 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -511,7 +511,7 @@ public: unzFile zipFile; // std::unordered_map is faster if available on the platform - typedef std::map FileListContainer; + typedef std::unordered_map FileListContainer; FileListContainer fileList; }; diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 1827ba53c7..672e4b7234 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -26,7 +26,7 @@ THE SOFTWARE. #include #include -#include +#include #include "CCPlatformMacros.h" #include "ccTypes.h" @@ -399,7 +399,7 @@ protected: * The full path cache. When a file is found, it will be added into this cache. * This variable is used for improving the performance of file search. */ - std::map _fullPathCache; + std::unordered_map _fullPathCache; /** * The singleton pointer of FileUtils. diff --git a/cocos/2d/platform/mac/CCEGLView.mm b/cocos/2d/platform/mac/CCEGLView.mm index d66f1dc17c..04ef6b69e7 100644 --- a/cocos/2d/platform/mac/CCEGLView.mm +++ b/cocos/2d/platform/mac/CCEGLView.mm @@ -21,7 +21,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ + #include "CCEGLView.h" + +#include + #include "EAGLView.h" #include "CCDirector.h" #include "CCSet.h" @@ -34,7 +38,7 @@ NS_CC_BEGIN -static std::map g_keyCodeMap = { +static std::unordered_map g_keyCodeMap = { /* The unknown key */ { GLFW_KEY_UNKNOWN , EventKeyboard::KeyCode::KEY_NONE }, diff --git a/cocos/network/SocketIO.h b/cocos/network/SocketIO.h index 5ec76bcb9b..7d62ed65a9 100644 --- a/cocos/network/SocketIO.h +++ b/cocos/network/SocketIO.h @@ -116,7 +116,7 @@ private: //c++11 style callbacks entities will be created using CC_CALLBACK (which uses std::bind) typedef std::function SIOEvent; //c++11 map to callbacks -typedef std::map EventRegistry; +typedef std::unordered_map EventRegistry; /** * @brief A single connection to a socket.io endpoint diff --git a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp index 2f8b7817cf..dd281507ea 100644 --- a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp @@ -23,11 +23,14 @@ ****************************************************************************/ #include "CCPhysicsJointInfo_chipmunk.h" + #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) #include +#include + NS_CC_BEGIN -std::map PhysicsJointInfo::_map; +std::unordered_map PhysicsJointInfo::_map; PhysicsJointInfo::PhysicsJointInfo(PhysicsJoint* joint) : _joint(joint) diff --git a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h index bdd3f1e887..9243d268be 100644 --- a/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h @@ -31,7 +31,7 @@ #include "chipmunk.h" #include "CCPlatformMacros.h" #include -#include +#include NS_CC_BEGIN class PhysicsJoint; @@ -45,16 +45,15 @@ public: PhysicsJoint* getJoint() const { return _joint; } std::vector& getJoints() { return _joints; } - static std::map& getMap() { return _map; } + static std::unordered_map& getMap() { return _map; } -private: +protected: PhysicsJointInfo(PhysicsJoint* joint); ~PhysicsJointInfo(); -private: std::vector _joints; PhysicsJoint* _joint; - static std::map _map; + static std::unordered_map _map; friend class PhysicsJoint; }; diff --git a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp index d12a053181..62780c1fb1 100644 --- a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp +++ b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp @@ -23,11 +23,14 @@ ****************************************************************************/ #include "CCPhysicsShapeInfo_chipmunk.h" + #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) #include +#include + NS_CC_BEGIN -std::map PhysicsShapeInfo::_map; +std::unordered_map PhysicsShapeInfo::_map; cpBody* PhysicsShapeInfo::_sharedBody = nullptr; PhysicsShapeInfo::PhysicsShapeInfo(PhysicsShape* shape) diff --git a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h index 2bdd55a7f9..d46246673e 100644 --- a/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h +++ b/cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h @@ -29,7 +29,7 @@ #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) #include -#include +#include #include "chipmunk.h" #include "CCPlatformMacros.h" @@ -45,25 +45,23 @@ public: void removeAll(); void setGroup(cpGroup group); void setBody(cpBody* body); - -public: + PhysicsShape* getShape() const { return _shape; } std::vector& getShapes() { return _shapes; } cpBody* getBody() const { return _body; } cpGroup getGourp() const { return _group; } - static std::map& getMap() { return _map; } + static std::unordered_map& getMap() { return _map; } static cpBody* getSharedBody() { return _sharedBody; } -private: +protected: PhysicsShapeInfo(PhysicsShape* shape); ~PhysicsShapeInfo(); -private: std::vector _shapes; PhysicsShape* _shape; cpBody* _body; cpGroup _group; - static std::map _map; + static std::unordered_map _map; static cpBody* _sharedBody; friend class PhysicsShape; diff --git a/cocos/scripting/javascript/bindings/ScriptingCore.cpp b/cocos/scripting/javascript/bindings/ScriptingCore.cpp index 0f7fca11f4..bbef7a525d 100644 --- a/cocos/scripting/javascript/bindings/ScriptingCore.cpp +++ b/cocos/scripting/javascript/bindings/ScriptingCore.cpp @@ -74,11 +74,11 @@ static char *_js_log_buf = NULL; static std::vector registrationList; // name ~> JSScript map -static std::map filename_script; +static std::unordered_map filename_script; // port ~> socket map -static std::map ports_sockets; +static std::unordered_map ports_sockets; // name ~> globals -static std::map globals; +static std::unordered_map globals; static void ReportException(JSContext *cx) { diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.hpp b/cocos/scripting/javascript/bindings/cocos2d_specifics.hpp index 9c03489007..25cca6ef30 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.hpp +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.hpp @@ -191,7 +191,7 @@ public: private: JSObject* _obj; - typedef std::map TouchDelegateMap; + typedef std::unordered_map TouchDelegateMap; typedef std::pair TouchDelegatePair; static TouchDelegateMap sTouchDelegateMap; bool _needUnroot; diff --git a/cocos/scripting/javascript/bindings/network/XMLHTTPRequest.h b/cocos/scripting/javascript/bindings/network/XMLHTTPRequest.h index 93951313f4..7a4be6b822 100644 --- a/cocos/scripting/javascript/bindings/network/XMLHTTPRequest.h +++ b/cocos/scripting/javascript/bindings/network/XMLHTTPRequest.h @@ -105,8 +105,8 @@ private: network::HttpRequest* _httpRequest; bool _isNetwork; bool _withCredentialsValue; - std::map _httpHeader; - std::map _requestHeader; + std::unordered_map _httpHeader; + std::unordered_map _requestHeader; }; #endif diff --git a/extensions/GUI/CCControlExtension/CCControl.h b/extensions/GUI/CCControlExtension/CCControl.h index 12533f7041..a86970e1d8 100644 --- a/extensions/GUI/CCControlExtension/CCControl.h +++ b/extensions/GUI/CCControlExtension/CCControl.h @@ -89,18 +89,9 @@ public: DISABLED = 1 << 2, // Disabled state of a control. This state indicates that the control is currently disabled. You can retrieve and set this value through the enabled property. SELECTED = 1 << 3 // Selected state of a control. This state indicates that the control is currently selected. You can retrieve and set this value through the selected property. }; - + + /** Creates a Control object */ static Control* create(); - /** - * @js ctor - */ - Control(); - virtual bool init(void); - /** - * @js NA - * @lua NA - */ - virtual ~Control(); /** Tells whether the control is enabled. */ virtual void setEnabled(bool bEnabled); @@ -184,6 +175,17 @@ public: virtual void setOpacityModifyRGB(bool bOpacityModifyRGB) override; protected: + /** + * @js ctor + */ + Control(); + virtual bool init(void); + /** + * @js NA + * @lua NA + */ + virtual ~Control(); + /** * Returns an Invocation object able to construct messages using a given * target-action pair. (The invocation may optionnaly include the sender and @@ -240,7 +242,6 @@ protected: */ void removeTargetWithActionForControlEvent(Object* target, Handler action, EventType controlEvent); -protected: bool _enabled; bool _selected; bool _highlighted; @@ -260,6 +261,9 @@ protected: /** The current control state constant. */ CC_SYNTHESIZE_READONLY(State, _state, State); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Control); }; Control::EventType operator|(Control::EventType a, Control::EventType b); diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index db18da4cdd..278338efe1 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -151,13 +151,13 @@ ControlButton* ControlButton::create(Node* label, Scale9Sprite* backgroundSprite return pRet; } -bool ControlButton::initWithTitleAndFontNameAndFontSize(string title, const char * fontName, float fontSize) +bool ControlButton::initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize) { - LabelTTF *label = LabelTTF::create(title.c_str(), fontName, fontSize); + LabelTTF *label = LabelTTF::create(title, fontName, fontSize); return initWithLabelAndBackgroundSprite(label, Scale9Sprite::create()); } -ControlButton* ControlButton::create(string title, const char * fontName, float fontSize) +ControlButton* ControlButton::create(const std::string& title, const std::string& fontName, float fontSize) { ControlButton *pRet = new ControlButton(); pRet->initWithTitleAndFontNameAndFontSize(title, fontName, fontSize); @@ -237,7 +237,7 @@ bool ControlButton::getZoomOnTouchDown() return _zoomOnTouchDown; } -void ControlButton::setPreferredSize(Size size) +void ControlButton::setPreferredSize(const Size& size) { if(size.width == 0 && size.height == 0) { @@ -258,7 +258,7 @@ void ControlButton::setPreferredSize(Size size) needsLayout(); } -Size ControlButton::getPreferredSize() +const Size& ControlButton::getPreferredSize() const { return _preferredSize; } @@ -274,12 +274,12 @@ bool ControlButton::doesAdjustBackgroundImage() return _doesAdjustBackgroundImage; } -Point ControlButton::getLabelAnchorPoint() +const Point& ControlButton::getLabelAnchorPoint() const { return this->_labelAnchorPoint; } -void ControlButton::setLabelAnchorPoint(Point labelAnchorPoint) +void ControlButton::setLabelAnchorPoint(const Point& labelAnchorPoint) { this->_labelAnchorPoint = labelAnchorPoint; if (_titleLabel != NULL) @@ -292,12 +292,12 @@ String* ControlButton::getTitleForState(State state) { if (_titleDispatchTable != NULL) { - String* title=(String*)_titleDispatchTable->objectForKey((int)state); + String* title = static_cast(_titleDispatchTable->objectForKey((int)state)); if (title) { return title; } - return (String*)_titleDispatchTable->objectForKey((int)Control::State::NORMAL); + return static_cast(_titleDispatchTable->objectForKey((int)Control::State::NORMAL)); } return String::create(""); } @@ -342,7 +342,7 @@ Color3B ControlButton::getTitleColorForState(State state) const return returnColor; } -void ControlButton::setTitleColorForState(Color3B color, State state) +void ControlButton::setTitleColorForState(const Color3B& color, State state) { //Color3B* colorValue=&color; _titleColorDispatchTable->removeObjectForKey((int)state); @@ -359,7 +359,7 @@ void ControlButton::setTitleColorForState(Color3B color, State state) Node* ControlButton::getTitleLabelForState(State state) { - Node* titleLabel = (Node*)_titleLabelDispatchTable->objectForKey((int)state); + Node* titleLabel = static_cast(_titleLabelDispatchTable->objectForKey((int)state)); if (titleLabel) { return titleLabel; @@ -369,7 +369,7 @@ Node* ControlButton::getTitleLabelForState(State state) void ControlButton::setTitleLabelForState(Node* titleLabel, State state) { - Node* previousLabel = (Node*)_titleLabelDispatchTable->objectForKey((int)state); + Node* previousLabel = static_cast(_titleLabelDispatchTable->objectForKey((int)state)); if (previousLabel) { removeChild(previousLabel, true); diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 1da0d5c74d..2cbadab7df 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -56,7 +56,7 @@ public: static ControlButton* create(); static ControlButton* create(Scale9Sprite* sprite); static ControlButton* create(Node* label, Scale9Sprite* backgroundSprite); - static ControlButton* create(std::string title, const char * fontName, float fontSize); + static ControlButton* create(const std::string& title, const std::string& fontName, float fontSize); virtual void needsLayout(void); @@ -105,7 +105,7 @@ public: * @param state The state that uses the specified color. The values are described * in "CCControlState". */ - virtual void setTitleColorForState(Color3B color, State state); + virtual void setTitleColorForState(const Color3B& color, State state); /** * Returns the title label used for a state. @@ -170,29 +170,21 @@ public: //set the margins at once (so we only have to do one call of needsLayout) virtual void setMargins(int marginH, int marginV); + /** Adjust the background image. YES by default. If the property is set to NO, the + background will use the prefered size of the background image. */ + bool doesAdjustBackgroundImage(); + void setAdjustBackgroundImage(bool adjustBackgroundImage); + + // Overrides virtual bool onTouchBegan(Touch *touch, Event *event) override; virtual void onTouchMoved(Touch *touch, Event *event) override; virtual void onTouchEnded(Touch *touch, Event *event) override; virtual void onTouchCancelled(Touch *touch, Event *event) override; - - // Overrides -// virtual bool ccTouchBegan(Touch *pTouch, Event *pEvent) override; -// virtual void ccTouchMoved(Touch *pTouch, Event *pEvent) override; -// virtual void ccTouchEnded(Touch *pTouch, Event *pEvent) override; -// virtual void ccTouchCancelled(Touch *pTouch, Event *pEvent) override; virtual GLubyte getOpacity(void) const override; virtual void setOpacity(GLubyte var) override; virtual const Color3B& getColor(void) const override; virtual void setColor(const Color3B&) override; -//protected: - // RGBAProtocol - //bool _isOpacityModifyRGB; - - /** Adjust the background image. YES by default. If the property is set to NO, the - background will use the prefered size of the background image. */ - bool doesAdjustBackgroundImage(); - void setAdjustBackgroundImage(bool adjustBackgroundImage); protected: /** @@ -208,7 +200,7 @@ protected: virtual bool init(); virtual bool initWithLabelAndBackgroundSprite(Node* label, Scale9Sprite* backgroundSprite); virtual bool initWithBackgroundSprite(Scale9Sprite* sprite); - virtual bool initWithTitleAndFontNameAndFontSize(std::string title, const char * fontName, float fontSize); + virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize); bool _isPushed; bool _parentInited; @@ -227,12 +219,12 @@ protected: CC_SYNTHESIZE_RETAIN(Scale9Sprite*, _backgroundSprite, BackgroundSprite); /** The prefered size of the button, if label is larger it will be expanded. */ - CC_PROPERTY(Size, _preferredSize, PreferredSize); + CC_PROPERTY_PASS_BY_REF(Size, _preferredSize, PreferredSize); /** Adjust the button zooming on touchdown. Default value is YES. */ CC_PROPERTY(bool, _zoomOnTouchDown, ZoomOnTouchDown); - CC_PROPERTY(Point, _labelAnchorPoint, LabelAnchorPoint); + CC_PROPERTY_PASS_BY_REF(Point, _labelAnchorPoint, LabelAnchorPoint); // CC_SYNTHESIZE_RETAIN(Dictionary*, _titleDispatchTable, TitleDispatchTable); @@ -248,7 +240,7 @@ protected: /* Define the button margin for Left/Right edge */ CC_SYNTHESIZE_READONLY(int, _marginH, HorizontalOrigin); -protected: +private: CC_DISALLOW_COPY_AND_ASSIGN(ControlButton); }; diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h index 47930e451d..f59992cead 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h @@ -55,7 +55,7 @@ protected: PhysicsTestScene* _scene; Texture2D* _spriteTexture; // weak ref SpriteBatchNode* _ball; - std::map _mouses; + std::unordered_map _mouses; }; class PhysicsDemoClickAdd : public PhysicsDemo From 515786a7eef09d784c79cc13314d90c1e1a66f9e Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 21 Nov 2013 17:06:06 -0800 Subject: [PATCH 13/28] adds CC_DISALLOW_COPY_AND_ASSIGN() to Actilons ... and also moves the Contructor/Destrucotor/initXXX to `protected:` --- cocos/2d/CCAction.h | 111 ++++++----- cocos/2d/CCActionEase.h | 177 ++++++++++++++++-- cocos/2d/CCActionInstant.h | 204 +++++++++++---------- cocos/2d/CCActionInterval.cpp | 20 +- cocos/2d/CCActionInterval.h | 334 +++++++++++++++++++++------------- 5 files changed, 541 insertions(+), 305 deletions(-) diff --git a/cocos/2d/CCAction.h b/cocos/2d/CCAction.h index 21a72591e9..202adf7847 100644 --- a/cocos/2d/CCAction.h +++ b/cocos/2d/CCAction.h @@ -46,15 +46,6 @@ class CC_DLL Action : public Object, public Clonable public: /// Default tag used for all the actions static const int INVALID_TAG = -1; - /** - * @js ctor - */ - Action(); - /** - * @js NA - * @lua NA - */ - virtual ~Action(); /** * @js NA * @lua NA @@ -108,6 +99,9 @@ public: inline void setTag(int tag) { _tag = tag; } protected: + Action(); + virtual ~Action(); + Node *_originalTarget; /** The "target". The target will be set with the 'startWithTarget' method. @@ -117,6 +111,9 @@ protected: Node *_target; /** The action tag. An identifier of the action */ int _tag; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Action); }; /** @@ -131,17 +128,6 @@ protected: class CC_DLL FiniteTimeAction : public Action { public: - /** - * @js ctor - */ - FiniteTimeAction() - : _duration(0) - {} - /** - * @js NA - * @lua NA - */ - virtual ~FiniteTimeAction(){} //! get duration in seconds of the action inline float getDuration() const { return _duration; } //! set duration in seconds of the action @@ -154,8 +140,16 @@ public: virtual FiniteTimeAction* clone() const override = 0; protected: + FiniteTimeAction() + : _duration(0) + {} + virtual ~FiniteTimeAction(){} + //! duration in seconds float _duration; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction); }; class ActionInterval; @@ -172,22 +166,11 @@ class CC_DLL Speed : public Action public: /** create the action */ static Speed* create(ActionInterval* action, float speed); - /** - * @js ctor - */ - Speed(); - /** - * @js NA - * @lua NA - */ - virtual ~Speed(void); inline float getSpeed(void) const { return _speed; } /** alter the speed of the inner function in runtime */ inline void setSpeed(float speed) { _speed = speed; } - /** initializes the action */ - bool initWithAction(ActionInterval *action, float speed); void setInnerAction(ActionInterval *action); @@ -204,8 +187,16 @@ public: virtual bool isDone() const override; protected: + Speed(); + virtual ~Speed(void); + /** initializes the action */ + bool initWithAction(ActionInterval *action, float speed); + float _speed; ActionInterval *_innerAction; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Speed); }; /** @@ -230,38 +221,11 @@ public: * with no boundary. */ static Follow* create(Node *followedNode, const Rect& rect = Rect::ZERO); - /** - * @js ctor - */ - Follow() - : _followedNode(nullptr) - , _boundarySet(false) - , _boundaryFullyCovered(false) - , _leftBoundary(0.0) - , _rightBoundary(0.0) - , _topBoundary(0.0) - , _bottomBoundary(0.0) - , _worldRect(Rect::ZERO) - {} - /** - * @js NA - * @lua NA - */ - virtual ~Follow(); - + inline bool isBoundarySet() const { return _boundarySet; } /** alter behavior - turn on/off boundary */ inline void setBoudarySet(bool value) { _boundarySet = value; } - /** - * Initializes the action with a set boundary or with no boundary. - * - * @param followedNode The node to be followed. - * @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work - * with no boundary. - */ - bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO); - // // Override // @@ -272,6 +236,33 @@ public: virtual void stop() override; protected: + /** + * @js ctor + */ + Follow() + : _followedNode(nullptr) + , _boundarySet(false) + , _boundaryFullyCovered(false) + , _leftBoundary(0.0) + , _rightBoundary(0.0) + , _topBoundary(0.0) + , _bottomBoundary(0.0) + , _worldRect(Rect::ZERO) + {} + /** + * @js NA + * @lua NA + */ + virtual ~Follow(); + /** + * Initializes the action with a set boundary or with no boundary. + * + * @param followedNode The node to be followed. + * @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work + * with no boundary. + */ + bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO); + // node to follow Node *_followedNode; @@ -292,6 +283,8 @@ protected: float _bottomBoundary; Rect _worldRect; +private: + CC_DISALLOW_COPY_AND_ASSIGN(Follow); }; // end of actions group diff --git a/cocos/2d/CCActionEase.h b/cocos/2d/CCActionEase.h index 13b708203a..efe0c9600c 100644 --- a/cocos/2d/CCActionEase.h +++ b/cocos/2d/CCActionEase.h @@ -44,14 +44,6 @@ class Object; class CC_DLL ActionEase : public ActionInterval { public: - /** - * @js NA - * @lua NA - */ - virtual ~ActionEase(void); - - /** initializes the action */ - bool initWithAction(ActionInterval *action); virtual ActionInterval* getInnerAction(); @@ -65,8 +57,16 @@ public: virtual void update(float time) override; protected: + ActionEase() {} + virtual ~ActionEase(); + /** initializes the action */ + bool initWithAction(ActionInterval *action); + /** The inner action */ ActionInterval *_inner; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ActionEase); }; /** @@ -76,15 +76,6 @@ protected: class CC_DLL EaseRateAction : public ActionEase { public: - /** - * @js NA - * @lua NA - */ - virtual ~EaseRateAction(); - - /** Initializes the action with the inner action and the rate parameter */ - bool initWithAction(ActionInterval *pAction, float fRate); - /** set rate value for the actions */ inline void setRate(float rate) { _rate = rate; } /** get rate value for the actions */ @@ -97,7 +88,15 @@ public: virtual EaseRateAction* reverse() const override = 0; protected: + EaseRateAction() {} + virtual ~EaseRateAction(); + /** Initializes the action with the inner action and the rate parameter */ + bool initWithAction(ActionInterval *pAction, float fRate); + float _rate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseRateAction); }; /** @@ -114,6 +113,13 @@ public: virtual void update(float time) override; virtual EaseIn* clone() const override; virtual EaseIn* reverse() const override; + +protected: + EaseIn() {} + virtual ~EaseIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseIn); }; /** @@ -130,6 +136,13 @@ public: virtual void update(float time) override; virtual EaseOut* clone() const override; virtual EaseOut* reverse() const override; + +protected: + EaseOut() {} + virtual ~EaseOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseOut); }; /** @@ -146,6 +159,13 @@ public: virtual void update(float time) override; virtual EaseInOut* clone() const override; virtual EaseInOut* reverse() const override; + +protected: + EaseInOut() {} + virtual ~EaseInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseInOut); }; /** @@ -162,6 +182,13 @@ public: virtual void update(float time) override; virtual EaseExponentialIn* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseExponentialIn() {} + virtual ~EaseExponentialIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseExponentialIn); }; /** @@ -178,6 +205,13 @@ public: virtual void update(float time) override; virtual EaseExponentialOut* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseExponentialOut() {} + virtual ~EaseExponentialOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseExponentialOut); }; /** @@ -194,6 +228,13 @@ public: virtual void update(float time) override; virtual EaseExponentialInOut* clone() const override; virtual EaseExponentialInOut* reverse() const override; + +protected: + EaseExponentialInOut() {} + virtual ~EaseExponentialInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseExponentialInOut); }; /** @@ -210,6 +251,13 @@ public: virtual void update(float time) override; virtual EaseSineIn* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseSineIn() {} + virtual ~EaseSineIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseSineIn); }; /** @@ -226,6 +274,13 @@ public: virtual void update(float time) override; virtual EaseSineOut* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseSineOut() {} + virtual ~EaseSineOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseSineOut); }; /** @@ -242,6 +297,13 @@ public: virtual void update(float time) override; virtual EaseSineInOut* clone() const override; virtual EaseSineInOut* reverse() const override; + +protected: + EaseSineInOut() {} + virtual ~EaseSineInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseSineInOut); }; /** @@ -252,8 +314,6 @@ public: class CC_DLL EaseElastic : public ActionEase { public: - /** Initializes the action with the inner action and the period in radians (default is 0.3) */ - bool initWithAction(ActionInterval *action, float period = 0.3f); /** get period of the wave in radians. default is 0.3 */ inline float getPeriod() const { return _period; } @@ -267,7 +327,16 @@ public: virtual EaseElastic* reverse() const override = 0; protected: + EaseElastic() {} + virtual ~EaseElastic() {} + /** Initializes the action with the inner action and the period in radians (default is 0.3) */ + bool initWithAction(ActionInterval *action, float period = 0.3f); + float _period; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseElastic); + }; /** @@ -287,6 +356,13 @@ public: virtual void update(float time) override; virtual EaseElasticIn* clone() const override; virtual EaseElastic* reverse() const override; + +protected: + EaseElasticIn() {} + virtual ~EaseElasticIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseElasticIn); }; /** @@ -306,6 +382,13 @@ public: virtual void update(float time) override; virtual EaseElasticOut* clone() const override; virtual EaseElastic* reverse() const override; + +protected: + EaseElasticOut() {} + virtual ~EaseElasticOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseElasticOut); }; /** @@ -325,6 +408,13 @@ public: virtual void update(float time) override; virtual EaseElasticInOut* clone() const override; virtual EaseElasticInOut* reverse() const override; + +protected: + EaseElasticInOut() {} + virtual ~EaseElasticInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseElasticInOut); }; /** @@ -340,6 +430,13 @@ public: // Overrides virtual EaseBounce* clone() const override = 0; virtual EaseBounce* reverse() const override = 0; + +protected: + EaseBounce() {} + virtual ~EaseBounce() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBounce); }; /** @@ -358,6 +455,13 @@ public: virtual void update(float time) override; virtual EaseBounceIn* clone() const override; virtual EaseBounce* reverse() const override; + +protected: + EaseBounceIn() {} + virtual ~EaseBounceIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBounceIn); }; /** @@ -376,6 +480,13 @@ public: virtual void update(float time) override; virtual EaseBounceOut* clone() const override; virtual EaseBounce* reverse() const override; + +protected: + EaseBounceOut() {} + virtual ~EaseBounceOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBounceOut); }; /** @@ -394,6 +505,13 @@ public: virtual void update(float time) override; virtual EaseBounceInOut* clone() const override; virtual EaseBounceInOut* reverse() const override; + +protected: + EaseBounceInOut() {} + virtual ~EaseBounceInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBounceInOut); }; /** @@ -412,6 +530,13 @@ public: virtual void update(float time) override; virtual EaseBackIn* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseBackIn() {} + virtual ~EaseBackIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBackIn); }; /** @@ -430,6 +555,13 @@ public: virtual void update(float time) override; virtual EaseBackOut* clone() const override; virtual ActionEase* reverse() const override; + +protected: + EaseBackOut() {} + virtual ~EaseBackOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBackOut); }; /** @@ -448,6 +580,13 @@ public: virtual void update(float time) override; virtual EaseBackInOut* clone() const override; virtual EaseBackInOut* reverse() const override; + +protected: + EaseBackInOut() {} + virtual ~EaseBackInOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(EaseBackInOut); }; // end of actions group diff --git a/cocos/2d/CCActionInstant.h b/cocos/2d/CCActionInstant.h index 01a26a3786..ad4c0ea314 100644 --- a/cocos/2d/CCActionInstant.h +++ b/cocos/2d/CCActionInstant.h @@ -65,7 +65,6 @@ public: /** Allocates and initializes the action */ static Show * create(); - Show(){} // // Overrides @@ -73,6 +72,13 @@ public: virtual void update(float time) override; virtual ActionInstant* reverse() const override; virtual Show* clone() const override; + +protected: + Show(){} + virtual ~Show(){} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Show); }; /** @@ -84,14 +90,19 @@ public: /** Allocates and initializes the action */ static Hide * create(); - Hide(){} - // // Overrides // virtual void update(float time) override; virtual ActionInstant* reverse() const override; virtual Hide* clone() const override; + +protected: + Hide(){} + virtual ~Hide(){} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Hide); }; /** @brief Toggles the visibility of a node @@ -102,14 +113,19 @@ public: /** Allocates and initializes the action */ static ToggleVisibility * create(); - ToggleVisibility(){} - // // Overrides // virtual void update(float time) override; virtual ToggleVisibility* reverse() const override; virtual ToggleVisibility* clone() const override; + +protected: + ToggleVisibility(){} + virtual ~ToggleVisibility(){} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ToggleVisibility); }; /** @@ -121,12 +137,6 @@ public: /** create the action */ static RemoveSelf * create(bool isNeedCleanUp = true); - RemoveSelf():_isNeedCleanUp(true) - {} - - /** init the action */ - bool init(bool isNeedCleanUp); - // // Override // @@ -135,7 +145,15 @@ public: virtual RemoveSelf* reverse() const override; protected: + RemoveSelf() : _isNeedCleanUp(true){} + virtual ~RemoveSelf(){} + /** init the action */ + bool init(bool isNeedCleanUp); + bool _isNeedCleanUp; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(RemoveSelf); }; /** @@ -148,13 +166,6 @@ public: /** create the action */ static FlipX * create(bool x); - FlipX() - :_flipX(false) - {} - - /** init the action */ - bool initWithFlipX(bool x); - // // Overrides // @@ -163,7 +174,15 @@ public: virtual FlipX* clone() const override; protected: + FlipX() :_flipX(false) {} + virtual ~FlipX() {} + /** init the action */ + bool initWithFlipX(bool x); + bool _flipX; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FlipX); }; /** @@ -176,13 +195,6 @@ public: /** create the action */ static FlipY * create(bool y); - FlipY() - :_flipY(false) - {} - - /** init the action */ - bool initWithFlipY(bool y); - // // Overrides // @@ -191,7 +203,15 @@ public: virtual FlipY* clone() const override; protected: + FlipY() :_flipY(false) {} + virtual ~FlipY() {} + /** init the action */ + bool initWithFlipY(bool y); + bool _flipY; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FlipY); }; /** @brief Places the node in a certain position @@ -199,12 +219,9 @@ protected: class CC_DLL Place : public ActionInstant // { public: - Place(){} /** creates a Place action with a position */ static Place * create(const Point& pos); - /** Initializes a Place action with a position */ - bool initWithPosition(const Point& pos); // // Overrides @@ -214,7 +231,15 @@ public: virtual Place* clone() const override; protected: + Place(){} + virtual ~Place(){} + /** Initializes a Place action with a position */ + bool initWithPosition(const Point& pos); + Point _position; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Place); }; @@ -240,34 +265,6 @@ public: */ CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Object* target, SEL_CallFunc selector); -public: - /** - * @js ctor - */ - CallFunc() - : _selectorTarget(NULL) - , _callFunc(NULL) - , _function(nullptr) - { - } - /** - * @js NA - * @lua NA - */ - virtual ~CallFunc(); - - /** initializes the action with the callback - typedef void (Object::*SEL_CallFunc)(); - @deprecated Use the std::function API instead. - */ - CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target); - - /** initializes the action with the std::function - * @js NK - * @lua NK - */ - bool initWithFunction(const std::function& func); - /** executes the callback */ virtual void execute(); @@ -293,6 +290,25 @@ public: virtual CallFunc* clone() const override; protected: + CallFunc() + : _selectorTarget(NULL) + , _callFunc(NULL) + , _function(nullptr) + {} + virtual ~CallFunc(); + + /** initializes the action with the callback + typedef void (Object::*SEL_CallFunc)(); + @deprecated Use the std::function API instead. + */ + CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target); + + /** initializes the action with the std::function + * @js NK + * @lua NK + */ + bool initWithFunction(const std::function& func); + /** Target that will be called */ Object* _selectorTarget; @@ -304,6 +320,9 @@ protected: /** function that will be called */ std::function _function; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(CallFunc); }; /** @@ -324,19 +343,6 @@ public: @deprecated Use the std::function API instead. */ CC_DEPRECATED_ATTRIBUTE static CallFuncN * create(Object* target, SEL_CallFuncN selector); -public: - CallFuncN():_functionN(nullptr){} - - /** initializes the action with the std::function - */ - bool initWithFunction(const std::function& func); - - /** initializes the action with the callback - - typedef void (Object::*SEL_CallFuncN)(Node*); - @deprecated Use the std::function API instead. - */ - CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_CallFuncN selector); // // Overrides @@ -345,8 +351,24 @@ public: virtual void execute() override; protected: + CallFuncN():_functionN(nullptr){} + virtual ~CallFuncN(){} + /** initializes the action with the std::function */ + bool initWithFunction(const std::function& func); + + /** initializes the action with the callback + + typedef void (Object::*SEL_CallFuncN)(Node*); + @deprecated Use the std::function API instead. + */ + CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Object* target, SEL_CallFuncN selector); + + /** function that will be called with the "sender" as the 1st argument */ std::function _functionN; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(CallFuncN); }; /** @@ -361,11 +383,6 @@ public: /** creates the action with the callback and the data to pass as an argument */ CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Object* target, SEL_CallFuncND selector, void* d); -protected: - /** initializes the action with the callback and the data to pass as an argument */ - bool initWithTarget(Object* target, SEL_CallFuncND selector, void* d); - -public: // // Overrides // @@ -373,8 +390,17 @@ public: virtual void execute() override; protected: + __CCCallFuncND() {} + virtual ~__CCCallFuncND() {} + + /** initializes the action with the callback and the data to pass as an argument */ + bool initWithTarget(Object* target, SEL_CallFuncND selector, void* d); + SEL_CallFuncND _callFuncND; void* _data; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncND); }; @@ -393,24 +419,6 @@ public: typedef void (Object::*SEL_CallFuncO)(Object*); */ CC_DEPRECATED_ATTRIBUTE static __CCCallFuncO * create(Object* target, SEL_CallFuncO selector, Object* object); - /** - * @js ctor - */ - __CCCallFuncO(); - /** - * @js NA - * @lua NA - */ - virtual ~__CCCallFuncO(); - -protected: - /** initializes the action with the callback - - typedef void (Object::*SEL_CallFuncO)(Object*); - */ - bool initWithTarget(Object* target, SEL_CallFuncO selector, Object* object); - -public: // // Overrides // @@ -421,9 +429,21 @@ public: void setObject(Object* obj); protected: + __CCCallFuncO(); + virtual ~__CCCallFuncO(); + /** initializes the action with the callback + + typedef void (Object::*SEL_CallFuncO)(Object*); + */ + bool initWithTarget(Object* target, SEL_CallFuncO selector, Object* object); + + /** object to be passed as argument */ Object* _object; SEL_CallFuncO _callFuncO; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncO); }; // end of actions group diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index bd300f73f0..a2ae6b7824 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -149,13 +149,13 @@ void ActionInterval::startWithTarget(Node *target) // Sequence // -Sequence* Sequence::createWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo) +Sequence* Sequence::createWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo) { - Sequence *pSequence = new Sequence(); - pSequence->initWithTwoActions(pActionOne, pActionTwo); - pSequence->autorelease(); + Sequence *sequence = new Sequence(); + sequence->initWithTwoActions(actionOne, actionTwo); + sequence->autorelease(); - return pSequence; + return sequence; } Sequence* Sequence::create(FiniteTimeAction *pAction1, ...) @@ -597,13 +597,13 @@ Spawn* Spawn::create(Array *arrayOfActions) return pRet; } -Spawn* Spawn::createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2) +Spawn* Spawn::createWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2) { - Spawn *pSpawn = new Spawn(); - pSpawn->initWithTwoActions(pAction1, pAction2); - pSpawn->autorelease(); + Spawn *spawn = new Spawn(); + spawn->initWithTwoActions(action1, action2); + spawn->autorelease(); - return pSpawn; + return spawn; } bool Spawn:: initWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2) diff --git a/cocos/2d/CCActionInterval.h b/cocos/2d/CCActionInterval.h index 270dca3414..a72327e997 100644 --- a/cocos/2d/CCActionInterval.h +++ b/cocos/2d/CCActionInterval.h @@ -64,9 +64,6 @@ public: /** how many seconds had elapsed since the actions started to run. */ inline float getElapsed(void) { return _elapsed; } - /** initializes the action */ - bool initWithDuration(float d); - //extension in GridAction void setAmplitudeRate(float amp); float getAmplitudeRate(void); @@ -80,8 +77,10 @@ public: virtual ActionInterval* reverse() const override = 0; virtual ActionInterval *clone() const override = 0; - protected: + /** initializes the action */ + bool initWithDuration(float d); + float _elapsed; bool _firstTick; }; @@ -105,14 +104,6 @@ public: static Sequence* createWithVariableList(FiniteTimeAction *pAction1, va_list args); /** creates the action */ static Sequence* createWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo); - /** - * @js NA - * @lua NA - */ - virtual ~Sequence(void); - - /** initializes the action */ - bool initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo); // // Overrides @@ -124,9 +115,17 @@ public: virtual void update(float t) override; protected: + Sequence() {} + virtual ~Sequence(void); + /** initializes the action */ + bool initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo); + FiniteTimeAction *_actions[2]; float _split; int _last; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Sequence); }; /** @brief Repeats an action a number of times. @@ -137,14 +136,6 @@ class CC_DLL Repeat : public ActionInterval public: /** creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */ static Repeat* create(FiniteTimeAction *pAction, unsigned int times); - /** - * @js NA - * @lua NA - */ - virtual ~Repeat(void); - - /** initializes a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */ - bool initWithAction(FiniteTimeAction *pAction, unsigned int times); inline void setInnerAction(FiniteTimeAction *pAction) { @@ -172,12 +163,20 @@ public: virtual bool isDone(void) const override; protected: + Repeat() {} + virtual ~Repeat(); + /** initializes a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */ + bool initWithAction(FiniteTimeAction *pAction, unsigned int times); + unsigned int _times; unsigned int _total; float _nextDt; bool _actionInstant; /** Inner action */ FiniteTimeAction *_innerAction; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Repeat); }; /** @brief Repeats an action for ever. @@ -189,20 +188,6 @@ class CC_DLL RepeatForever : public ActionInterval public: /** creates the action */ static RepeatForever* create(ActionInterval *pAction); - /** - * @js ctor - */ - RepeatForever() - : _innerAction(NULL) - {} - /** - * @js NA - * @lua NA - */ - virtual ~RepeatForever(); - - /** initializes the action */ - bool initWithAction(ActionInterval *pAction); inline void setInnerAction(ActionInterval *pAction) { @@ -229,8 +214,18 @@ public: virtual bool isDone(void) const override; protected: + RepeatForever() + : _innerAction(nullptr) + {} + virtual ~RepeatForever(); + /** initializes the action */ + bool initWithAction(ActionInterval *pAction); + /** Inner action */ ActionInterval *_innerAction; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(RepeatForever); }; /** @brief Spawn a new action immediately @@ -255,14 +250,6 @@ public: /** creates the Spawn action */ static Spawn* createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2); - /** - * @js NA - * @lua NA - */ - virtual ~Spawn(void); - - /** initializes the Spawn action with the 2 actions to spawn */ - bool initWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2); // // Overrides @@ -274,8 +261,16 @@ public: virtual void update(float time) override; protected: + Spawn() {} + virtual ~Spawn(); + /** initializes the Spawn action with the 2 actions to spawn */ + bool initWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2); + FiniteTimeAction *_one; FiniteTimeAction *_two; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Spawn); }; /** @brief Rotates a Node object to a certain angle by modifying it's @@ -290,10 +285,6 @@ public: /** creates the action */ static RotateTo* create(float fDuration, float fDeltaAngle); - /** initializes the action */ - bool initWithDuration(float fDuration, float fDeltaAngle); - - bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY); // // Overrides @@ -304,6 +295,12 @@ public: virtual void update(float time) override; protected: + RotateTo() {} + virtual ~RotateTo() {} + /** initializes the action */ + bool initWithDuration(float fDuration, float fDeltaAngle); + bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY); + float _dstAngleX; float _startAngleX; float _diffAngleX; @@ -311,6 +308,9 @@ protected: float _dstAngleY; float _startAngleY; float _diffAngleY; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(RotateTo); }; /** @brief Rotates a Node object clockwise a number of degrees by modifying it's rotation attribute. @@ -320,12 +320,7 @@ class CC_DLL RotateBy : public ActionInterval public: /** creates the action */ static RotateBy* create(float fDuration, float fDeltaAngle); - - /** initializes the action */ - bool initWithDuration(float fDuration, float fDeltaAngle); - static RotateBy* create(float fDuration, float fDeltaAngleX, float fDeltaAngleY); - bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY); // // Override @@ -336,10 +331,19 @@ public: virtual void update(float time) override; protected: + RotateBy() {} + virtual ~RotateBy() {} + /** initializes the action */ + bool initWithDuration(float fDuration, float fDeltaAngle); + bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY); + float _angleX; float _startAngleX; float _angleY; float _startAngleY; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(RotateBy); }; /** Moves a Node object x,y pixels by modifying it's position attribute. @@ -354,9 +358,6 @@ public: /** creates the action */ static MoveBy* create(float duration, const Point& deltaPosition); - /** initializes the action */ - bool initWithDuration(float duration, const Point& deltaPosition); - // // Overrides // @@ -366,9 +367,17 @@ public: virtual void update(float time) override; protected: + MoveBy() {} + virtual ~MoveBy() {} + /** initializes the action */ + bool initWithDuration(float duration, const Point& deltaPosition); + Point _positionDelta; Point _startPosition; Point _previousPosition; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MoveBy); }; /** Moves a Node object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. @@ -382,9 +391,6 @@ public: /** creates the action */ static MoveTo* create(float duration, const Point& position); - /** initializes the action */ - bool initWithDuration(float duration, const Point& position); - // // Overrides // @@ -392,7 +398,15 @@ public: virtual void startWithTarget(Node *target) override; protected: + MoveTo() {} + virtual ~MoveTo() {} + /** initializes the action */ + bool initWithDuration(float duration, const Point& position); + Point _endPosition; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(MoveTo); }; /** Skews a Node object to given angles by modifying it's skewX and skewY attributes @@ -404,9 +418,6 @@ public: /** creates the action */ static SkewTo* create(float t, float sx, float sy); - SkewTo(); - bool initWithDuration(float t, float sx, float sy); - // // Overrides // @@ -416,6 +427,10 @@ public: virtual void update(float time) override; protected: + SkewTo(); + virtual ~SkewTo() {} + bool initWithDuration(float t, float sx, float sy); + float _skewX; float _skewY; float _startSkewX; @@ -424,6 +439,9 @@ protected: float _endSkewY; float _deltaX; float _deltaY; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(SkewTo); }; /** Skews a Node object by skewX and skewY degrees @@ -435,14 +453,20 @@ public: /** creates the action */ static SkewBy* create(float t, float deltaSkewX, float deltaSkewY); - bool initWithDuration(float t, float sx, float sy); - // // Overrides // virtual void startWithTarget(Node *target) override; virtual SkewBy* clone() const override; virtual SkewBy* reverse(void) const override; + +protected: + SkewBy() {} + virtual ~SkewBy() {} + bool initWithDuration(float t, float sx, float sy); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(SkewBy); }; /** @brief Moves a Node object simulating a parabolic jump movement by modifying it's position attribute. @@ -453,9 +477,6 @@ public: /** creates the action */ static JumpBy* create(float duration, const Point& position, float height, int jumps); - /** initializes the action */ - bool initWithDuration(float duration, const Point& position, float height, int jumps); - // // Overrides // @@ -465,11 +486,19 @@ public: virtual void update(float time) override; protected: + JumpBy() {} + virtual ~JumpBy() {} + /** initializes the action */ + bool initWithDuration(float duration, const Point& position, float height, int jumps); + Point _startPosition; Point _delta; float _height; int _jumps; Point _previousPos; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(JumpBy); }; /** @brief Moves a Node object to a parabolic position simulating a jump movement by modifying it's position attribute. @@ -486,6 +515,11 @@ public: virtual void startWithTarget(Node *target) override; virtual JumpTo* clone() const override; virtual JumpTo* reverse(void) const override; + +private: + JumpTo() {} + virtual ~JumpTo() {} + CC_DISALLOW_COPY_AND_ASSIGN(JumpTo); }; /** Bezier configuration structure @@ -513,9 +547,6 @@ public: */ static BezierBy* create(float t, const ccBezierConfig& c); - /** initializes the action with a duration and a bezier configuration */ - bool initWithDuration(float t, const ccBezierConfig& c); - // // Overrides // @@ -525,9 +556,17 @@ public: virtual void update(float time) override; protected: + BezierBy() {} + virtual ~BezierBy() {} + /** initializes the action with a duration and a bezier configuration */ + bool initWithDuration(float t, const ccBezierConfig& c); + ccBezierConfig _config; Point _startPosition; Point _previousPosition; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(BezierBy); }; /** @brief An action that moves the target with a cubic Bezier curve to a destination point. @@ -544,7 +583,6 @@ public: * @endcode */ static BezierTo* create(float t, const ccBezierConfig& c); - bool initWithDuration(float t, const ccBezierConfig &c); // // Overrides @@ -554,7 +592,14 @@ public: virtual BezierTo* reverse(void) const override; protected: + BezierTo() {} + virtual ~BezierTo() {} + bool initWithDuration(float t, const ccBezierConfig &c); + ccBezierConfig _toConfig; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(BezierTo); }; /** @brief Scales a Node object to a zoom factor by modifying it's scale attribute. @@ -569,12 +614,6 @@ public: /** creates the action with and X factor and a Y factor */ static ScaleTo* create(float duration, float sx, float sy); - /** initializes the action with the same scale factor for X and Y */ - bool initWithDuration(float duration, float s); - - /** initializes the action with and X factor and a Y factor */ - bool initWithDuration(float duration, float sx, float sy); - // // Overrides // @@ -584,6 +623,13 @@ public: virtual void update(float time) override; protected: + ScaleTo() {} + virtual ~ScaleTo() {} + /** initializes the action with the same scale factor for X and Y */ + bool initWithDuration(float duration, float s); + /** initializes the action with and X factor and a Y factor */ + bool initWithDuration(float duration, float sx, float sy); + float _scaleX; float _scaleY; float _startScaleX; @@ -592,6 +638,9 @@ protected: float _endScaleY; float _deltaX; float _deltaY; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ScaleTo); }; /** @brief Scales a Node object a zoom factor by modifying it's scale attribute. @@ -611,6 +660,13 @@ public: virtual void startWithTarget(Node *target) override; virtual ScaleBy* clone() const override; virtual ScaleBy* reverse(void) const override; + +protected: + ScaleBy() {} + virtual ~ScaleBy() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ScaleBy); }; /** @brief Blinks a Node object by modifying it's visible attribute @@ -621,9 +677,6 @@ public: /** creates the action */ static Blink* create(float duration, int blinks); - /** initializes the action */ - bool initWithDuration(float duration, int blinks); - // // Overrides // @@ -634,8 +687,16 @@ public: virtual void stop() override; protected: + Blink() {} + virtual ~Blink() {} + /** initializes the action */ + bool initWithDuration(float duration, int blinks); + int _times; bool _originalState; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Blink); }; /** @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255. @@ -653,6 +714,13 @@ public: virtual void update(float time) override; virtual FadeIn* clone() const override; virtual ActionInterval* reverse(void) const override; + +protected: + FadeIn() {} + virtual ~FadeIn() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeIn); }; /** @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0. @@ -670,6 +738,13 @@ public: virtual void update(float time) override; virtual FadeOut* clone() const override; virtual ActionInterval* reverse(void) const override; + +protected: + FadeOut() {} + virtual ~FadeOut() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeOut); }; /** @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a custom one. @@ -681,9 +756,6 @@ public: /** creates an action with duration and opacity */ static FadeTo* create(float duration, GLubyte opacity); - /** initializes the action with duration and opacity */ - bool initWithDuration(float duration, GLubyte opacity); - // // Overrides // @@ -693,8 +765,16 @@ public: virtual void update(float time) override; protected: + FadeTo() {} + virtual ~FadeTo() {} + /** initializes the action with duration and opacity */ + bool initWithDuration(float duration, GLubyte opacity); + GLubyte _toOpacity; GLubyte _fromOpacity; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeTo); }; /** @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one. @@ -707,9 +787,6 @@ public: /** creates an action with duration and color */ static TintTo* create(float duration, GLubyte red, GLubyte green, GLubyte blue); - /** initializes the action with duration and color */ - bool initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue); - // // Overrides // @@ -719,8 +796,16 @@ public: virtual void update(float time) override; protected: + TintTo() {} + virtual ~TintTo() {} + /** initializes the action with duration and color */ + bool initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue); + Color3B _to; Color3B _from; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TintTo); }; /** @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one. @@ -732,9 +817,6 @@ public: /** creates an action with duration and color */ static TintBy* create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue); - /** initializes the action with duration and color */ - bool initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue); - // // Overrides // @@ -744,6 +826,11 @@ public: virtual void update(float time) override; protected: + TintBy() {} + virtual ~TintBy() {} + /** initializes the action with duration and color */ + bool initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue); + GLshort _deltaR; GLshort _deltaG; GLshort _deltaB; @@ -751,6 +838,9 @@ protected: GLshort _fromR; GLshort _fromG; GLshort _fromB; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TintBy); }; /** @brief Delays the action a certain amount of seconds @@ -767,6 +857,13 @@ public: virtual void update(float time) override; virtual DelayTime* reverse() const override; virtual DelayTime* clone() const override; + +protected: + DelayTime() {} + virtual ~DelayTime() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(DelayTime); }; /** @brief Executes an action in reverse order, from time=duration to time=0 @@ -781,18 +878,6 @@ class CC_DLL ReverseTime : public ActionInterval public: /** creates the action */ static ReverseTime* create(FiniteTimeAction *pAction); - /** - * @js NA - * @lua NA - */ - virtual ~ReverseTime(void); - /** - * @js ctor - */ - ReverseTime(); - - /** initializes the action */ - bool initWithAction(FiniteTimeAction *pAction); // // Overrides @@ -804,7 +889,15 @@ public: virtual void update(float time) override; protected: + ReverseTime(); + virtual ~ReverseTime(void); + /** initializes the action */ + bool initWithAction(FiniteTimeAction *pAction); + FiniteTimeAction *_other; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ReverseTime); }; class Texture2D; @@ -814,18 +907,6 @@ class CC_DLL Animate : public ActionInterval public: /** creates the action with an Animation and will restore the original frame when the animation is over */ static Animate* create(Animation *pAnimation); - /** - * @js ctor - */ - Animate(); - /** - * @js NA - * @lua NA - */ - virtual ~Animate(); - - /** initializes the action with an Animation and will restore the original frame when the animation is over */ - bool initWithAnimation(Animation *pAnimation); /** sets the Animation object to be animated */ void setAnimation( Animation* animation ); @@ -843,11 +924,19 @@ public: virtual void update(float t) override; protected: + Animate(); + virtual ~Animate(); + /** initializes the action with an Animation and will restore the original frame when the animation is over */ + bool initWithAnimation(Animation *pAnimation); + std::vector* _splitTimes; int _nextFrame; SpriteFrame* _origFrame; unsigned int _executedLoops; Animation* _animation; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Animate); }; /** Overrides the target of an action so that it always runs on the target @@ -856,22 +945,9 @@ protected: class CC_DLL TargetedAction : public ActionInterval { public: - /** - * @js ctor - */ - TargetedAction(); - /** - * @js NA - * @lua NA - */ - virtual ~TargetedAction(); - /** Create an action with the specified action and forced target */ static TargetedAction* create(Node* target, FiniteTimeAction* pAction); - /** Init an action with the specified action and forced target */ - bool initWithTarget(Node* target, FiniteTimeAction* pAction); - /** Sets the target that the action will be forced to run with */ void setForcedTarget(Node* forcedTarget); /** returns the target that the action is forced to run with */ @@ -887,9 +963,17 @@ public: virtual void stop(void) override; virtual void update(float time) override; -private: +protected: + TargetedAction(); + virtual ~TargetedAction(); + /** Init an action with the specified action and forced target */ + bool initWithTarget(Node* target, FiniteTimeAction* pAction); + FiniteTimeAction* _action; Node* _forcedTarget; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TargetedAction); }; // end of actions group From 4d7e56b44abefbdb1967f84a010e2fdd15d4b324 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 09:42:21 -0800 Subject: [PATCH 14/28] fix indentation --- cocos/2d/CCGLProgram.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCGLProgram.h b/cocos/2d/CCGLProgram.h index c7b6b2728c..2d66baf3bb 100644 --- a/cocos/2d/CCGLProgram.h +++ b/cocos/2d/CCGLProgram.h @@ -251,7 +251,7 @@ private: GLint _uniforms[UNIFORM_MAX]; struct _hashUniformEntry* _hashForUniforms; - struct flag_struct { + struct flag_struct { unsigned int usesTime:1; unsigned int usesMVP:1; unsigned int usesMV:1; From 1c65669a9f845977d1075a9f8c0b098726fd9291 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 11:27:03 -0800 Subject: [PATCH 15/28] fixes type in documentation --- samples/Cpp/TestCpp/Classes/testBasic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index e47dcd24a0..013b5d8563 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -33,7 +33,7 @@ void TestScene::onEnter() /* ****** GCC Compiler issue on Android and Linux (CLANG compiler is ok) ****** We couldn't use 'Scene::create' directly since gcc will trigger - an error called "error: 'this' was not captured for this lambda function". + an error called "error: 'this' was not captured for this lambda function". This is because 'Scene' is the super class of TestScene, if we invoke 'Scene::create' directly in this lambda expression, gcc compiler found 'Scene::create' and it think that was the member function of 'TestScene' 's super class, but this lambda function doesn't From 3ab1e4f3a1ed012d04f77df447601b19cc13a8d5 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 12:15:41 -0800 Subject: [PATCH 16/28] ClippingNode Test works again --- .../ClippingNodeTest/ClippingNodeTest.cpp | 57 ++++++++----------- .../ConfigurationTest/ConfigurationTest.cpp | 18 ++---- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 19 ++----- .../Classes/SchedulerTest/SchedulerTest.cpp | 51 ++++++----------- samples/Cpp/TestCpp/Classes/testBasic.h | 7 --- 5 files changed, 53 insertions(+), 99 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index 84bbf9eb15..30e94367eb 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -16,36 +16,21 @@ enum { kTagContentNode = 102, }; -TESTLAYER_CREATE_FUNC(ScrollViewDemo); -TESTLAYER_CREATE_FUNC(HoleDemo); -TESTLAYER_CREATE_FUNC(ShapeTest); -TESTLAYER_CREATE_FUNC(ShapeInvertedTest); -TESTLAYER_CREATE_FUNC(SpriteTest); -TESTLAYER_CREATE_FUNC(SpriteNoAlphaTest); -TESTLAYER_CREATE_FUNC(SpriteInvertedTest); -TESTLAYER_CREATE_FUNC(NestedTest); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest2); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest3); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest4); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest5); -TESTLAYER_CREATE_FUNC(RawStencilBufferTest6); - -static NEWTESTFUNC createFunctions[] = { - CF(ScrollViewDemo), - CF(HoleDemo), - CF(ShapeTest), - CF(ShapeInvertedTest), - CF(SpriteTest), - CF(SpriteNoAlphaTest), - CF(SpriteInvertedTest), - CF(NestedTest), - CF(RawStencilBufferTest), - CF(RawStencilBufferTest2), - CF(RawStencilBufferTest3), - CF(RawStencilBufferTest4), - CF(RawStencilBufferTest5), - CF(RawStencilBufferTest6) +static std::function createFunctions[] = { + CL(ScrollViewDemo), + CL(HoleDemo), + CL(ShapeTest), + CL(ShapeInvertedTest), + CL(SpriteTest), + CL(SpriteNoAlphaTest), + CL(SpriteInvertedTest), + CL(NestedTest), + CL(RawStencilBufferTest), + CL(RawStencilBufferTest2), + CL(RawStencilBufferTest3), + CL(RawStencilBufferTest4), + CL(RawStencilBufferTest5), + CL(RawStencilBufferTest6) }; static int sceneIdx=-1; @@ -57,6 +42,7 @@ static Layer* nextAction() sceneIdx = sceneIdx % MAX_LAYER; auto layer = (createFunctions[sceneIdx])(); + return layer; } @@ -68,12 +54,14 @@ static Layer* backAction() sceneIdx += total; auto layer = (createFunctions[sceneIdx])(); + return layer; } static Layer* restartAction() { auto layer = (createFunctions[sceneIdx])(); + return layer; } @@ -113,23 +101,26 @@ std::string BaseClippingNodeTest::subtitle() void BaseClippingNodeTest::restartCallback(Object* sender) { - Scene *s = ClippingNodeTestScene::create(); + Scene *s = new ClippingNodeTestScene(); s->addChild(restartAction()); Director::getInstance()->replaceScene(s); + s->release(); } void BaseClippingNodeTest::nextCallback(Object* sender) { - Scene *s = ClippingNodeTestScene::create(); + Scene *s = new ClippingNodeTestScene(); s->addChild(nextAction()); Director::getInstance()->replaceScene(s); + s->release(); } void BaseClippingNodeTest::backCallback(Object* sender) { - Scene *s = ClippingNodeTestScene::create(); + Scene *s = new ClippingNodeTestScene(); s->addChild(backAction()); Director::getInstance()->replaceScene(s); + s->release(); } void BaseClippingNodeTest::setup() diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp index fa9b5b7a4c..7df99cf60e 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp @@ -3,18 +3,12 @@ #include "../testResource.h" #include "cocos2d.h" -TESTLAYER_CREATE_FUNC(ConfigurationLoadConfig); -TESTLAYER_CREATE_FUNC(ConfigurationQuery); -TESTLAYER_CREATE_FUNC(ConfigurationInvalid); -TESTLAYER_CREATE_FUNC(ConfigurationDefault); -TESTLAYER_CREATE_FUNC(ConfigurationSet); - -static NEWTESTFUNC createFunctions[] = { - CF(ConfigurationLoadConfig), - CF(ConfigurationQuery), - CF(ConfigurationInvalid), - CF(ConfigurationDefault), - CF(ConfigurationSet) +static std::function createFunctions[] = { + CL(ConfigurationLoadConfig), + CL(ConfigurationQuery), + CL(ConfigurationInvalid), + CL(ConfigurationDefault), + CL(ConfigurationSet) }; static int sceneIdx=-1; diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp index 66d15719ce..bc2737edf6 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -1,18 +1,11 @@ #include "FileUtilsTest.h" - -TESTLAYER_CREATE_FUNC(TestResolutionDirectories); -TESTLAYER_CREATE_FUNC(TestSearchPath); -TESTLAYER_CREATE_FUNC(TestFilenameLookup); -TESTLAYER_CREATE_FUNC(TestIsFileExist); -TESTLAYER_CREATE_FUNC(TextWritePlist); - -static NEWTESTFUNC createFunctions[] = { - CF(TestResolutionDirectories), - CF(TestSearchPath), - CF(TestFilenameLookup), - CF(TestIsFileExist), - CF(TextWritePlist), +static std::function createFunctions[] = { + CL(TestResolutionDirectories), + CL(TestSearchPath), + CL(TestFilenameLookup), + CL(TestIsFileExist), + CL(TextWritePlist), }; static int sceneIdx=-1; diff --git a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp index 0ede17cec3..1da50ad4ca 100644 --- a/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SchedulerTest/SchedulerTest.cpp @@ -11,40 +11,23 @@ Layer* nextSchedulerTest(); Layer* backSchedulerTest(); Layer* restartSchedulerTest(); -TESTLAYER_CREATE_FUNC(SchedulerTimeScale) -TESTLAYER_CREATE_FUNC(TwoSchedulers) -TESTLAYER_CREATE_FUNC(SchedulerAutoremove) -TESTLAYER_CREATE_FUNC(SchedulerPauseResume) -TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAll) -TESTLAYER_CREATE_FUNC(SchedulerPauseResumeAllUser) -TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAll) -TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllHard) -TESTLAYER_CREATE_FUNC(SchedulerUnscheduleAllUserLevel) -TESTLAYER_CREATE_FUNC(SchedulerSchedulesAndRemove) -TESTLAYER_CREATE_FUNC(SchedulerUpdate) -TESTLAYER_CREATE_FUNC(SchedulerUpdateAndCustom) -TESTLAYER_CREATE_FUNC(SchedulerUpdateFromCustom) -TESTLAYER_CREATE_FUNC(RescheduleSelector) -TESTLAYER_CREATE_FUNC(SchedulerDelayAndRepeat) -TESTLAYER_CREATE_FUNC(SchedulerIssue2268) - -static NEWTESTFUNC createFunctions[] = { - CF(SchedulerTimeScale), - CF(TwoSchedulers), - CF(SchedulerAutoremove), - CF(SchedulerPauseResume), - CF(SchedulerPauseResumeAll), - CF(SchedulerPauseResumeAllUser), - CF(SchedulerUnscheduleAll), - CF(SchedulerUnscheduleAllHard), - CF(SchedulerUnscheduleAllUserLevel), - CF(SchedulerSchedulesAndRemove), - CF(SchedulerUpdate), - CF(SchedulerUpdateAndCustom), - CF(SchedulerUpdateFromCustom), - CF(RescheduleSelector), - CF(SchedulerDelayAndRepeat), - CF(SchedulerIssue2268) +static std::function createFunctions[] = { + CL(SchedulerTimeScale), + CL(TwoSchedulers), + CL(SchedulerAutoremove), + CL(SchedulerPauseResume), + CL(SchedulerPauseResumeAll), + CL(SchedulerPauseResumeAllUser), + CL(SchedulerUnscheduleAll), + CL(SchedulerUnscheduleAllHard), + CL(SchedulerUnscheduleAllUserLevel), + CL(SchedulerSchedulesAndRemove), + CL(SchedulerUpdate), + CL(SchedulerUpdateAndCustom), + CL(SchedulerUpdateFromCustom), + CL(RescheduleSelector), + CL(SchedulerDelayAndRepeat), + CL(SchedulerIssue2268) }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) diff --git a/samples/Cpp/TestCpp/Classes/testBasic.h b/samples/Cpp/TestCpp/Classes/testBasic.h index 46e07e2c1c..e6ddd8f9f3 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.h +++ b/samples/Cpp/TestCpp/Classes/testBasic.h @@ -17,13 +17,6 @@ public: virtual void runThisTest() = 0; }; -typedef Layer* (*NEWTESTFUNC)(); -#define TESTLAYER_CREATE_FUNC(className) \ -static Layer* create##className() \ -{ return new className(); } - -#define CF(className) create##className - // C++ 11 #define CL(__className__) [](){ return __className__::create();} From 72436c896a69d08b5c8ef6f8adb02a2e8dc0987e Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 13:40:32 -0800 Subject: [PATCH 17/28] prevents bug in gcc 4.6.3 --- samples/Cpp/TestCpp/Classes/testBasic.cpp | 45 ++++++++--------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index 013b5d8563..cffd5acbef 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -19,6 +19,19 @@ TestScene::TestScene(bool bPortrait, bool physics/* = false*/) } } +void testScene_callback( Object *sender ) +{ + auto scene = Scene::create(); + + auto layer = new TestController(); + scene->addChild(layer); + layer->release(); + + Director::getInstance()->replaceScene(scene); + + cocostudio::ArmatureDataManager::destoryInstance(); +} + void TestScene::onEnter() { Scene::onEnter(); @@ -29,36 +42,8 @@ void TestScene::onEnter() //#else auto label = LabelTTF::create("MainMenu", "Arial", 20); //#endif - auto menuItem = MenuItemLabel::create(label, [](Object *sender) { - /* - ****** GCC Compiler issue on Android and Linux (CLANG compiler is ok) ****** - We couldn't use 'Scene::create' directly since gcc will trigger - an error called "error: 'this' was not captured for this lambda function". - This is because 'Scene' is the super class of TestScene, if we invoke 'Scene::create' - directly in this lambda expression, gcc compiler found 'Scene::create' and it think - that was the member function of 'TestScene' 's super class, but this lambda function doesn't - capture anything like 'this', so it has no access to invoke 'Scene::create'. - - Solution (1): Passing 'this' to this lambda function. - Solution (2): Don't use 'Scene::create' and don't pass 'this' to this lambda function, - instead, we just need to new the 'Scene' and initialize the Scene. - - Semantically, I think in this lambda function, we shouldn't capture any varibles - outside the scope. So I choose the (2) solution. Commented by James Chen. - */ - - auto scene = Scene::create(); - - auto layer = new TestController(); - scene->addChild(layer); - layer->release(); - - Director::getInstance()->replaceScene(scene); - - cocostudio::ArmatureDataManager::destoryInstance(); - }); - - auto menu =Menu::create(menuItem, NULL); + auto menuItem = MenuItemLabel::create(label, testScene_callback ); + auto menu = Menu::create(menuItem, NULL); menu->setPosition( Point::ZERO ); menuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) ); From 3f1983214f4d03e1e1cbe217cd204a8e2b740815 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 15:07:58 -0800 Subject: [PATCH 18/28] Effects have protected contructors and disallowed copy + assign --- cocos/2d/CCActionGrid.h | 84 ++++--- cocos/2d/CCActionGrid3D.h | 93 +++++-- cocos/2d/CCActionProgressTimer.h | 22 +- cocos/2d/CCActionTiledGrid.h | 124 +++++++--- cocos/2d/CCTransition.h | 410 +++++++++++++------------------ 5 files changed, 398 insertions(+), 335 deletions(-) diff --git a/cocos/2d/CCActionGrid.h b/cocos/2d/CCActionGrid.h index c3daac990d..eb9ddc23a5 100644 --- a/cocos/2d/CCActionGrid.h +++ b/cocos/2d/CCActionGrid.h @@ -41,8 +41,6 @@ class GridBase; class CC_DLL GridAction : public ActionInterval { public: - /** initializes the action with size and duration */ - bool initWithDuration(float duration, const Size& gridSize); /** returns the grid */ virtual GridBase* getGrid(); @@ -53,7 +51,15 @@ public: virtual void startWithTarget(Node *target) override; protected: + GridAction() {} + virtual ~GridAction() {} + /** initializes the action with size and duration */ + bool initWithDuration(float duration, const Size& gridSize); + Size _gridSize; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(GridAction); }; /** @@ -153,18 +159,6 @@ class CC_DLL AccelDeccelAmplitude : public ActionInterval public: /** creates the action with an inner action that has the amplitude property, and a duration time */ static AccelDeccelAmplitude* create(Action *action, float duration); - /** - * @js NA - * @lua NA - */ - virtual ~AccelDeccelAmplitude(); - /** initializes the action with an inner action that has the amplitude property, and a duration time */ - bool initWithAction(Action *pAction, float duration); - - /** returns a new clone of the action */ - virtual AccelDeccelAmplitude* clone() const; - /** returns a new reversed action */ - virtual AccelDeccelAmplitude* reverse() const; /** get amplitude rate */ inline float getRate(void) const { return _rate; } @@ -174,10 +168,20 @@ public: // Overrides virtual void startWithTarget(Node *target) override; virtual void update(float time) override; + virtual AccelDeccelAmplitude* clone() const override; + virtual AccelDeccelAmplitude* reverse() const override; protected: + AccelDeccelAmplitude() {} + virtual ~AccelDeccelAmplitude(); + /** initializes the action with an inner action that has the amplitude property, and a duration time */ + bool initWithAction(Action *pAction, float duration); + float _rate; ActionInterval *_other; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(AccelDeccelAmplitude); }; /** @brief AccelAmplitude action */ @@ -186,14 +190,6 @@ class CC_DLL AccelAmplitude : public ActionInterval public: /** creates the action with an inner action that has the amplitude property, and a duration time */ static AccelAmplitude* create(Action *action, float duration); - /** - * @js NA - * @lua NA - */ - virtual ~AccelAmplitude(); - - /** initializes the action with an inner action that has the amplitude property, and a duration time */ - bool initWithAction(Action *action, float duration); /** get amplitude rate */ inline float getRate() const { return _rate; } @@ -207,8 +203,15 @@ public: virtual AccelAmplitude* reverse() const override; protected: + AccelAmplitude() {} + virtual ~AccelAmplitude(); + bool initWithAction(Action *action, float duration); + float _rate; ActionInterval *_other; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(AccelAmplitude); }; /** @brief DeccelAmplitude action */ @@ -217,13 +220,6 @@ class CC_DLL DeccelAmplitude : public ActionInterval public: /** creates the action with an inner action that has the amplitude property, and a duration time */ static DeccelAmplitude* create(Action *action, float duration); - /** - * @js NA - * @lua NA - */ - virtual ~DeccelAmplitude(); - /** initializes the action with an inner action that has the amplitude property, and a duration time */ - bool initWithAction(Action *action, float duration); /** get amplitude rate */ inline float getRate(void) const { return _rate; } @@ -233,12 +229,20 @@ public: // overrides virtual void startWithTarget(Node *target) override; virtual void update(float time) override; - virtual DeccelAmplitude* clone() const; - virtual DeccelAmplitude* reverse() const; + virtual DeccelAmplitude* clone() const override; + virtual DeccelAmplitude* reverse() const override; protected: + DeccelAmplitude() {} + virtual ~DeccelAmplitude(); + /** initializes the action with an inner action that has the amplitude property, and a duration time */ + bool initWithAction(Action *action, float duration); + float _rate; ActionInterval *_other; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(DeccelAmplitude); }; /** @brief StopGrid action. @@ -256,6 +260,13 @@ public: virtual void startWithTarget(Node *target) override; virtual StopGrid* clone() const override; virtual StopGrid* reverse() const override; + +protected: + StopGrid() {} + virtual ~StopGrid() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(StopGrid); }; /** @brief ReuseGrid action */ @@ -265,16 +276,21 @@ public: /** creates an action with the number of times that the current grid will be reused */ static ReuseGrid* create(int times); - /** initializes an action with the number of times that the current grid will be reused */ - bool initWithTimes(int times); - // Override virtual void startWithTarget(Node *target) override; virtual ReuseGrid* clone() const override; virtual ReuseGrid* reverse() const override; protected: + ReuseGrid() {} + virtual ~ReuseGrid() {} + /** initializes an action with the number of times that the current grid will be reused */ + bool initWithTimes(int times); + int _times; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ReuseGrid); }; // end of actions group diff --git a/cocos/2d/CCActionGrid3D.h b/cocos/2d/CCActionGrid3D.h index 57f868ca55..fbc82f4819 100644 --- a/cocos/2d/CCActionGrid3D.h +++ b/cocos/2d/CCActionGrid3D.h @@ -53,17 +53,22 @@ public: /** sets the ampliture rate */ inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } - /** initializes an action with duration, grid size, waves and amplitude */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); - // Overrides virtual Waves3D* clone() const override; virtual void update(float time) override; protected: + Waves3D() {} + virtual ~Waves3D() {} + /** initializes an action with duration, grid size, waves and amplitude */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); + unsigned int _waves; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Waves3D); }; /** @brief FlipX3D action */ @@ -73,25 +78,36 @@ public: /** creates the action with duration */ static FlipX3D* create(float duration); + // Override + virtual FlipX3D* clone() const override; + virtual void update(float time) override; + +protected: + FlipX3D() {} + virtual ~FlipX3D() {} /** initializes the action with duration */ bool initWithDuration(float duration); virtual bool initWithSize(const Size& gridSize, float duration); - // Override - virtual FlipX3D* clone() const override; - virtual void update(float time) override; +private: + CC_DISALLOW_COPY_AND_ASSIGN(FlipX3D); }; /** @brief FlipY3D action */ class CC_DLL FlipY3D : public FlipX3D { public: + FlipY3D() {} + virtual ~FlipY3D() {} /** creates the action with duration */ static FlipY3D* create(float duration); // Overrides virtual void update(float time) override; virtual FlipY3D* clone() const override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FlipY3D); }; /** @brief Lens3D action */ @@ -111,14 +127,16 @@ public: inline const Point& getPosition() const { return _position; } void setPosition(const Point& position); - /** initializes the action with center position, radius, a grid size and duration */ - bool initWithDuration(float duration, const Size& gridSize, const Point& position, float radius); - // Overrides virtual Lens3D* clone() const override; virtual void update(float time) override; protected: + Lens3D() {} + virtual ~Lens3D() {} + /** initializes the action with center position, radius, a grid size and duration */ + bool initWithDuration(float duration, const Size& gridSize, const Point& position, float radius); + /* lens center position */ Point _position; float _radius; @@ -128,6 +146,9 @@ protected: bool _concave; bool _dirty; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Lens3D); }; /** @brief Ripple3D action */ @@ -148,45 +169,57 @@ public: inline float getAmplitudeRate() const { return _amplitudeRate; } inline void setAmplitudeRate(float fAmplitudeRate) { _amplitudeRate = fAmplitudeRate; } - /** initializes the action with radius, number of waves, amplitude, a grid size and duration */ - bool initWithDuration(float duration, const Size& gridSize, const Point& position, float radius, unsigned int waves, float amplitude); - // Override virtual Ripple3D* clone() const override; virtual void update(float time) override; protected: + Ripple3D() {} + virtual ~Ripple3D() {} + /** initializes the action with radius, number of waves, amplitude, a grid size and duration */ + bool initWithDuration(float duration, const Size& gridSize, const Point& position, float radius, unsigned int waves, float amplitude); + /* center position */ Point _position; float _radius; unsigned int _waves; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Ripple3D); }; /** @brief Shaky3D action */ class CC_DLL Shaky3D : public Grid3DAction { public: + Shaky3D() {} + virtual ~Shaky3D() {} /** creates the action with a range, shake Z vertices, a grid and duration */ static Shaky3D* create(float duration, const Size& gridSize, int range, bool shakeZ); - /** initializes the action with a range, shake Z vertices, a grid and duration */ - bool initWithDuration(float duration, const Size& gridSize, int range, bool shakeZ); - // Overrides virtual Shaky3D* clone() const override; virtual void update(float time) override; protected: + /** initializes the action with a range, shake Z vertices, a grid and duration */ + bool initWithDuration(float duration, const Size& gridSize, int range, bool shakeZ); + int _randrange; bool _shakeZ; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Shaky3D); }; /** @brief Liquid action */ class CC_DLL Liquid : public Grid3DAction { public: + Liquid() {} + virtual ~Liquid() {} /** creates the action with amplitude, a grid and duration */ static Liquid* create(float duration, const Size& gridSize, unsigned int waves, float amplitude); @@ -196,23 +229,28 @@ public: inline float getAmplitudeRate() const { return _amplitudeRate; } inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } - /** initializes the action with amplitude, a grid and duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); - // Overrides virtual Liquid* clone() const override; virtual void update(float time) override; protected: + /** initializes the action with amplitude, a grid and duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); + unsigned int _waves; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Liquid); }; /** @brief Waves action */ class CC_DLL Waves : public Grid3DAction { public: + Waves() {} + virtual ~Waves() {} /** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ static Waves* create(float duration, const Size& gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical); @@ -222,25 +260,30 @@ public: inline float getAmplitudeRate() const { return _amplitudeRate; } inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } - /** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical); - // Overrides virtual Waves* clone() const override; virtual void update(float time) override; protected: + /** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical); + unsigned int _waves; float _amplitude; float _amplitudeRate; bool _vertical; bool _horizontal; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Waves); }; /** @brief Twirl action */ class CC_DLL Twirl : public Grid3DAction { public: + Twirl() {} + virtual ~Twirl() {} /** creates the action with center position, number of twirls, amplitude, a grid size and duration */ static Twirl* create(float duration, const Size& gridSize, Point position, unsigned int twirls, float amplitude); @@ -255,19 +298,23 @@ public: inline float getAmplitudeRate() const { return _amplitudeRate; } inline void setAmplitudeRate(float amplitudeRate) { _amplitudeRate = amplitudeRate; } - /** initializes the action with center position, number of twirls, amplitude, a grid size and duration */ - bool initWithDuration(float duration, const Size& gridSize, Point position, unsigned int twirls, float amplitude); // Overrides virtual Twirl* clone() const override; virtual void update(float time) override; protected: + /** initializes the action with center position, number of twirls, amplitude, a grid size and duration */ + bool initWithDuration(float duration, const Size& gridSize, Point position, unsigned int twirls, float amplitude); + /* twirl center */ Point _position; unsigned int _twirls; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(Twirl); }; // end of actions group diff --git a/cocos/2d/CCActionProgressTimer.h b/cocos/2d/CCActionProgressTimer.h index de8c2c9c09..dc41237a48 100644 --- a/cocos/2d/CCActionProgressTimer.h +++ b/cocos/2d/CCActionProgressTimer.h @@ -44,9 +44,6 @@ public: /** Creates and initializes with a duration and a percent */ static ProgressTo* create(float duration, float fPercent); - /** Initializes with a duration and a percent */ - bool initWithDuration(float duration, float fPercent); - // // Overrides // @@ -56,8 +53,16 @@ public: virtual void update(float time) override; protected: + ProgressTo() {} + virtual ~ProgressTo() {} + /** Initializes with a duration and a percent */ + bool initWithDuration(float duration, float fPercent); + float _to; float _from; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ProgressTo); }; /** @@ -70,9 +75,6 @@ public: /** Creates and initializes the action with a duration, a "from" percentage and a "to" percentage */ static ProgressFromTo* create(float duration, float fFromPercentage, float fToPercentage); - /** Initializes the action with a duration, a "from" percentage and a "to" percentage */ - bool initWithDuration(float duration, float fFromPercentage, float fToPercentage); - // // Overrides // @@ -82,8 +84,16 @@ public: virtual void update(float time) override; protected: + ProgressFromTo() {} + virtual ~ProgressFromTo() {} + /** Initializes the action with a duration, a "from" percentage and a "to" percentage */ + bool initWithDuration(float duration, float fFromPercentage, float fToPercentage); + float _to; float _from; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ProgressFromTo); }; // end of actions group diff --git a/cocos/2d/CCActionTiledGrid.h b/cocos/2d/CCActionTiledGrid.h index e1471f1ea8..ca4dd786a6 100644 --- a/cocos/2d/CCActionTiledGrid.h +++ b/cocos/2d/CCActionTiledGrid.h @@ -41,16 +41,21 @@ public: /** creates the action with a range, whether or not to shake Z vertices, a grid size, and duration */ static ShakyTiles3D* create(float duration, const Size& gridSize, int nRange, bool bShakeZ); - /** initializes the action with a range, whether or not to shake Z vertices, a grid size, and duration */ - bool initWithDuration(float duration, const Size& gridSize, int nRange, bool bShakeZ); - // Override virtual ShakyTiles3D* clone() const override; virtual void update(float time) override; protected: + ShakyTiles3D() {} + virtual ~ShakyTiles3D() {} + /** initializes the action with a range, whether or not to shake Z vertices, a grid size, and duration */ + bool initWithDuration(float duration, const Size& gridSize, int nRange, bool bShakeZ); + int _randrange; bool _shakeZ; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ShakyTiles3D); }; /** @brief ShatteredTiles3D action */ @@ -60,17 +65,22 @@ public: /** creates the action with a range, whether of not to shatter Z vertices, a grid size and duration */ static ShatteredTiles3D* create(float duration, const Size& gridSize, int nRange, bool bShatterZ); - /** initializes the action with a range, whether or not to shatter Z vertices, a grid size and duration */ - bool initWithDuration(float duration, const Size& gridSize, int nRange, bool bShatterZ); - // Override virtual ShatteredTiles3D* clone() const override; virtual void update(float time) override; protected: + ShatteredTiles3D() {} + virtual ~ShatteredTiles3D() {} + /** initializes the action with a range, whether or not to shatter Z vertices, a grid size and duration */ + bool initWithDuration(float duration, const Size& gridSize, int nRange, bool bShatterZ); + int _randrange; bool _once; bool _shatterZ; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ShatteredTiles3D); }; struct Tile; @@ -82,13 +92,6 @@ class CC_DLL ShuffleTiles : public TiledGrid3DAction public: /** creates the action with a random seed, the grid size and the duration */ static ShuffleTiles* create(float duration, const Size& gridSize, unsigned int seed); - /** - * @js NA - * @lua NA - */ - virtual ~ShuffleTiles(void); - /** initializes the action with a random seed, the grid size and the duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int seed); void shuffle(unsigned int *array, unsigned int nLen); Size getDelta(const Size& pos) const; @@ -100,10 +103,18 @@ public: virtual ShuffleTiles* clone() const override; protected: + ShuffleTiles() {} + virtual ~ShuffleTiles(); + /** initializes the action with a random seed, the grid size and the duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int seed); + unsigned int _seed; unsigned int _tilesCount; unsigned int* _tilesOrder; Tile* _tiles; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(ShuffleTiles); }; /** @brief FadeOutTRTiles action @@ -123,6 +134,13 @@ public: // Overrides virtual void update(float time) override; virtual FadeOutTRTiles* clone() const override; + +protected: + FadeOutTRTiles() {} + virtual ~FadeOutTRTiles() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeOutTRTiles); }; /** @brief FadeOutBLTiles action. @@ -137,6 +155,13 @@ public: // Overrides virtual float testFunc(const Size& pos, float time) override; virtual FadeOutBLTiles* clone() const override; + +protected: + FadeOutBLTiles() {} + virtual ~FadeOutBLTiles() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeOutBLTiles); }; /** @brief FadeOutUpTiles action. @@ -153,6 +178,13 @@ public: // Overrides virtual FadeOutUpTiles* clone() const override; virtual float testFunc(const Size& pos, float time) override; + +protected: + FadeOutUpTiles() {} + virtual ~FadeOutUpTiles() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeOutUpTiles); }; /** @brief FadeOutDownTiles action. @@ -167,6 +199,13 @@ public: // Overrides virtual FadeOutDownTiles* clone() const override; virtual float testFunc(const Size& pos, float time) override; + +protected: + FadeOutDownTiles() {} + virtual ~FadeOutDownTiles() {} + +private: + CC_DISALLOW_COPY_AND_ASSIGN(FadeOutDownTiles); }; /** @brief TurnOffTiles action. @@ -179,13 +218,6 @@ public: static TurnOffTiles* create(float duration, const Size& gridSize); /** creates the action with a random seed, the grid size and the duration */ static TurnOffTiles* create(float duration, const Size& gridSize, unsigned int seed); - /** - * @js NA - * @lua NA - */ - ~TurnOffTiles(void); - /** initializes the action with a random seed, the grid size and the duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int seed); void shuffle(unsigned int *pArray, unsigned int nLen); void turnOnTile(const Point& pos); @@ -197,9 +229,17 @@ public: virtual void update(float time) override; protected: + TurnOffTiles() {} + virtual ~TurnOffTiles(); + /** initializes the action with a random seed, the grid size and the duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int seed); + unsigned int _seed; unsigned int _tilesCount; unsigned int* _tilesOrder; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TurnOffTiles); }; /** @brief WavesTiles3D action. */ @@ -209,9 +249,6 @@ public: /** creates the action with a number of waves, the waves amplitude, the grid size and the duration */ static WavesTiles3D* create(float duration, const Size& gridSize, unsigned int waves, float amplitude); - /** initializes the action with a number of waves, the waves amplitude, the grid size and the duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); - /** waves amplitude */ inline float getAmplitude(void) const { return _amplitude; } inline void setAmplitude(float fAmplitude) { _amplitude = fAmplitude; } @@ -225,9 +262,17 @@ public: virtual void update(float time) override; protected: + WavesTiles3D() {} + virtual ~WavesTiles3D() {} + /** initializes the action with a number of waves, the waves amplitude, the grid size and the duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude); + unsigned int _waves; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(WavesTiles3D); }; /** @brief JumpTiles3D action. @@ -239,9 +284,6 @@ public: /** creates the action with the number of jumps, the sin amplitude, the grid size and the duration */ static JumpTiles3D* create(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude); - /** initializes the action with the number of jumps, the sin amplitude, the grid size and the duration */ - bool initWithDuration(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude); - /** amplitude of the sin*/ inline float getAmplitude(void) const { return _amplitude; } inline void setAmplitude(float fAmplitude) { _amplitude = fAmplitude; } @@ -255,9 +297,17 @@ public: virtual void update(float time) override; protected: + JumpTiles3D() {} + virtual ~JumpTiles3D() {} + /** initializes the action with the number of jumps, the sin amplitude, the grid size and the duration */ + bool initWithDuration(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude); + unsigned int _jumps; float _amplitude; float _amplitudeRate; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(JumpTiles3D); }; /** @brief SplitRows action */ @@ -267,17 +317,22 @@ public : /** creates the action with the number of rows to split and the duration */ static SplitRows* create(float duration, unsigned int nRows); - /** initializes the action with the number of rows to split and the duration */ - bool initWithDuration(float duration, unsigned int nRows); - // Overrides virtual SplitRows* clone() const override; virtual void update(float time) override; virtual void startWithTarget(Node *target) override; protected: + SplitRows() {} + virtual ~SplitRows() {} + /** initializes the action with the number of rows to split and the duration */ + bool initWithDuration(float duration, unsigned int nRows); + unsigned int _rows; Size _winSize; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(SplitRows); }; /** @brief SplitCols action */ @@ -287,17 +342,22 @@ public: /** creates the action with the number of columns to split and the duration */ static SplitCols* create(float duration, unsigned int nCols); - /** initializes the action with the number of columns to split and the duration */ - bool initWithDuration(float duration, unsigned int nCols); - // Overrides virtual SplitCols* clone() const override; virtual void update(float time) override; virtual void startWithTarget(Node *target) override; protected: + SplitCols() {} + virtual ~SplitCols() {} + /** initializes the action with the number of columns to split and the duration */ + bool initWithDuration(float duration, unsigned int nCols); + unsigned int _cols; Size _winSize; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(SplitCols); }; // end of actions group diff --git a/cocos/2d/CCTransition.h b/cocos/2d/CCTransition.h index 43f1fe5bee..f2485d016e 100644 --- a/cocos/2d/CCTransition.h +++ b/cocos/2d/CCTransition.h @@ -90,33 +90,24 @@ public: // Overrides // virtual void draw() override; - /** - * @js NA - * @lua NA - */ virtual void onEnter() override; - /** - * @js NA - * @lua NA - */ virtual void onExit() override; virtual void cleanup() override; protected: TransitionScene(); virtual ~TransitionScene(); - /** initializes a transition with duration and incoming scene */ bool initWithDuration(float t,Scene* scene); virtual void sceneOrder(); void setNewScene(float dt); - Scene * _inScene; - Scene * _outScene; - float _duration; - bool _isInSceneOnTop; - bool _isSendCleanupToScene; + Scene *_inScene; + Scene *_outScene; + float _duration; + bool _isInSceneOnTop; + bool _isSendCleanupToScene; private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionScene); @@ -152,14 +143,9 @@ class CC_DLL TransitionRotoZoom : public TransitionScene public: static TransitionRotoZoom* create(float t, Scene* scene); - // // Overrides // - /** - * @js NA - * @lua NA - */ virtual void onEnter() override; protected: @@ -182,10 +168,6 @@ public: // // Overrides // - /** - * @js NA - * @lua NA - */ virtual void onEnter() override; protected: @@ -204,8 +186,6 @@ class CC_DLL TransitionMoveInL : public TransitionScene, public TransitionEaseSc public: static TransitionMoveInL* create(float t, Scene* scene); - /** initializes the scenes */ - virtual void initScenes(void); /** returns the action that will be performed */ virtual ActionInterval* action(void); @@ -214,16 +194,15 @@ public: // // Overrides // - /** - * @js NA - * @lua NA - */ virtual void onEnter() override; protected: TransitionMoveInL(); virtual ~TransitionMoveInL(); + /** initializes the scenes */ + virtual void initScenes(); + private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInL); }; @@ -235,12 +214,13 @@ class CC_DLL TransitionMoveInR : public TransitionMoveInL { public: static TransitionMoveInR* create(float t, Scene* scene); - virtual void initScenes(); protected: TransitionMoveInR(); virtual ~TransitionMoveInR(); + virtual void initScenes(); + private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInR); }; @@ -252,12 +232,13 @@ class CC_DLL TransitionMoveInT : public TransitionMoveInL { public: static TransitionMoveInT* create(float t, Scene* scene); - virtual void initScenes(); protected: TransitionMoveInT(); virtual ~TransitionMoveInT(); + virtual void initScenes(); + private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInT); }; @@ -269,19 +250,13 @@ class CC_DLL TransitionMoveInB : public TransitionMoveInL { public: static TransitionMoveInB* create(float t, Scene* scene); - virtual void initScenes(); protected: - /** - * @js ctor - */ TransitionMoveInB(); - /** - * @js NA - * @lua NA - */ virtual ~TransitionMoveInB(); + virtual void initScenes(); + private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionMoveInB); }; @@ -296,31 +271,21 @@ public: virtual ActionInterval* easeActionWithAction(ActionInterval * action); - /** initializes the scenes */ - virtual void initScenes(void); /** returns the action that will be performed by the incoming and outgoing scene */ virtual ActionInterval* action(void); // // Overrides // - /** - * @js NA - * @lua NA - */ virtual void onEnter() override; protected: - /** - * @js ctor - */ TransitionSlideInL(); - /** - * @js NA - * @lua NA - */ virtual ~TransitionSlideInL(); + /** initializes the scenes */ + virtual void initScenes(void); + virtual void sceneOrder() override; private: @@ -334,23 +299,21 @@ class CC_DLL TransitionSlideInR : public TransitionSlideInL { public: static TransitionSlideInR* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSlideInR(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSlideInR(); - /** initializes the scenes */ - virtual void initScenes(void); /** returns the action that will be performed by the incoming and outgoing scene */ virtual ActionInterval* action(void); protected: + TransitionSlideInR(); + virtual ~TransitionSlideInR(); + + /** initializes the scenes */ + virtual void initScenes(void); + virtual void sceneOrder() override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSlideInR); }; /** @brief TransitionSlideInB: @@ -360,23 +323,21 @@ class CC_DLL TransitionSlideInB : public TransitionSlideInL { public: static TransitionSlideInB* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSlideInB(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSlideInB(); - /** initializes the scenes */ - virtual void initScenes(void); /** returns the action that will be performed by the incoming and outgoing scene */ virtual ActionInterval* action(void); protected: + TransitionSlideInB(); + virtual ~TransitionSlideInB(); + + /** initializes the scenes */ + virtual void initScenes(); + virtual void sceneOrder() override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSlideInB); }; /** @brief TransitionSlideInT: @@ -386,23 +347,21 @@ class CC_DLL TransitionSlideInT : public TransitionSlideInL { public: static TransitionSlideInT* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSlideInT(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSlideInT(); - /** initializes the scenes */ - virtual void initScenes(void); /** returns the action that will be performed by the incoming and outgoing scene */ virtual ActionInterval* action(void); protected: + TransitionSlideInT(); + virtual ~TransitionSlideInT(); + + /** initializes the scenes */ + virtual void initScenes(void); + virtual void sceneOrder() override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSlideInT); }; /** @@ -412,21 +371,23 @@ class CC_DLL TransitionShrinkGrow : public TransitionScene , public TransitionEa { public: static TransitionShrinkGrow* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionShrinkGrow(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionShrinkGrow(); // // Overrides // + /** + * @js NA + * @lua NA + */ virtual void onEnter() override; virtual ActionInterval* easeActionWithAction(ActionInterval * action) override; + +protected: + TransitionShrinkGrow(); + virtual ~TransitionShrinkGrow(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionShrinkGrow); }; /** @brief TransitionFlipX: @@ -438,15 +399,6 @@ class CC_DLL TransitionFlipX : public TransitionSceneOriented public: static TransitionFlipX* create(float t, Scene* s, Orientation o); static TransitionFlipX* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionFlipX(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFlipX(); // // Overrides @@ -456,6 +408,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionFlipX(); + virtual ~TransitionFlipX(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFlipX); }; /** @brief TransitionFlipY: @@ -467,15 +426,6 @@ class CC_DLL TransitionFlipY : public TransitionSceneOriented public: static TransitionFlipY* create(float t, Scene* s, Orientation o); static TransitionFlipY* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionFlipY(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFlipY(); // // Overrides @@ -485,6 +435,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionFlipY(); + virtual ~TransitionFlipY(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFlipY); }; /** @brief TransitionFlipAngular: @@ -496,15 +453,6 @@ class CC_DLL TransitionFlipAngular : public TransitionSceneOriented public: static TransitionFlipAngular* create(float t, Scene* s, Orientation o); static TransitionFlipAngular* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionFlipAngular(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFlipAngular(); // // Overrides @@ -514,6 +462,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionFlipAngular(); + virtual ~TransitionFlipAngular(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFlipAngular); }; /** @brief TransitionZoomFlipX: @@ -525,15 +480,6 @@ class CC_DLL TransitionZoomFlipX : public TransitionSceneOriented public: static TransitionZoomFlipX* create(float t, Scene* s, Orientation o); static TransitionZoomFlipX* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionZoomFlipX(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionZoomFlipX(); // // Overrides @@ -543,6 +489,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionZoomFlipX(); + virtual ~TransitionZoomFlipX(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionZoomFlipX); }; /** @brief TransitionZoomFlipY: @@ -554,15 +507,6 @@ class CC_DLL TransitionZoomFlipY : public TransitionSceneOriented public: static TransitionZoomFlipY* create(float t, Scene* s, Orientation o); static TransitionZoomFlipY* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionZoomFlipY(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionZoomFlipY(); // // Overrides @@ -572,6 +516,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionZoomFlipY(); + virtual ~TransitionZoomFlipY(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionZoomFlipY); }; /** @brief TransitionZoomFlipAngular: @@ -583,15 +534,6 @@ class CC_DLL TransitionZoomFlipAngular : public TransitionSceneOriented public: static TransitionZoomFlipAngular* create(float t, Scene* s, Orientation o); static TransitionZoomFlipAngular* create(float t, Scene* s); - /** - * @js ctor - */ - TransitionZoomFlipAngular(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionZoomFlipAngular(); // // Overrides @@ -601,6 +543,13 @@ public: * @lua NA */ virtual void onEnter() override; + +protected: + TransitionZoomFlipAngular(); + virtual ~TransitionZoomFlipAngular(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionZoomFlipAngular); }; /** @brief TransitionFade: @@ -612,25 +561,9 @@ public: /** creates the transition with a duration and with an RGB color * Example: FadeTransition::create(2, scene, Color3B(255,0,0); // red color */ - static TransitionFade* create(float duration,Scene* scene, const Color3B& color); - static TransitionFade* create(float duration,Scene* scene); - /** - * @js ctor - */ - TransitionFade(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFade(); + static TransitionFade* create(float duration, Scene* scene, const Color3B& color); + static TransitionFade* create(float duration, Scene* scene); - /** initializes the transition with a duration and with an RGB color */ - bool initWithDuration(float t, Scene*scene ,const Color3B& color); - - // - // Overrides - // - bool initWithDuration(float t,Scene* scene); /** * @js NA * @lua NA @@ -643,7 +576,18 @@ public: virtual void onExit(); protected: - Color4B _color; + TransitionFade(); + virtual ~TransitionFade(); + + /** initializes the transition with a duration and with an RGB color */ + bool initWithDuration(float t, Scene*scene, const Color3B& color); + bool initWithDuration(float t, Scene* scene); + + Color4B _color; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFade); + }; class RenderTexture; @@ -655,19 +599,14 @@ class CC_DLL TransitionCrossFade : public TransitionScene { public : static TransitionCrossFade* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionCrossFade(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionCrossFade(); // // Overrides // + /** + * @js NA + * @lua NA + */ virtual void draw() override; /** * @js NA @@ -680,6 +619,12 @@ public : */ virtual void onExit() override; +protected: + TransitionCrossFade(); + virtual ~TransitionCrossFade(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionCrossFade); }; /** @brief TransitionTurnOffTiles: @@ -689,15 +634,6 @@ class CC_DLL TransitionTurnOffTiles : public TransitionScene ,public TransitionE { public : static TransitionTurnOffTiles* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionTurnOffTiles(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionTurnOffTiles(); // // Overrides @@ -710,7 +646,13 @@ public : virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; protected: + TransitionTurnOffTiles(); + virtual ~TransitionTurnOffTiles(); + virtual void sceneOrder() override; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionTurnOffTiles); }; /** @brief TransitionSplitCols: @@ -720,17 +662,8 @@ class CC_DLL TransitionSplitCols : public TransitionScene , public TransitionEas { public: static TransitionSplitCols* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSplitCols(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSplitCols(); - virtual ActionInterval* action(void); + virtual ActionInterval* action(); // // Overrides @@ -741,6 +674,13 @@ public: */ virtual void onEnter() override; virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; + +protected: + TransitionSplitCols(); + virtual ~TransitionSplitCols(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSplitCols); }; /** @brief TransitionSplitRows: @@ -750,20 +690,18 @@ class CC_DLL TransitionSplitRows : public TransitionSplitCols { public: static TransitionSplitRows* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionSplitRows(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionSplitRows(); // // Overrides // virtual ActionInterval* action(void) override; + +protected: + TransitionSplitRows(); + virtual ~TransitionSplitRows(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionSplitRows); }; /** @brief TransitionFadeTR: @@ -773,15 +711,7 @@ class CC_DLL TransitionFadeTR : public TransitionScene , public TransitionEaseSc { public: static TransitionFadeTR* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionFadeTR(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFadeTR(); + virtual ActionInterval* actionWithSize(const Size& size); // @@ -795,7 +725,13 @@ public: virtual ActionInterval* easeActionWithAction(ActionInterval * action) override; protected: + TransitionFadeTR(); + virtual ~TransitionFadeTR(); + virtual void sceneOrder(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFadeTR); }; /** @brief TransitionFadeBL: @@ -805,21 +741,18 @@ class CC_DLL TransitionFadeBL : public TransitionFadeTR { public: static TransitionFadeBL* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionFadeBL(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFadeBL(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; +protected: + TransitionFadeBL(); + virtual ~TransitionFadeBL(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFadeBL); }; /** @brief TransitionFadeUp: @@ -829,20 +762,18 @@ class CC_DLL TransitionFadeUp : public TransitionFadeTR { public: static TransitionFadeUp* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionFadeUp(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFadeUp(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; + +protected: + TransitionFadeUp(); + virtual ~TransitionFadeUp(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFadeUp); }; /** @brief TransitionFadeDown: @@ -852,20 +783,19 @@ class CC_DLL TransitionFadeDown : public TransitionFadeTR { public: static TransitionFadeDown* create(float t, Scene* scene); - /** - * @js ctor - */ - TransitionFadeDown(); - /** - * @js NA - * @lua NA - */ - virtual ~TransitionFadeDown(); // // Overrides // virtual ActionInterval* actionWithSize(const Size& size) override; + +protected: + TransitionFadeDown(); + virtual ~TransitionFadeDown(); + +private: + CC_DISALLOW_COPY_AND_ASSIGN(TransitionFadeDown); + }; // end of transition group From 9b52af010d087d651b3fd4e10f34f3b4fd80323a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 16:09:05 -0800 Subject: [PATCH 19/28] Macro CC_DISABLE_COPY is renamed to CC_DISALLOW_COPY_AND_ASSIGN and the old CC_DISALLOW_COPY_AND_ASSIGN is removed --- cocos/2d/ccMacros.h | 18 ---------------- cocos/2d/platform/CCDevice.h | 6 ++++-- cocos/2d/platform/CCEGLViewProtocol.cpp | 11 ++++------ cocos/2d/platform/CCEGLViewProtocol.h | 14 ++++++------- cocos/2d/platform/mac/CCEGLView.mm | 4 ++-- cocos/base/CCPlatformMacros.h | 28 +++++++++++++++++-------- 6 files changed, 36 insertions(+), 45 deletions(-) diff --git a/cocos/2d/ccMacros.h b/cocos/2d/ccMacros.h index f82f3c9284..dbea2d512a 100644 --- a/cocos/2d/ccMacros.h +++ b/cocos/2d/ccMacros.h @@ -257,22 +257,4 @@ extern unsigned int CC_DLL g_uNumberOfDraws; */ #define AnimationFrameDisplayedNotification "CCAnimationFrameDisplayedNotification" -// A macro to disallow the copy constructor and operator= functions -// This should be used in the private: declarations for a class -#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - -// A macro to disallow all the implicit constructors, namely the -// default constructor, copy constructor and operator= functions. -// -// This should be used in the private: declarations for a class -// that wants to prevent anyone from instantiating it. This is -// especially useful for classes containing only static methods. -#define CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName(); \ - CC_DISALLOW_COPY_AND_ASSIGN(TypeName) - - - #endif // __CCMACROS_H__ diff --git a/cocos/2d/platform/CCDevice.h b/cocos/2d/platform/CCDevice.h index 1a7ddc0e72..65d5a3f3b7 100644 --- a/cocos/2d/platform/CCDevice.h +++ b/cocos/2d/platform/CCDevice.h @@ -2,13 +2,12 @@ #define __CCDEVICE_H__ #include "CCPlatformMacros.h" +#include "ccMacros.h" NS_CC_BEGIN class CC_DLL Device { -private: - Device(); public: /** * Gets the DPI of device @@ -24,6 +23,9 @@ public: * Sets the interval of accelerometer. */ static void setAccelerometerInterval(float interval); + +private: + CC_DISALLOW_IMPLICIT_CONSTRUCTORS(Device); }; diff --git a/cocos/2d/platform/CCEGLViewProtocol.cpp b/cocos/2d/platform/CCEGLViewProtocol.cpp index ebeba6b203..c6623a234f 100644 --- a/cocos/2d/platform/CCEGLViewProtocol.cpp +++ b/cocos/2d/platform/CCEGLViewProtocol.cpp @@ -177,7 +177,7 @@ bool EGLViewProtocol::isScissorEnabled() return (GL_FALSE == glIsEnabled(GL_SCISSOR_TEST)) ? false : true; } -Rect EGLViewProtocol::getScissorRect() +Rect EGLViewProtocol::getScissorRect() const { GLfloat params[4]; glGetFloatv(GL_SCISSOR_BOX, params); @@ -188,15 +188,12 @@ Rect EGLViewProtocol::getScissorRect() return Rect(x, y, w, h); } -void EGLViewProtocol::setViewName(const char* pszViewName) +void EGLViewProtocol::setViewName(const std::string& viewname ) { - if (pszViewName != NULL && strlen(pszViewName) > 0) - { - strncpy(_viewName, pszViewName, sizeof(_viewName)); - } + _viewName = viewname; } -const char* EGLViewProtocol::getViewName() +const std::string& EGLViewProtocol::getViewName() const { return _viewName; } diff --git a/cocos/2d/platform/CCEGLViewProtocol.h b/cocos/2d/platform/CCEGLViewProtocol.h index ed54d59712..53f9400dcf 100644 --- a/cocos/2d/platform/CCEGLViewProtocol.h +++ b/cocos/2d/platform/CCEGLViewProtocol.h @@ -129,11 +129,10 @@ public: /** * Get the current scissor rectangle */ - virtual Rect getScissorRect(); + virtual Rect getScissorRect() const; - virtual void setViewName(const char* pszViewName); - - const char* getViewName(); + virtual void setViewName(const std::string& viewname); + const std::string& getViewName() const; /** Touch events are handled by default; if you want to customize your handlers, please override these functions: */ virtual void handleTouchesBegin(int num, long ids[], float xs[], float ys[]); @@ -155,10 +154,11 @@ public: * Get scale factor of the vertical direction. */ float getScaleY() const; -private: - void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[]); + protected: + void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[]); + EGLTouchDelegate* _delegate; // real screen size @@ -168,7 +168,7 @@ protected: // the view port size Rect _viewPortRect; // the view name - char _viewName[50]; + std::string _viewName; float _scaleX; float _scaleY; diff --git a/cocos/2d/platform/mac/CCEGLView.mm b/cocos/2d/platform/mac/CCEGLView.mm index 04ef6b69e7..5d4f23b281 100644 --- a/cocos/2d/platform/mac/CCEGLView.mm +++ b/cocos/2d/platform/mac/CCEGLView.mm @@ -312,8 +312,8 @@ EGLView::EGLView() , _mainWindow(nullptr) { CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n"); + _viewName = "cocos2dx"; s_pEglView = this; - strcpy(_viewName, "Cocos2dxWin32"); glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError); glfwInit(); } @@ -334,7 +334,7 @@ bool EGLView::init(const char *viewName, float width, float height, float frameZ setFrameZoomFactor(frameZoomFactor); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); - _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr); + _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName.c_str(), nullptr, nullptr); glfwMakeContextCurrent(_mainWindow); glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]); diff --git a/cocos/base/CCPlatformMacros.h b/cocos/base/CCPlatformMacros.h index fca1255c0d..f3c8c91ba7 100644 --- a/cocos/base/CCPlatformMacros.h +++ b/cocos/base/CCPlatformMacros.h @@ -234,19 +234,29 @@ public: virtual void set##funName(varType var) \ #define LUALOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) #endif // Lua engine debug +// A macro to disallow the copy constructor and operator= functions +// This should be used in the private: declarations for a class #if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \ - || (defined(__clang__) && (__clang_major__ >= 3)) -#define CC_DISABLE_COPY(Class) \ -private: \ - Class(const Class &) = delete; \ - Class &operator =(const Class &) = delete; +|| (defined(__clang__) && (__clang_major__ >= 3)) +#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName &) = delete; \ + TypeName &operator =(const TypeName &) = delete; #else -#define CC_DISABLE_COPY(Class) \ -private: \ - Class(const Class &); \ - Class &operator =(const Class &); +#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + Class(const TypeName &); \ + Class &operator =(const TypeName &); #endif +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#define CC_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + CC_DISALLOW_COPY_AND_ASSIGN(TypeName) + /* * only certain compilers support __attribute__((deprecated)) */ From 447a34655ac71069adb5542fb56425852e736fce Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 16:14:05 -0800 Subject: [PATCH 20/28] RenderTexture contructor ctor is public again --- cocos/2d/CCRenderTexture.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 90b2ba1784..5837848eab 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -152,23 +152,18 @@ public: virtual void visit() override; virtual void draw() override; -protected: - /** - * @js ctor - */ +public: + // XXX should be procted. + // but due to a bug in PowerVR + Android, + // the constructor is public again RenderTexture(); - /** - * @js NA - * @lua NA - */ virtual ~RenderTexture(); - /** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat); - /** initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format*/ bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat); +protected: void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); GLuint _FBO; From cc5a03f21a0e9c324bb9848de34f5fd7552008bd Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 22 Nov 2013 16:58:05 -0800 Subject: [PATCH 21/28] updates cocos2d version --- cocos/2d/cocos2d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/cocos2d.cpp b/cocos/2d/cocos2d.cpp index d531f85893..1c754fd45b 100644 --- a/cocos/2d/cocos2d.cpp +++ b/cocos/2d/cocos2d.cpp @@ -30,7 +30,7 @@ NS_CC_BEGIN const char* cocos2dVersion() { - return "3.0-alpha1"; + return "3.0-beta0-pre"; } NS_CC_END From a198fb51df9ed79781a3f3c5b5ec89ad49130b10 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 25 Nov 2013 16:24:33 -0800 Subject: [PATCH 22/28] JS Bindings Menu doesn't initialize the menu twice. --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 8ac72cc7c1..f72dd9cbdf 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -3194d28204e71875735934ee3207961ec14e655a \ No newline at end of file +e25d022404007994fb9abd210bd35646a217e49e \ No newline at end of file From 6f67447b5e151dd8cc4c2e6d97155cf68b8beb03 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 15:43:39 +0800 Subject: [PATCH 23/28] =?UTF-8?q?issue=20#3258:=20Updates=20cocos2dx.ini.?= =?UTF-8?q?=20Adding=20some=20classes=20to=20=E2=80=98classes=5Fneed=5Fext?= =?UTF-8?q?end=E2=80=99=20section.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/tojs/cocos2dx.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 2acfad1a34..bd3f409288 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -28,6 +28,8 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # expression, it will be enclosed in "^$", like this: "^Menu*$". classes = Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF EGLViewProtocol EGLView Component +classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode + # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also # regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just From b55e8f17c71d51179602c4cbaba29509cab327fb Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 15:44:21 +0800 Subject: [PATCH 24/28] issue #3258: MenuItemFont has empty argument create function now. --- cocos/2d/CCMenuItem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCMenuItem.h b/cocos/2d/CCMenuItem.h index fb44773d27..09de7fe399 100644 --- a/cocos/2d/CCMenuItem.h +++ b/cocos/2d/CCMenuItem.h @@ -246,7 +246,7 @@ class CC_DLL MenuItemFont : public MenuItemLabel { public: /** creates a menu item from a string without target/selector. To be used with MenuItemToggle */ - static MenuItemFont * create(const std::string& value); + 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); /** creates a menu item from a string with a target/selector */ From ebcdf2f87d62295105fd5ec27e3b7177516aea36 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 15:44:49 +0800 Subject: [PATCH 25/28] issue #3258: Bug fix of MenuItemToggle binding. --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- .../lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index f72dd9cbdf..0fca450a63 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -e25d022404007994fb9abd210bd35646a217e49e \ No newline at end of file +779c204bb8fdea3bbe3fe7ac2f687b1d0250ee3a \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id index c3dcf3390c..0f09dcedde 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -86fa141032de3d513df690fc82b20d2f2b4ab01b \ No newline at end of file +270dc280a6f338f52b0147dc00421c5478941304 \ No newline at end of file From 03005173b1d26e9ad3882c2188ce134201aeb5f9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 15:45:09 +0800 Subject: [PATCH 26/28] issue #3258: Updates bindings-generator. --- tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bindings-generator b/tools/bindings-generator index 2f3c19e01d..e6c7016f83 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 2f3c19e01d5043485d0887ad69a3f02e312ad690 +Subproject commit e6c7016f83c9d02e0b8e784c65043369a1745680 From 63702188be4f7fbd90af05edfef87f8de9ea66b3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 15:56:43 +0800 Subject: [PATCH 27/28] issue #3258: Compilation error fix for linux port. --- cocos/2d/platform/linux/CCEGLView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/platform/linux/CCEGLView.cpp b/cocos/2d/platform/linux/CCEGLView.cpp index 612f936d51..d8fbbf5737 100644 --- a/cocos/2d/platform/linux/CCEGLView.cpp +++ b/cocos/2d/platform/linux/CCEGLView.cpp @@ -290,7 +290,7 @@ EGLView::EGLView() { CCASSERT(nullptr == s_pEglView, "EGLView is singleton, Should be inited only one time\n"); s_pEglView = this; - strcpy(_viewName, "Cocos2dxWin32"); + _viewName = "Cocos2dxWin32"; glfwSetErrorCallback(EGLViewEventHandler::OnGLFWError); glfwInit(); } @@ -310,7 +310,7 @@ bool EGLView::init(const char* viewName, float width, float height, float frameZ setFrameZoomFactor(frameZoomFactor); glfwWindowHint(GLFW_RESIZABLE,GL_FALSE); - _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName, nullptr, nullptr); + _mainWindow = glfwCreateWindow(_screenSize.width * _frameZoomFactor, _screenSize.height * _frameZoomFactor, _viewName.c_str(), nullptr, nullptr); glfwMakeContextCurrent(_mainWindow); glfwGetFramebufferSize(_mainWindow, &_frameBufferSize[0], &_frameBufferSize[1]); From a04c45f0d9c17c18ed89cebe2a78a649db0739e5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 26 Nov 2013 16:19:12 +0800 Subject: [PATCH 28/28] issue #3258: Renames ControlSwitchSprite::createWithMaskSprite to ControlSwitchSprite::create. --- extensions/GUI/CCControlExtension/CCControlSwitch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp index 8a7d046593..13b2329579 100644 --- a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp +++ b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp @@ -35,7 +35,7 @@ class ControlSwitchSprite : public Sprite, public ActionTweenDelegate { public: /** creates an autorelease instance of ControlSwitchSprite */ - static ControlSwitchSprite* createWithMaskSprite( + static ControlSwitchSprite* create( Sprite *maskSprite, Sprite *onSprite, Sprite *offSprite, @@ -121,7 +121,7 @@ private: CC_DISALLOW_COPY_AND_ASSIGN(ControlSwitchSprite); }; -ControlSwitchSprite* ControlSwitchSprite::createWithMaskSprite(Sprite *maskSprite, +ControlSwitchSprite* ControlSwitchSprite::create(Sprite *maskSprite, Sprite *onSprite, Sprite *offSprite, Sprite *thumbSprite, @@ -376,7 +376,7 @@ bool ControlSwitch::initWithMaskSprite(Sprite *maskSprite, Sprite * onSprite, Sp _on = true; - _switchSprite = ControlSwitchSprite::createWithMaskSprite(maskSprite, + _switchSprite = ControlSwitchSprite::create(maskSprite, onSprite, offSprite, thumbSprite,