tmxlite: D:/W/B/src/tmxlite-1.4.5/tmxlite/include/tmxlite/TileLayer.hpp Source File

tmxlite 1.0.0 lightweight parse for Tiled maps

TileLayer.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2022
3http://trederia.blogspot.com
4
5tmxlite - Zlib license.
6
7This software is provided 'as-is', without any express or
8implied warranty. In no event will the authors be held
9liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute
13it freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented;
16you must not claim that you wrote the original software.
17If you use this software in a product, an acknowledgment
18in the product documentation would be appreciated but
19is not required.
20
212. Altered source versions must be plainly marked as such,
22and must not be misrepresented as being the original software.
23
243. This notice may not be removed or altered from any
25source distribution.
26*********************************************************************/
27
28#pragma once
29
30#include <tmxlite/Layer.hpp>
31#include <tmxlite/Types.hpp>
32
33namespace tmx
34{
38 class TMXLITE_EXPORT_API TileLayer final : public Layer
39 {
40 public:
44 struct Tile final
45 {
46 std::uint32_t ID = 0;
47 std::uint8_t flipFlags = 0;
48 };
49
53 struct Chunk final
54 {
55 Vector2i position; //<! coordinate in tiles, not pixels
56 Vector2i size;
57 std::vector<Tile> tiles;
58 };
59
63 enum FlipFlag
64 {
65 Horizontal = 0x8,
66 Vertical = 0x4,
67 Diagonal = 0x2
68 };
69
70 explicit TileLayer(std::size_t);
71
72 Type getType() const override { return Layer::Type::Tile; }
73 void parse(const pugi::xml_node&, Map*) override;
74
81 const std::vector<Tile>& getTiles() const { return m_tiles; }
82
89 const std::vector<Chunk>& getChunks() const { return m_chunks; }
90
91 private:
92 std::vector<Tile> m_tiles;
93 std::vector<Chunk> m_chunks;
94 std::size_t m_tileCount;
95
96 void parseBase64(const pugi::xml_node&);
97 void parseCSV(const pugi::xml_node&);
98 void parseUnencoded(const pugi::xml_node&);
99
100 void createTiles(const std::vector<std::uint32_t>&, std::vector<Tile>& destination);
101 };
102
103 template <>
104 inline TileLayer& Layer::getLayerAs<TileLayer>()
105 {
106 assert(getType() == Type::Tile);
107 return *static_cast<TileLayer*>(this);
108 }
109
110 template <>
111 inline const TileLayer& Layer::getLayerAs<TileLayer>() const
112 {
113 assert(getType() == Type::Tile);
114 return *static_cast<const TileLayer*>(this);
115 }
116}
tmx::Layer::getLayerAs
T & getLayerAs()
Use this to get a reference to the concrete layer type which this layer points to....
tmx::Layer::Type
Type
Layer type as returned by getType() Tile: this layer is a TileLayer type Object: This layer is an Obj...
Definition Layer.hpp:71
tmx::Layer::getType
virtual Type getType() const =0
Returns a Type value representing the concrete type. Use this when deciding which concrete layer type...
tmx::Map
Parser for TMX format tile maps. This class can be used to parse the XML format tile maps created wit...
Definition Map.hpp:94
tmx::TileLayer
A layer made up from a series of tile sets.
Definition TileLayer.hpp:39
tmx::TileLayer::FlipFlag
FlipFlag
Flags used to tell if a tile is flipped when drawn.
Definition TileLayer.hpp:64
tmx::TileLayer::parse
void parse(const pugi::xml_node &, Map *) override
Attempts to parse the specific node layer type.
tmx::TileLayer::getTiles
const std::vector< Tile > & getTiles() const
Returns the list of tiles used to make up the layer If this is empty then the map is most likely infi...
Definition TileLayer.hpp:81
tmx::TileLayer::getType
Type getType() const override
Returns a Type value representing the concrete type. Use this when deciding which concrete layer type...
Definition TileLayer.hpp:72
tmx::TileLayer::getChunks
const std::vector< Chunk > & getChunks() const
Returns a vector of chunks which make up this layer if the map is set to infinite....
Definition TileLayer.hpp:89
tmx::TileLayer::Chunk
Represents a chunk of tile data, if this is an infinite map.
Definition TileLayer.hpp:54
tmx::TileLayer::Chunk::size
Vector2i size
size in tiles, not pixels
Definition TileLayer.hpp:56
tmx::TileLayer::Tile
Tile information for a layer.
Definition TileLayer.hpp:45
tmx::TileLayer::Tile::flipFlags
std::uint8_t flipFlags
Flags marking if the tile should be flipped when drawn.
Definition TileLayer.hpp:47
tmx::TileLayer::Tile::ID
std::uint32_t ID
Global ID of the tile.
Definition TileLayer.hpp:46