123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #ifndef __CC_FAST_TMX_LAYER_H__
- #define __CC_FAST_TMX_LAYER_H__
- #include <map>
- #include <unordered_map>
- #include "2d/CCNode.h"
- #include "2d/CCTMXXMLParser.h"
- #include "renderer/CCPrimitiveCommand.h"
- #include "base/CCMap.h"
- NS_CC_BEGIN
- class TMXMapInfo;
- class TMXLayerInfo;
- class TMXTilesetInfo;
- class Texture2D;
- class Sprite;
- struct _ccCArray;
- namespace experimental{
- class CC_DLL TMXLayer : public Node
- {
- public:
-
- static TMXLayer * create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
-
- TMXLayer();
-
- virtual ~TMXLayer();
-
- int getTileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr);
-
- void setTileGID(int gid, const Vec2& tileCoordinate);
-
- void setTileGID(int gid, const Vec2& tileCoordinate, TMXTileFlags flags);
-
- void removeTileAt(const Vec2& tileCoordinate);
-
- Vec2 getPositionAt(const Vec2& tileCoordinate);
-
- Value getProperty(const std::string& propertyName) const;
-
- void setupTiles();
-
-
- const std::string& getLayerName() { return _layerName; }
-
-
- void setLayerName(const std::string& layerName) { _layerName = layerName; }
-
- const Size& getLayerSize() const { return _layerSize; }
-
-
- void setLayerSize(const Size& size) { _layerSize = size; }
-
-
- const Size& getMapTileSize() const { return _mapTileSize; }
-
-
- void setMapTileSize(const Size& size) { _mapTileSize = size; }
-
-
- const uint32_t* getTiles() const { return _tiles; };
-
-
- void setTiles(uint32_t* tiles) { _tiles = tiles; _quadsDirty = true;};
-
-
- TMXTilesetInfo* getTileSet() const { return _tileSet; }
-
-
- void setTileSet(TMXTilesetInfo* info) {
- CC_SAFE_RETAIN(info);
- CC_SAFE_RELEASE(_tileSet);
- _tileSet = info;
- }
-
-
- int getLayerOrientation() const { return _layerOrientation; }
-
-
- void setLayerOrientation(int orientation) { _layerOrientation = orientation; }
-
-
- const ValueMap& getProperties() const { return _properties; }
-
-
- ValueMap& getProperties() { return _properties; }
-
-
- void setProperties(const ValueMap& properties)
- {
- _properties = properties;
- }
-
- Sprite* getTileAt(const Vec2& tileCoordinate);
-
-
- void setupTileSprite(Sprite* sprite, const Vec2& pos, uint32_t gid);
-
-
-
- virtual std::string getDescription() const override;
- virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;
- void removeChild(Node* child, bool cleanup = true) override;
- protected:
- bool initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
- void updateTiles(const Rect& culledRect);
- Vec2 calculateLayerOffset(const Vec2& offset);
-
- void parseInternalProperties();
-
- Mat4 tileToNodeTransform();
- Rect tileBoundsForClipTransform(const Mat4 &tileToClip);
-
- int getVertexZForPos(const Vec2& pos);
-
-
- void setFlaggedTileGIDByIndex(int index, uint32_t gid);
-
-
- void updateTotalQuads();
-
- void onDraw(Primitive* primitive);
- int getTileIndexByPos(int x, int y) const { return x + y * (int) _layerSize.width; }
-
- void updateVertexBuffer();
- void updateIndexBuffer();
- void updatePrimitives();
- protected:
-
-
- std::string _layerName;
-
- Size _layerSize;
-
- Size _mapTileSize;
-
- uint32_t* _tiles;
-
- TMXTilesetInfo* _tileSet;
-
- int _layerOrientation;
-
- ValueMap _properties;
- Texture2D *_texture;
-
-
- std::map<int, std::pair<Sprite*, int> > _spriteContainer;
-
- Size _screenGridSize;
- Rect _screenGridRect;
- int _screenTileCount;
-
- int _vertexZvalue;
- bool _useAutomaticVertexZ;
-
-
- Mat4 _tileToNodeTransform;
-
- bool _quadsDirty;
- std::vector<int> _tileToQuadIndex;
- std::vector<V3F_C4B_T2F_Quad> _totalQuads;
- #ifdef CC_FAST_TILEMAP_32_BIT_INDICES
- std::vector<GLuint> _indices;
- #else
- std::vector<GLushort> _indices;
- #endif
- std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets;
- std::unordered_map<int/*vertexZ*/, int/*number to quads*/> _indicesVertexZNumber;
- std::vector<PrimitiveCommand> _renderCommands;
- bool _dirty;
-
- VertexBuffer* _vertexBuffer;
-
- VertexData* _vData;
-
- IndexBuffer* _indexBuffer;
-
- Map<int , Primitive*> _primitives;
-
- public:
-
- static const int FAST_TMX_ORIENTATION_ORTHO;
- static const int FAST_TMX_ORIENTATION_HEX;
- static const int FAST_TMX_ORIENTATION_ISO;
- };
- }
- NS_CC_END
- #endif
|