axmol/cocos/2d/CCParticleBatchNode.h

157 lines
5.8 KiB
C
Raw Normal View History

/*
* Copyright (C) 2009 Matt Oswald
* Copyright (c) 2009-2010 Ricardo Quesada
* Copyright (c) 2010-2012 cocos2d-x.org
* Copyright (c) 2011 Zynga Inc.
* Copyright (c) 2011 Marco Tillemans
* Copyright (c) 2013-2014 Chukong Technologies Inc.
*
* http://www.cocos2d-x.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#ifndef __CCPARTICLEBATCHNODE_H__
#define __CCPARTICLEBATCHNODE_H__
#include "2d/CCNode.h"
Squashed commit of the following: commit a794d107ad85667e3d754f0b6251fc864dfbf288 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 14:33:49 2014 -0700 Yeah... everything compiles on win32 and wp8 commit 4740be6e4a0d16f742c27996e7ab2c100adc76af Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:58:38 2014 -0700 CCIME moved to base and compiles on Android commit ff3e1bf1eb27a01019f4e1b56d1aebbe2d385f72 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 13:02:57 2014 -0700 compiles Ok for Windows Phone 8 commit 8160a4eb2ecdc61b5bd1cf56b90d2da6f11e3ebd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 12:25:31 2014 -0700 fixes for Windows Phone 8 commit 418197649efc93032aee0adc205e502101cdb53d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 11:15:13 2014 -0700 Compiles on Win32 commit 08813ed7cf8ac1079ffadeb1ce78ea9e833e1a33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 10:08:31 2014 -0700 Compiles on linux! commit 118896521e5b335a5257090b6863f1fb2a2002fe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 09:30:42 2014 -0700 moves cocos/2d/platform -> cocos/platform commit 4fe9319d7717b0c1bccb2db0156eeb86255a89e0 Merge: bd68ec2 511295e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 16 08:24:41 2014 -0700 Merge remote-tracking branch 'cocos2d/v3' into files commit bd68ec2f0e3a826d8b2f4b60564ba65ce766bc56 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu May 15 19:36:23 2014 -0700 files in the correct directory
2014-05-17 05:36:00 +08:00
#include "base/CCProtocols.h"
2014-04-30 08:37:36 +08:00
#include "renderer/CCBatchCommand.h"
NS_CC_BEGIN
class Texture2D;
class TextureAtlas;
class ParticleSystem;
2012-06-20 18:09:11 +08:00
/**
* @addtogroup particle_nodes
* @{
*/
#define kParticleDefaultCapacity 500
/** ParticleBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
* (often known as "batch draw").
*
* A ParticleBatchNode can reference one and only one texture (one image file, one texture atlas).
* Only the ParticleSystems that are contained in that texture can be added to the SpriteBatchNode.
* All ParticleSystems added to a SpriteBatchNode are drawn in one OpenGL ES draw call.
* If the ParticleSystems are not added to a ParticleBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient.
*
*
* Limitations:
* - At the moment only ParticleSystemQuad 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 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, 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 std::string& fileImage, int capacity = kParticleDefaultCapacity);
2014-01-03 18:15:56 +08:00
/** Inserts a child into the ParticleBatchNode */
void insertChild(ParticleSystem* system, int index);
2013-12-05 17:19:01 +08:00
void removeChildAtIndex(int index, bool doCleanup);
void removeAllChildrenWithCleanup(bool doCleanup);
/** disables a particle by inserting a 0'd quad into the texture atlas */
2013-12-05 17:19:01 +08:00
void disableParticle(int particleIndex);
/** Gets the texture atlas used for drawing the quads */
inline TextureAtlas* getTextureAtlas() const { return _textureAtlas; };
/** Sets the texture atlas used for drawing the quads */
inline void setTextureAtlas(TextureAtlas* atlas) { _textureAtlas = atlas; };
// Overrides
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
using Node::addChild;
virtual void addChild(Node * child, int zOrder, int tag) override;
virtual void removeChild(Node* child, bool cleanup) override;
virtual void reorderChild(Node * child, int zOrder) override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual Texture2D* getTexture(void) const override;
virtual void setTexture(Texture2D *texture) override;
/**
* @code
* When this function bound into js or lua,the parameter will be changed
* In js: var setBlendFunc(var src, var dst)
* @endcode
* @lua NA
*/
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
/**
* @js NA
* @lua NA
*/
virtual const BlendFunc& getBlendFunc(void) const override;
2014-01-03 18:15:56 +08:00
CC_CONSTRUCTOR_ACCESS:
2014-01-03 18:15:56 +08:00
/**
* @js ctor
*/
ParticleBatchNode();
/**
* @js NA
* @lua NA
*/
virtual ~ParticleBatchNode();
2014-01-03 18:15:56 +08:00
/** 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();
2013-12-12 12:07:20 +08:00
void increaseAtlasCapacityTo(ssize_t quantity);
2013-12-05 17:19:01 +08:00
int searchNewPositionInChildrenForZ(int z);
void getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z);
int addChildHelper(ParticleSystem* child, int z, int aTag);
void updateBlendFunc(void);
/** the texture atlas used for drawing the quads */
TextureAtlas* _textureAtlas;
/** the blend function used for drawing the quads */
BlendFunc _blendFunc;
// quad command
BatchCommand _batchCommand;
};
2012-06-20 18:09:11 +08:00
// end of particle_nodes group
/// @}
NS_CC_END
#endif /* __CCPARTICLEBATCHNODE_H__ */