| 170 | } |
| 171 | |
| 172 | static bool addLayer( |
| 173 | std::list<TileNode::TileQuad>& tileQuads, |
| 174 | const tmx::Map& map, |
| 175 | tmx::Layer* target, |
| 176 | std::vector<TileNode::AnimatedTile>& animatedTiles, |
| 177 | std::vector<TileNode::Animation>& animations) { |
| 178 | if (!target) return false; |
| 179 | switch (target->getType()) { |
| 180 | case tmx::Layer::Type::Group: { |
| 181 | auto& layer = target->getLayerAs<tmx::LayerGroup>(); |
| 182 | for (const auto& lyr : layer.getLayers()) { |
| 183 | if (lyr->getType() != tmx::Layer::Type::Tile && lyr->getType() != tmx::Layer::Type::Group) { |
| 184 | continue; |
| 185 | } |
| 186 | if (!addLayer(tileQuads, map, lyr.get(), animatedTiles, animations)) { |
| 187 | return false; |
| 188 | } |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | case tmx::Layer::Type::Tile: |
| 193 | break; |
| 194 | default: |
| 195 | return false; |
| 196 | } |
| 197 | auto& layer = target->getLayerAs<tmx::TileLayer>(); |
| 198 | const auto offset = layer.getOffset(); |
| 199 | const auto mapSize = map.getTileCount(); |
| 200 | |
| 201 | const auto tc = target->getTintColour(); |
| 202 | const auto vertColor = Color{tc.r, tc.g, tc.b, tc.a}.toABGR(); |
| 203 | |
| 204 | if (map.isInfinite()) { |
| 205 | const auto mapTileSize = map.getTileSize(); |
| 206 | const auto tileSize = tmx::Vector2i{s_cast<int>(mapTileSize.x), s_cast<int>(mapTileSize.y)}; |
| 207 | for (const auto& chunk : layer.getChunks()) { |
| 208 | if (!addTiles( |
| 209 | tileQuads, |
| 210 | map, |
| 211 | chunk.tiles, |
| 212 | {s_cast<unsigned int>(chunk.size.x), s_cast<unsigned int>(chunk.size.y)}, |
| 213 | offset + chunk.position * tileSize, |
| 214 | mapSize.y, |
| 215 | vertColor, |
| 216 | animatedTiles, |
| 217 | animations)) { |
| 218 | return false; |
| 219 | } |
| 220 | } |
| 221 | } else { |
| 222 | const auto& tileIDs = layer.getTiles(); |
| 223 | if (!addTiles( |
| 224 | tileQuads, |
| 225 | map, |
| 226 | tileIDs, |
| 227 | mapSize, |
| 228 | offset, |
| 229 | mapSize.y, vertColor, animatedTiles, animations)) { |