#ifndef __CCPARTICLEBATCHNODE_H__
#define __CCPARTICLEBATCHNODE_H__
#include "base_nodes/CCNode.h"
#include "CCProtocols.h"
NS_CC_BEGIN
class CCTexture2D;
class CCTextureAtlas;
class CCParticleSystem;
/**
* @addtogroup particle_nodes
* @{
*/
#define kCCParticleDefaultCapacity 500
/** CCParticleBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
* (often known as "batch draw").
*
* A CCParticleBatchNode can reference(参考,参照;涉及) one and only one texture (one image file, one texture atlas).
* Only the CCParticleSystems that are contained in that texture can be added to the CCSpriteBatchNode.
* All CCParticleSystems added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call.
* If the CCParticleSystems are not added to a CCParticleBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient(有效率的;有能力的;生效的).
*
*
* Limitations:
* - At the moment only CCParticleSystemQuad is supported
* - All systems need to be drawn with the same parameters(参数), blend function, aliasing(混淆现象), texture
*
* Most efficient usage
* - Initialize the ParticleBatchNode with the texture and enough capacity for all the particle systems
* - Initialize all particle systems and add them as child to the batch node
* @since v1.1
*/
class CC_DLL CCParticleBatchNode : public CCNode, public CCTextureProtocol
{
public:
CCParticleBatchNode();
virtual ~CCParticleBatchNode();
//初始化粒子系统 参数是所用纹理 粒子容量
static CCParticleBatchNode* createWithTexture(CCTexture2D *tex, unsigned int capacity = kCCParticleDefaultCapacity);
//同上 纹理通过文件名间接传入
static CCParticleBatchNode* create(const char* fileImage, unsigned int capacity = kCCParticleDefaultCapacity);
bool initWithTexture(CCTexture2D *tex, unsigned int capacity);
{
m_pTextureAtlas = new CCTextureAtlas();
m_pTextureAtlas->initWithTexture(tex, capacity);
// no lazy alloc in this node
m_pChildren = new CCArray();
m_pChildren->initWithCapacity(capacity);
m_tBlendFunc.src = CC_BLEND_SRC;
m_tBlendFunc.dst = CC_BLEND_DST;
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
return true;
}
bool initWithFile(const char* fileImage, unsigned int capacity);
{
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(fileImage);
return initWithTexture(tex, capacity);
}
//往粒子系统加node
virtual void addChild(CCNode * child);
virtual void addChild(CCNode * child, int zOrder);
virtual void addChild(CCNode * child, int zOrder, int tag);
/** Inserts a child into the CCParticleBatchNode */
void insertChild(CCParticleSystem* pSystem, unsigned int index);
/** remove child from the CCParticleBatchNode */
virtual void removeChild(CCNode* child, bool cleanup);
virtual void reorderChild(CCNode * child, int zOrder);
void removeChildAtIndex(unsigned int index, bool doCleanup);
void removeAllChildrenWithCleanup(bool doCleanup);
/** disables a particle by inserting a 0'd quad into the texture atlas */
void disableParticle(unsigned int particleIndex);
virtual void draw(void);
// returns the used texture
virtual CCTexture2D* getTexture(void);
// sets a new texture. it will be retained
virtual void setTexture(CCTexture2D *texture);
virtual void setBlendFunc(ccBlendFunc blendFunc);
// returns the blending function used for the texture
virtual ccBlendFunc getBlendFunc(void);
void visit();
private:
void updateAllAtlasIndexes();
void increaseAtlasCapacityTo(unsigned int quantity);
unsigned int searchNewPositionInChildrenForZ(int z);
void getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, CCNode* child, int z);
unsigned int addChildHelper(CCParticleSystem* child, int z, int aTag);
void updateBlendFunc(void);
/** the texture atlas used for drawing the quads */
CC_SYNTHESIZE(CCTextureAtlas*, m_pTextureAtlas, TextureAtlas);
private:
/** the blend function used for drawing the quads */
ccBlendFunc m_tBlendFunc;
};
// end of particle_nodes group
/// @}
NS_CC_END
#endif /* __CCPARTICLEBATCHNODE_H__ */