Skip to content

Commit

Permalink
update to latest SFML
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jun 5, 2024
1 parent 28edfb4 commit 6cf66cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set(SFML_ENABLE_PCH true)
CPMAddPackage(
NAME SFML
GITHUB_REPOSITORY vittorioromeo/SFML
GIT_TAG 1774e83b5fbd068151aabd7a4fa2b0bd4af4e0bd
GIT_TAG 17879283be7a95fd66ce76e61410ebee299819ba
)

set_target_properties(sfml-system PROPERTIES UNITY_BUILD OFF)
Expand Down Expand Up @@ -186,8 +186,8 @@ endif()
if(NOT SSVOH_ANDROID)
CPMAddPackage(
NAME imgui-sfml
GITHUB_REPOSITORY SFML/imgui-sfml
GIT_TAG 4727cf135a0e412d1f5b2e7fa402283dce0c91da
GITHUB_REPOSITORY vittorioromeo/imgui-sfml
GIT_TAG a128357d5f5841e49ee113fad8d5810ab0d9ac0e
)

set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON)
Expand Down
29 changes: 9 additions & 20 deletions src/SSVOpenHexagon/Global/AssetStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "SSVOpenHexagon/Global/Assert.hpp"

#include "SSVOpenHexagon/Global/Macros.hpp"
#include "SSVOpenHexagon/Utils/Concat.hpp"
#include "SSVOpenHexagon/Utils/UniquePtr.hpp"

#include <SFML/Graphics/Font.hpp>
Expand All @@ -21,24 +20,6 @@

namespace hg {

template <typename Map, typename Key, typename F>
[[nodiscard]] static decltype(auto) tryEmplaceAndThen(
Map& map, const Key& key, F&& f)
{
auto [it, inserted] =
map.emplace(std::piecewise_construct, std::tuple{key}, std::tuple{});

return inserted && f(it->second);
}

template <typename Map, typename Key>
[[nodiscard]] static decltype(auto) tryEmplaceAndThenLoadFromFile(
Map& map, const Key& key, const std::string& path)
{
return tryEmplaceAndThen(
map, key, [&path](auto& value) { return value.loadFromFile(path); });
}

template <typename Map, typename Key>
[[nodiscard]] static auto* getAsPtr(Map& map, const Key& key) noexcept
{
Expand All @@ -57,7 +38,15 @@ class AssetStorage::AssetStorageImpl
[[nodiscard]] bool loadTexture(
const std::string& id, const std::string& path)
{
return tryEmplaceAndThenLoadFromFile(_textures, id, path);
std::optional texture = sf::Texture::loadFromFile(path);

if (!texture.has_value())
{
return false;
}

auto [it, inserted] = _textures.emplace(id, *SSVOH_MOVE(texture));
return inserted;
}

[[nodiscard]] bool loadFont(const std::string& id, const std::string& path)
Expand Down
7 changes: 4 additions & 3 deletions src/SSVOpenHexagon/Global/Assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,11 @@ HGAssets::HGAssetsImpl::~HGAssetsImpl()
[[nodiscard]] sf::Texture& HGAssets::HGAssetsImpl::getTextureOrNullTexture(
const std::string& mId)
{
static sf::Texture nullTexture;
sf::Texture* ptr = assetStorage->getTexture(mId);
static auto nullTexture = sf::Texture::create({1u, 1u});
SSVOH_ASSERT(nullTexture.has_value());

return ptr ? *ptr : nullTexture;
sf::Texture* ptr = assetStorage->getTexture(mId);
return ptr ? *ptr : *nullTexture;
}

[[nodiscard]] sf::Font& HGAssets::HGAssetsImpl::getFont(const std::string& mId)
Expand Down

0 comments on commit 6cf66cf

Please sign in to comment.