123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- #ifndef __CC_SPRITE_BATCH_NODE_H__
- #define __CC_SPRITE_BATCH_NODE_H__
- #include <vector>
- #include "2d/CCNode.h"
- #include "base/CCProtocols.h"
- #include "renderer/CCTextureAtlas.h"
- #include "renderer/CCBatchCommand.h"
- NS_CC_BEGIN
- class Sprite;
- class CC_DLL SpriteBatchNode : public Node, public TextureProtocol
- {
- static const int DEFAULT_CAPACITY = 29;
- public:
-
- static SpriteBatchNode* createWithTexture(Texture2D* tex, ssize_t capacity = DEFAULT_CAPACITY);
-
- static SpriteBatchNode* create(const std::string& fileImage, ssize_t capacity = DEFAULT_CAPACITY);
-
- TextureAtlas* getTextureAtlas() { return _textureAtlas; }
-
- void setTextureAtlas(TextureAtlas* textureAtlas)
- {
- if (textureAtlas != _textureAtlas)
- {
- CC_SAFE_RETAIN(textureAtlas);
- CC_SAFE_RELEASE(_textureAtlas);
- _textureAtlas = textureAtlas;
- }
- }
-
- const std::vector<Sprite*>& getDescendants() const { return _descendants; }
-
- void increaseAtlasCapacity();
-
- void removeChildAtIndex(ssize_t index, bool doCleanup);
-
-
- void appendChild(Sprite* sprite);
-
-
- void removeSpriteFromAtlas(Sprite *sprite);
-
-
- ssize_t rebuildIndexInOrder(Sprite *parent, ssize_t index);
-
-
- ssize_t highestAtlasIndexInChild(Sprite *sprite);
-
-
- ssize_t lowestAtlasIndexInChild(Sprite *sprite);
-
-
- ssize_t atlasIndexForChild(Sprite *sprite, int z);
-
- void reorderBatch(bool reorder);
-
-
-
-
- virtual Texture2D* getTexture() const override;
- virtual void setTexture(Texture2D *texture) override;
-
- virtual void setBlendFunc(const BlendFunc &blendFunc) override;
-
- virtual const BlendFunc& getBlendFunc() const override;
-
- 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 addChild(Node * child, int zOrder, const std::string &name) override;
- virtual void reorderChild(Node *child, int zOrder) override;
-
- virtual void removeChild(Node *child, bool cleanup) override;
-
- virtual void removeAllChildrenWithCleanup(bool cleanup) override;
- virtual void sortAllChildren() override;
-
- virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
-
- virtual std::string getDescription() const override;
-
- void insertQuadFromSprite(Sprite *sprite, ssize_t index);
-
- SpriteBatchNode * addSpriteWithoutQuad(Sprite *child, int z, int aTag);
-
- void reserveCapacity(ssize_t newCapacity);
- CC_CONSTRUCTOR_ACCESS:
-
- SpriteBatchNode();
-
- virtual ~SpriteBatchNode();
-
-
- bool initWithTexture(Texture2D *tex, ssize_t capacity = DEFAULT_CAPACITY);
-
- bool initWithFile(const std::string& fileImage, ssize_t capacity = DEFAULT_CAPACITY);
- bool init() override;
-
- protected:
-
- void updateQuadFromSprite(Sprite *sprite, ssize_t index);
- void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex);
- void swap(ssize_t oldIndex, ssize_t newIndex);
- void updateBlendFunc();
- TextureAtlas *_textureAtlas;
- BlendFunc _blendFunc;
- BatchCommand _batchCommand;
-
-
-
- std::vector<Sprite*> _descendants;
- };
- NS_CC_END
- #endif
|