From 23c750c409b9530932dca68a37458d78d92d6657 Mon Sep 17 00:00:00 2001 From: Benedikt Galbavy Date: Tue, 5 Nov 2024 19:45:24 +0100 Subject: [PATCH] Implemented requested changes --- src/Map.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index 66ab990..1653c72 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -24,6 +24,7 @@ #include "TextureManager.h" #include "TileComponent.h" #include "VEGO.h" +#include "tmxlite/Types.hpp" void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map>* textureDict /* backreference */) { @@ -111,7 +112,7 @@ void Map::loadMapTmx(const char* path) return property.getName() == "zIndex"; }); - if (zIndexIterator != properties.end() && std::is_samegetType()), int>::value) { + if (zIndexIterator != properties.end() && std::is_nothrow_convertiblegetType()), int>::value) { zIndex = zIndexIterator->getIntValue(); } @@ -119,16 +120,16 @@ void Map::loadMapTmx(const char* path) for (auto i = 0u; i < tileSets.size(); i++) { auto tilesetTexture = VEGO_Game().textureManager->loadTexture(texturePaths.at(i).c_str()); - int texX, texY; - SDL_QueryTexture(tilesetTexture, nullptr, nullptr, &texX, &texY); + tmx::Vector2i textureSize; + SDL_QueryTexture(tilesetTexture, nullptr, nullptr, &(textureSize.x), &(textureSize.y)); - const auto tileCountX = texX / mapTileSize.x; - const auto tileCountY = texY / mapTileSize.y; + const auto tileCountX = textureSize.x / mapTileSize.x; + const auto tileCountY = textureSize.y / mapTileSize.y; for (auto idx = 0ul; idx < mapSize.x * mapSize.y; idx++) { - if (!(idx < tiles.size() && tiles[idx].ID >= tileSets.at(i).getFirstGID() - && tiles[idx].ID < (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount()))) { + if (idx >= tiles.size() || tiles[idx].ID < tileSets.at(i).getFirstGID() + || tiles[idx].ID >= (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount())) { continue; } @@ -143,8 +144,8 @@ void Map::loadMapTmx(const char* path) v *= mapTileSize.y; //normalise the UV - u /= texX; - v /= texY; + u /= textureSize.x; + v /= textureSize.y; //vert pos const float tilePosX = static_cast(x) * mapTileSize.x;