diff options
-rw-r--r-- | loader/atlas-loader.hpp | 2 | ||||
-rw-r--r-- | loader/atlas-loader.inl | 32 | ||||
-rw-r--r-- | loader/ground-atlas.cpp | 30 | ||||
-rw-r--r-- | loader/ground-traits.cpp | 17 | ||||
-rw-r--r-- | loader/ground-traits.hpp | 1 | ||||
-rw-r--r-- | loader/impl.hpp | 4 | ||||
-rw-r--r-- | loader/loader.hpp | 2 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 1 |
8 files changed, 39 insertions, 50 deletions
diff --git a/loader/atlas-loader.hpp b/loader/atlas-loader.hpp index 9fa82e49..3dc1707a 100644 --- a/loader/atlas-loader.hpp +++ b/loader/atlas-loader.hpp @@ -26,6 +26,8 @@ public: ArrayView<const Cell> ensure_atlas_list(); const std::shared_ptr<Atlas>& get_atlas(StringView name, loader_policy p); + std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& cell); + const Cell& get_invalid_atlas(); }; diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl index a2e3e2a7..dcd6ba27 100644 --- a/loader/atlas-loader.inl +++ b/loader/atlas-loader.inl @@ -4,6 +4,8 @@ #include "atlas-loader.hpp" #include "atlas-loader-storage.hpp" #include "loader/loader.hpp" +#include <memory> +#include <Corrade/Containers/ArrayView.h> namespace floormat::loader_detail { @@ -38,7 +40,7 @@ const std::shared_ptr<ATLAS>& atlas_loader<ATLAS, TRAITS>::get_atlas(StringView switch (p) { - using enum loader_policy; + using enum loader_policy; case error: case ignore: case warn: @@ -50,12 +52,12 @@ const std::shared_ptr<ATLAS>& atlas_loader<ATLAS, TRAITS>::get_atlas(StringView if (name == loader.INVALID) [[unlikely]] switch (p) { - using enum loader_policy; + using enum loader_policy; case error: goto error; case ignore: case warn: - return invalid_atlas->atlas; + return t.atlas_of(*invalid_atlas); } fm_soft_assert(loader.check_atlas_name(name)); @@ -66,29 +68,29 @@ const std::shared_ptr<ATLAS>& atlas_loader<ATLAS, TRAITS>::get_atlas(StringView { switch (p) { - using enum loader_policy; + using enum loader_policy; case error: goto error; case warn: case ignore: - return invalid_atlas->atlas; + return t.atlas_of(*invalid_atlas); } } - else if (!it->second->atlas) - return it->second->atlas = t.make_atlas(name, *it->second); + else if (const auto& atlas = t.atlas_of(*it->second)) + return t.atlas_of(*it->second); else - return it->second->atlas; + return t.atlas_of(*it->second) = t.make_atlas(name, *it->second); } else switch (p) { - using enum loader_policy; + using enum loader_policy; case error: goto error; case warn: goto missing_warn; case ignore: - return invalid_atlas->atlas; + return t.atlas_of(*invalid_atlas); } std::unreachable(); @@ -102,11 +104,15 @@ missing_warn: s.name_map[ s.missing_atlas_names.back() ] = invalid_atlas; if (name != loader.INVALID) - { DBG_nospace << t.loader_name() << " '" << name << "' doesn't exist"; - } - return invalid_atlas->atlas; + return t.atlas_of(*invalid_atlas); +} + +template<typename ATLAS, typename TRAITS> +auto atlas_loader<ATLAS, TRAITS>::make_atlas(StringView name, const Cell& cell) -> std::shared_ptr<Atlas> +{ + return t.make_atlas(name, cell); } template<typename ATLAS, typename TRAITS> diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp index 02186cec..0ea4f768 100644 --- a/loader/ground-atlas.cpp +++ b/loader/ground-atlas.cpp @@ -1,43 +1,23 @@ #include "impl.hpp" -#include "atlas-loader-storage.hpp" #include "atlas-loader.inl" #include "ground-traits.hpp" #include "ground-cell.hpp" -#include "src/tile-constants.hpp" -#include "src/ground-atlas.hpp" -#include "compat/exception.hpp" -#include "serialize/json-helper.hpp" -#include "serialize/ground-atlas.hpp" -#include <Corrade/Containers/ArrayViewStl.h> -#include <Corrade/Utility/Path.h> -#include <Magnum/Trade/ImageData.h> -#include <Magnum/ImageView.h> +#include <Magnum/Math/Vector2.h> namespace floormat::loader_detail { template class atlas_loader<ground_atlas>; -} // namespace floormat::loader_detail - -namespace floormat { - -using loader_detail::atlas_loader_traits; -using ALT = atlas_loader_traits<ground_atlas>; - std::shared_ptr<ground_atlas> -loader_::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) +loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) { fm_assert(name != loader.INVALID); - auto tex = texture(loader.GROUND_TILESET_PATH, name); - auto info = ground_def{name, size, pass}; - auto atlas = std::make_shared<class ground_atlas>(info, tex); + auto atlas = _ground_loader->make_atlas(name, { + .atlas = {}, .name = name, .size = size, .pass = pass, + }); return atlas; } -} // namespace floormat - -namespace floormat::loader_detail { - atlas_loader<class ground_atlas>* loader_impl::make_ground_atlas_loader() { return new atlas_loader<class ground_atlas>; diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp index cf0dee4e..e1fd5e70 100644 --- a/loader/ground-traits.cpp +++ b/loader/ground-traits.cpp @@ -16,12 +16,15 @@ namespace floormat::loader_detail { -StringView atlas_loader_traits<ground_atlas>::loader_name() { return "ground_atlas"_s; } -StringView atlas_loader_traits<ground_atlas>::name_of(const Cell& x) { return x.name; } -auto atlas_loader_traits<ground_atlas>::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; } -StringView atlas_loader_traits<ground_atlas>::name_of(const Atlas& x) { return x.name(); } +using traits = atlas_loader_traits<ground_atlas>; -void atlas_loader_traits<ground_atlas>::ensure_atlases_loaded(Storage& st) +StringView traits::loader_name() { return "ground_atlas"_s; } +auto traits::atlas_of(const Cell& x) -> const std::shared_ptr<Atlas>& { return x.atlas; } +auto traits::atlas_of(Cell& x) -> std::shared_ptr<Atlas>& { return x.atlas; } +StringView traits::name_of(const Cell& x) { return x.name; } +StringView traits::name_of(const Atlas& x) { return x.name(); } + +void traits::ensure_atlases_loaded(Storage& st) { if (!st.is_empty()) [[likely]] return; @@ -64,7 +67,7 @@ void atlas_loader_traits<ground_atlas>::ensure_atlases_loaded(Storage& st) fm_debug_assert(!st.is_empty()); } -auto atlas_loader_traits<ground_atlas>::make_invalid_atlas(Storage& s) -> const Cell& +auto traits::make_invalid_atlas(Storage& s) -> const Cell& { if (!s.invalid_atlas) [[unlikely]] { @@ -76,7 +79,7 @@ auto atlas_loader_traits<ground_atlas>::make_invalid_atlas(Storage& s) -> const return *s.invalid_atlas; } -auto atlas_loader_traits<ground_atlas>::make_atlas(StringView name, const Cell& cell) -> std::shared_ptr<Atlas> +auto traits::make_atlas(StringView name, const Cell& cell) -> std::shared_ptr<Atlas> { auto def = ground_def{name, cell.size, cell.pass}; auto tex = loader.texture(loader.GROUND_TILESET_PATH, name); diff --git a/loader/ground-traits.hpp b/loader/ground-traits.hpp index 56923cd0..df661e26 100644 --- a/loader/ground-traits.hpp +++ b/loader/ground-traits.hpp @@ -15,6 +15,7 @@ template<> struct atlas_loader_traits<ground_atlas> static StringView loader_name(); static const std::shared_ptr<Atlas>& atlas_of(const Cell& x); + static std::shared_ptr<Atlas>& atlas_of(Cell& x); static StringView name_of(const Cell& x); static StringView name_of(const Atlas& x); static void ensure_atlases_loaded(Storage& st); diff --git a/loader/impl.hpp b/loader/impl.hpp index 7bddda29..a1ea4d88 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -14,9 +14,6 @@ namespace floormat::loader_detail { - - - struct loader_impl final : loader_ { explicit loader_impl(); @@ -60,6 +57,7 @@ struct loader_impl final : loader_ const std::shared_ptr<class ground_atlas>& ground_atlas(StringView filename, loader_policy policy) noexcept(false) override; ArrayView<const ground_cell> ground_atlas_list() noexcept(false) override; const ground_cell& make_invalid_ground_atlas() override; + std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) override; // >-----> anim >-----> tsl::robin_map<StringView, std::shared_ptr<class anim_atlas>> anim_atlas_map; diff --git a/loader/loader.hpp b/loader/loader.hpp index faa0269a..452b6fcc 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -58,7 +58,7 @@ struct loader_ virtual const anim_cell& make_invalid_anim_atlas() = 0; /** \deprecated{internal use only}*/ [[nodiscard]] - std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false); + virtual std::shared_ptr<class ground_atlas> get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) = 0; /** \deprecated{internal use only}*/ [[nodiscard]] std::shared_ptr<class wall_atlas> get_wall_atlas(StringView name) noexcept(false); /** \deprecated{internal use only}*/ [[nodiscard]] diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index 80eb6e0f..5baa24f3 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -16,7 +16,6 @@ namespace floormat { using nlohmann::json; -using loader_detail::loader_impl; [[maybe_unused]] static void from_json(const json& j, wall_cell& val) { |