ParticleSystem uses protected constructors

This commit is contained in:
Ricardo Quesada 2013-11-14 16:21:49 -08:00
parent c52dc4ff5f
commit dd68eb4796
11 changed files with 197 additions and 205 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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 );

View File

@ -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:

View File

@ -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

View File

@ -16,7 +16,7 @@ public:
class ParticleDemo : public BaseTest
{
protected:
ParticleSystem* _emitter;
ParticleSystemQuad* _emitter;
Sprite* _background;
LayerColor* _color;

View File

@ -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)