Skip to content

Commit

Permalink
update error reporting in SFML example
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Sep 12, 2023
1 parent 2ac3055 commit d259a59
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
8 changes: 4 additions & 4 deletions SFMLExample/SFMLExample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../tmxlite/include;../sfml/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../tmxlite/include;../extlibs/sfml/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../sfml/bin/Debug;../tmxlite/x64/bin/DebugStatic</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../extlibs/sfml/lib;../tmxlite/x64/bin/DebugStatic</AdditionalLibraryDirectories>
<AdditionalDependencies>libtmxlite-s-d.lib;sfml-system-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand All @@ -133,14 +133,14 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../tmxlite/include;../sfml/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../tmxlite/include;../extlibs/sfml/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../sfml/bin/Release;../tmxlite/x64/bin/ReleaseStatic</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../extlibs/sfml/lib;../tmxlite/x64/bin/ReleaseStatic</AdditionalLibraryDirectories>
<AdditionalDependencies>libtmxlite-s.lib;sfml-system.lib;sfml-window.lib;sfml-graphics.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand Down
2 changes: 1 addition & 1 deletion SFMLExample/assets/demo.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.2" orientation="orthogonal" renderorder="right-down" width="15" height="8" tilewidth="64" tileheight="64" infinite="0" nextlayerid="5" nextobjectid="1">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="15" height="8" tilewidth="64" tileheight="64" infinite="0" nextlayerid="5" nextobjectid="1">
<tileset firstgid="1" name="tileset" tilewidth="64" tileheight="64" tilecount="42" columns="6">
<image source="images/tilemap/tileset.png" width="384" height="448"/>
<tile id="0">
Expand Down
34 changes: 20 additions & 14 deletions SFMLExample/src/SFMLOrthogonalLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,20 @@ class MapLayer final : public sf::Drawable
MapLayer(const tmx::Map& map, std::size_t idx)
{
const auto& layers = map.getLayers();
if (map.getOrientation() == tmx::Orientation::Orthogonal &&
idx < layers.size() && layers[idx]->getType() == tmx::Layer::Type::Tile)
if (map.getOrientation() != tmx::Orientation::Orthogonal)
{
std::cout << "Map is not orthogonal - nothing will be drawn" << std::endl;
}
else if (idx >= layers.size())
{
std::cout << "Layer index " << idx << " is out of range, layer count is " << layers.size() << std::endl;
}
else if (layers[idx]->getType() != tmx::Layer::Type::Tile)
{
std::cout << "layer " << idx << " is not a Tile layer..." << std::endl;
}

else
{
//round the chunk size to the nearest tile
const auto tileSize = map.getTileSize();
Expand All @@ -79,10 +91,6 @@ class MapLayer final : public sf::Drawable
m_globalBounds.width = mapSize.width;
m_globalBounds.height = mapSize.height;
}
else
{
std::cout << "Not a valid orthogonal layer, nothing will be drawn." << std::endl;
}
}

~MapLayer() = default;
Expand Down Expand Up @@ -127,7 +135,7 @@ class MapLayer final : public sf::Drawable
as.currentTime += elapsed;

tmx::TileLayer::Tile tile;
std::uint32_t animTime = 0;
std::int32_t animTime = 0;
auto x = as.animTile.animation.frames.begin();
while (animTime < as.currentTime.asMilliseconds())
{
Expand Down Expand Up @@ -183,10 +191,8 @@ class MapLayer final : public sf::Drawable
layerOpacity = static_cast<sf::Uint8>(layer.getOpacity() / 1.f * 255.f);
sf::Color vertColour = sf::Color(200 ,200, 200, layerOpacity);
auto offset = layer.getOffset();
layerOffset.x = offset.x;
layerOffset.x = offset.y;
chunkTileCount.x = tileCount.x;
chunkTileCount.y = tileCount.y;
layerOffset = { static_cast<float>(offset.x), static_cast<float>(offset.y) };
chunkTileCount = { tileCount.x, tileCount.y };
mapTileSize = tileSize;
const auto& tileIDs = layer.getTiles();

Expand Down Expand Up @@ -224,8 +230,8 @@ class MapLayer final : public sf::Drawable
for (const auto& ca : m_chunkArrays)
{
sf::Uint32 idx = 0;
std::size_t xPos = static_cast<std::size_t>(getPosition().x / mapTileSize.x);
std::size_t yPos = static_cast<std::size_t>(getPosition().y / mapTileSize.y);
std::uint32_t xPos = static_cast<std::uint32_t>(getPosition().x / mapTileSize.x);
std::uint32_t yPos = static_cast<std::uint32_t>(getPosition().y / mapTileSize.y);
for (auto y = yPos; y < yPos + chunkTileCount.y; ++y)
{
for (auto x = xPos; x < xPos + chunkTileCount.x; ++x)
Expand All @@ -242,7 +248,7 @@ class MapLayer final : public sf::Drawable
m_activeAnimations.push_back(as);
}

sf::Vector2f tileOffset(x * mapTileSize.x, (float)y * mapTileSize.y + mapTileSize.y - ca->tileSetSize.y);
sf::Vector2f tileOffset(static_cast<float>(x) * mapTileSize.x, static_cast<float>(y) * mapTileSize.y + mapTileSize.y - ca->tileSetSize.y);

auto idIndex = m_chunkTileIDs[idx].ID - ca->m_firstGID;
sf::Vector2f tileIndex(idIndex % ca->tsTileCount.x, idIndex / ca->tsTileCount.x);
Expand Down
5 changes: 3 additions & 2 deletions tmxlite.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29926.136
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tmxlite", "tmxlite\tmxlite.vcxproj", "{0BC0C535-FEBB-4A83-8197-AF74FA26E100}"
EndProject
Expand Down Expand Up @@ -68,6 +68,7 @@ Global
{2298A657-D09A-438E-B976-5EE827966124}.Debug|ARM.ActiveCfg = Debug|Win32
{2298A657-D09A-438E-B976-5EE827966124}.Debug|ARM64.ActiveCfg = Debug|Win32
{2298A657-D09A-438E-B976-5EE827966124}.Debug|x64.ActiveCfg = Debug|x64
{2298A657-D09A-438E-B976-5EE827966124}.Debug|x64.Build.0 = Debug|x64
{2298A657-D09A-438E-B976-5EE827966124}.Debug|x86.ActiveCfg = Debug|Win32
{2298A657-D09A-438E-B976-5EE827966124}.Debug|x86.Build.0 = Debug|Win32
{2298A657-D09A-438E-B976-5EE827966124}.Release|ARM.ActiveCfg = Release|Win32
Expand Down

0 comments on commit d259a59

Please sign in to comment.