From 1d04b429470e7e66f5be4764f806e7e6f7e4807e Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 3 Jan 2014 18:15:56 +0800 Subject: [PATCH 1/2] Put "initxx" functions into protected. --- cocos/2d/CCParticleBatchNode.h | 23 +++++++++++-------- cocos/2d/CCParticleSystemQuad.h | 13 ++++++----- .../Classes/ParticleTest/ParticleTest.cpp | 3 +-- .../PerformanceParticleTest.cpp | 9 +------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index 4162d3b9dd..41fb9e5d40 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -73,22 +73,13 @@ public: /** 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 std::string& fileImage, int capacity = kParticleDefaultCapacity); - /** - * @js ctor - */ - ParticleBatchNode(); + /** * @js NA * @lua NA */ virtual ~ParticleBatchNode(); - /** initializes the particle system with Texture2D, a capacity of particles */ - 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 std::string& fileImage, int capacity); - /** Inserts a child into the ParticleBatchNode */ void insertChild(ParticleSystem* system, int index); @@ -127,6 +118,18 @@ public: * @lua NA */ virtual const BlendFunc& getBlendFunc(void) const override; + +protected: + /** + * @js ctor + */ + ParticleBatchNode(); + + /** initializes the particle system with Texture2D, a capacity of particles */ + 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 std::string& fileImage, int capacity); private: void updateAllAtlasIndexes(); diff --git a/cocos/2d/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h index 93e7a1f948..9901655313 100644 --- a/cocos/2d/CCParticleSystemQuad.h +++ b/cocos/2d/CCParticleSystemQuad.h @@ -84,12 +84,6 @@ public: */ void listenBackToForeground(EventCustom* event); - // Overrides - /** - * @js NA - * @lua NA - */ - virtual bool initWithTotalParticles(int numberOfParticles) override; /** * @js NA * @lua NA @@ -140,6 +134,13 @@ protected: /** initializes the texture with a rectangle measured Points */ void initTexCoordsWithRect(const Rect& rect); + + // Overrides + /** + * @js NA + * @lua NA + */ + virtual bool initWithTotalParticles(int numberOfParticles) override; void setupVBOandVAO(); void setupVBO(); diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp index d7ecafe32b..18f9c8a4bd 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp @@ -1553,8 +1553,7 @@ void MultipleParticleSystemsBatched::onEnter() removeChild(_background, true); _background = NULL; - auto batchNode = new ParticleBatchNode(); - batchNode->initWithTexture(NULL, 3000); + ParticleBatchNode *batchNode = ParticleBatchNode::createWithTexture(nullptr, 3000); addChild(batchNode, 1, 2); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp index 1f4adbbf1a..2ec2501ce6 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp @@ -196,24 +196,21 @@ void ParticleMainScene::createParticleSystem() // } // else { - particleSystem = ParticleSystemQuad::create(); + particleSystem = ParticleSystemQuad::createWithTotalParticles(quantityParticles); } switch( subtestNumber) { case 1: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; case 2: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; case 3: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; // case 4: @@ -223,21 +220,17 @@ void ParticleMainScene::createParticleSystem() // break; case 4: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; case 5: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; case 6: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::A8); - particleSystem->initWithTotalParticles(quantityParticles); particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); break; // case 8: -// particleSystem->initWithTotalParticles(quantityParticles); // ////---- particleSystem.texture = [[TextureCache sharedTextureCache] addImage:@"fire.pvr"]; // particleSystem->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png")); // break; From b0c23eacf54b5a081ff33a56791c156e81b96b34 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 3 Jan 2014 18:28:43 +0800 Subject: [PATCH 2/2] Don't release autoreased object. --- .../TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp index 2ec2501ce6..d653d67bb3 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp @@ -240,7 +240,6 @@ void ParticleMainScene::createParticleSystem() break; } addChild(particleSystem, 0, kTagParticleSystem); - particleSystem->release(); doTest();