diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index bfa615f775..7bec79a9b6 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -49,10 +49,9 @@ THE SOFTWARE. NS_CC_BEGIN -namespace -{ - static const int MAX_QUADS_COUNT = 65536 / 6; -} +const int FastTMXLayer::FAST_TMX_ORIENTATION_ORTHO = 0; +const int FastTMXLayer::FAST_TMX_ORIENTATION_HEX = 1; +const int FastTMXLayer::FAST_TMX_ORIENTATION_ISO = 2; // FastTMXLayer - init & alloc & dealloc FastTMXLayer * FastTMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo) @@ -114,7 +113,7 @@ FastTMXLayer::FastTMXLayer() , _mapTileSize(Size::ZERO) , _tiles(nullptr) , _tileSet(nullptr) -, _layerOrientation(FastTMXOrientationOrtho) +, _layerOrientation(FAST_TMX_ORIENTATION_ORTHO) ,_texture(nullptr) , _vertexZvalue(0) , _useAutomaticVertexZ(false) @@ -216,7 +215,7 @@ void FastTMXLayer::updateTiles(const Rect& culledRect) int tilesOverY = 0; // for diagonal oriention tiles float tileSizeMax = std::max(tileSize.width, tileSize.height); - if (_layerOrientation == FastTMXOrientationOrtho) + if (_layerOrientation == FAST_TMX_ORIENTATION_ORTHO) { tilesOverX = ceil(tileSizeMax / mapTileSize.width) - 1; tilesOverY = ceil(tileSizeMax / mapTileSize.height) - 1; @@ -224,7 +223,7 @@ void FastTMXLayer::updateTiles(const Rect& culledRect) if (tilesOverX < 0) tilesOverX = 0; if (tilesOverY < 0) tilesOverY = 0; } - else if(_layerOrientation == FastTMXOrientationIso) + else if(_layerOrientation == FAST_TMX_ORIENTATION_ISO) { Rect overTileRect(0, 0, tileSizeMax - mapTileSize.width, tileSizeMax - mapTileSize.height); if (overTileRect.size.width < 0) overTileRect.size.width = 0; @@ -234,6 +233,11 @@ void FastTMXLayer::updateTiles(const Rect& culledRect) tilesOverX = ceil(overTileRect.origin.x + overTileRect.size.width) - floor(overTileRect.origin.x); tilesOverY = ceil(overTileRect.origin.y + overTileRect.size.height) - floor(overTileRect.origin.y); } + else + { + //do nothing, do not support + CCASSERT(0, "TMX invalid value"); + } _indicesVertexZNumber.clear(); @@ -327,18 +331,18 @@ void FastTMXLayer::setupTiles() switch (_layerOrientation) { - case FastTMXOrientationOrtho: + case FAST_TMX_ORIENTATION_ORTHO: _screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 1; _screenGridSize.height = ceil(screenSize.height / _mapTileSize.height) + 1; // tiles could be bigger than the grid, add additional rows if needed _screenGridSize.height += _tileSet->_tileSize.height / _mapTileSize.height; break; - case FastTMXOrientationIso: + case FAST_TMX_ORIENTATION_ISO: _screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 2; _screenGridSize.height = ceil(screenSize.height / (_mapTileSize.height/2)) + 4; break; - case FastTMXOrientationHex: + case FAST_TMX_ORIENTATION_HEX: default: CCLOGERROR("FastTMX does not support type %d", _layerOrientation); break; @@ -356,7 +360,7 @@ Mat4 FastTMXLayer::tileToNodeTransform() switch(_layerOrientation) { - case FastTMXOrientationOrtho: + case FAST_TMX_ORIENTATION_ORTHO: { _tileToNodeTransform = Mat4 ( @@ -368,7 +372,7 @@ Mat4 FastTMXLayer::tileToNodeTransform() return _tileToNodeTransform; } - case FastTMXOrientationIso: + case FAST_TMX_ORIENTATION_ISO: { float offX = (_layerSize.width - 1) * w / 2; _tileToNodeTransform = Mat4 @@ -380,7 +384,7 @@ Mat4 FastTMXLayer::tileToNodeTransform() ); return _tileToNodeTransform; } - case FastTMXOrientationHex: + case FAST_TMX_ORIENTATION_HEX: { _tileToNodeTransform = Mat4::IDENTITY; return _tileToNodeTransform; @@ -604,14 +608,14 @@ int FastTMXLayer::getVertexZForPos(const Vec2& pos) { switch (_layerOrientation) { - case FastTMXOrientationIso: + case FAST_TMX_ORIENTATION_ISO: maxVal = static_cast(_layerSize.width + _layerSize.height); ret = static_cast(-(maxVal - (pos.x + pos.y))); break; - case FastTMXOrientationOrtho: + case FAST_TMX_ORIENTATION_ORTHO: ret = static_cast(-(_layerSize.height-pos.y)); break; - case FastTMXOrientationHex: + case FAST_TMX_ORIENTATION_HEX: CCASSERT(0, "TMX Hexa zOrder not supported"); break; default: @@ -713,15 +717,16 @@ Vec2 FastTMXLayer::calculateLayerOffset(const Vec2& pos) Vec2 ret = Vec2::ZERO; switch (_layerOrientation) { - case FastTMXOrientationOrtho: + case FAST_TMX_ORIENTATION_ORTHO: ret = Vec2( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height); break; - case FastTMXOrientationIso: + case FAST_TMX_ORIENTATION_ISO: ret = Vec2((_mapTileSize.width /2) * (pos.x - pos.y), (_mapTileSize.height /2 ) * (-pos.x - pos.y)); break; - case FastTMXOrientationHex: - CCASSERT(pos.equals(Vec2::ZERO), "offset for hexagonal map not implemented yet"); + case FAST_TMX_ORIENTATION_HEX: + default: + CCASSERT(pos.equals(Vec2::ZERO), "offset for this map not implemented yet"); break; } return ret; diff --git a/cocos/2d/CCFastTMXLayer.h b/cocos/2d/CCFastTMXLayer.h index 5b54eb018b..f007c698a5 100644 --- a/cocos/2d/CCFastTMXLayer.h +++ b/cocos/2d/CCFastTMXLayer.h @@ -24,8 +24,8 @@ 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 __CCTMX_LAYER2_H__ -#define __CCTMX_LAYER2_H__ +#ifndef __CC_FAST_TMX_LAYER_H__ +#define __CC_FAST_TMX_LAYER_H__ #include "CCTMXObjectGroup.h" #include "CCTMXXMLParser.h" @@ -73,10 +73,7 @@ For further information, please see the programming guide: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps -@since v0.8.1 -Tiles can have tile flags for additional properties. At the moment only flip horizontal and flip vertical are used. These bit flags are defined in TMXXMLParser.h. - -@since 1.1 +@since v3.2 */ class CC_DLL FastTMXLayer : public Node @@ -97,9 +94,6 @@ public: /** returns the tile gid at a given tile coordinate. It also returns the tile flags. */ int getTileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr); - CC_DEPRECATED_ATTRIBUTE int tileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr){ - return getTileGIDAt(tileCoordinate, flags); - }; /** sets the tile gid (gid = tile global id) at a given tile coordinate. The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1. @@ -121,11 +115,9 @@ public: /** returns the position in points of a given tile coordinate */ Vec2 getPositionAt(const Vec2& tileCoordinate); - CC_DEPRECATED_ATTRIBUTE Vec2 positionAt(const Vec2& tileCoordinate) { return getPositionAt(tileCoordinate); }; /** return the value for the specific property name */ Value getProperty(const std::string& propertyName) const; - CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const std::string& propertyName) const { return getProperty(propertyName); }; /** Creates the tiles */ void setupTiles(); @@ -254,6 +246,12 @@ protected: std::unordered_map _indicesVertexZNumber; std::vector _renderCommands; bool _dirty; + +public: + /** Possible orientations of the TMX map */ + static const int FAST_TMX_ORIENTATION_ORTHO; + static const int FAST_TMX_ORIENTATION_HEX; + static const int FAST_TMX_ORIENTATION_ISO; }; // end of tilemap_parallax_nodes group diff --git a/cocos/2d/CCFastTMXTiledMap.h b/cocos/2d/CCFastTMXTiledMap.h index 7a2ccdfa42..9dfc098552 100644 --- a/cocos/2d/CCFastTMXTiledMap.h +++ b/cocos/2d/CCFastTMXTiledMap.h @@ -24,8 +24,8 @@ 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 __CCTMX_TILE_MAP2_H__ -#define __CCTMX_TILE_MAP2_H__ +#ifndef __CC_FAST_TMX_TILEMAP_H__ +#define __CC_FAST_TMX_TILEMAP_H__ #include "CCNode.h" #include "CCTMXObjectGroup.h" @@ -38,24 +38,6 @@ class TMXLayerInfo; class TMXTilesetInfo; class TMXMapInfo; -/** - * @addtogroup tilemap_parallax_nodes - * @{ - */ - -/** Possible orientations of the TMX map */ -enum -{ - /** Orthogonal orientation */ - FastTMXOrientationOrtho, - - /** Hexagonal orientation */ - FastTMXOrientationHex, - - /** Isometric orientation */ - FastTMXOrientationIso, -}; - /** @brief FastTMXTiledMap knows how to parse and render a TMX map. It adds support for the TMX tiled map format used by http://www.mapeditor.org @@ -105,7 +87,7 @@ layer->getProperty(name_of_the_property); objectGroup->getProperty(name_of_the_property); object->getProperty(name_of_the_property); -@since v0.8.1 +@since v3.2 */ class CC_DLL FastTMXTiledMap : public Node { @@ -118,31 +100,15 @@ public: /** return the FastTMXLayer for the specific layer */ FastTMXLayer* getLayer(const std::string& layerName) const; - /** - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE FastTMXLayer* layerNamed(const std::string& layerName) const { return getLayer(layerName); }; /** return the TMXObjectGroup for the specific group */ TMXObjectGroup* getObjectGroup(const std::string& groupName) const; - /** - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE TMXObjectGroup* objectGroupNamed(const std::string& groupName) const { return getObjectGroup(groupName); }; /** return the value for the specific property name */ Value getProperty(const std::string& propertyName) const; - /** - * @js NA - * @lua NA - */ - CC_DEPRECATED_ATTRIBUTE Value propertyNamed(const char *propertyName) const { return getProperty(propertyName); }; /** return properties dictionary for tile GID */ Value getPropertiesForGID(int GID) const; - CC_DEPRECATED_ATTRIBUTE Value propertiesForGID(int GID) const { return getPropertiesForGID(GID); }; /** the map's size property measured in tiles */ inline const Size& getMapSize() const { return _mapSize; }; @@ -164,7 +130,7 @@ public: }; /** properties */ - inline ValueMap& getProperties() { return _properties; }; + inline const ValueMap& getProperties() const { return _properties; }; inline void setProperties(const ValueMap& properties) { _properties = properties; }; diff --git a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp index 0e8435e133..9df7f7cad5 100644 --- a/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp +++ b/tests/cpp-tests/Classes/TileMapTest/TileMapTest2.cpp @@ -30,8 +30,6 @@ namespace static int sceneIdx = -1; -#define MAX_LAYER 27 - static std::function createFunctions[] = { CLN(TMXIsoZorderNew), CLN(TMXOrthoZorderNew), @@ -45,7 +43,7 @@ namespace CLN(TMXIsoTest1New), CLN(TMXIsoTest2New), CLN(TMXUncompressedTestNew), - CLN(TMXHexTestNew), + //CLN(TMXHexTestNew), CLN(TMXReadWriteTestNew), CLN(TMXTilesetTestNew), CLN(TMXOrthoObjectsTestNew), @@ -64,6 +62,8 @@ namespace CLN(TMXGIDObjectsTestNew), }; + +#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) Layer* createTileMalayer(int nIndex) {