diff options
Diffstat (limited to 'loader')
-rw-r--r-- | loader/anim-atlas.cpp | 4 | ||||
-rw-r--r-- | loader/anim-traits.cpp | 2 | ||||
-rw-r--r-- | loader/anim-traits.hpp | 2 | ||||
-rw-r--r-- | loader/atlas-loader-storage.hpp | 4 | ||||
-rw-r--r-- | loader/atlas-loader.hpp | 4 | ||||
-rw-r--r-- | loader/atlas-loader.inl | 32 | ||||
-rw-r--r-- | loader/ground-atlas.cpp | 8 | ||||
-rw-r--r-- | loader/ground-traits.cpp | 2 | ||||
-rw-r--r-- | loader/ground-traits.hpp | 2 | ||||
-rw-r--r-- | loader/wall-traits.cpp | 2 | ||||
-rw-r--r-- | loader/wall-traits.hpp | 2 |
11 files changed, 48 insertions, 16 deletions
diff --git a/loader/anim-atlas.cpp b/loader/anim-atlas.cpp index be7cc688..1c1a7ec0 100644 --- a/loader/anim-atlas.cpp +++ b/loader/anim-atlas.cpp @@ -3,7 +3,6 @@ #include "anim-cell.hpp" #include "anim-traits.hpp" #include "compat/exception.hpp" -//#include "src/anim-atlas.hpp" namespace floormat::loader_detail { @@ -26,11 +25,8 @@ ArrayView<const anim_cell> loader_impl::anim_atlas_list() std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir, loader_policy p) noexcept(false) { - fm_soft_assert(check_atlas_name(name)); - char buf[fm_FILENAME_MAX]; auto path = make_atlas_path(buf, dir, name); - return _anim_loader->get_atlas(path, p); } diff --git a/loader/anim-traits.cpp b/loader/anim-traits.cpp index e15956e9..dafed985 100644 --- a/loader/anim-traits.cpp +++ b/loader/anim-traits.cpp @@ -26,7 +26,7 @@ StringView anim_traits::name_of(const Cell& x) { return x.name; } StringView anim_traits::name_of(const Atlas& x) { return x.name(); } String& anim_traits::name_of(Cell& x) { return x.name; } -void anim_traits::ensure_atlases_loaded(Storage& s) +void anim_traits::load_atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); s.cell_array = {}; diff --git a/loader/anim-traits.hpp b/loader/anim-traits.hpp index 8eef8b89..70ddcd89 100644 --- a/loader/anim-traits.hpp +++ b/loader/anim-traits.hpp @@ -19,7 +19,7 @@ template<> struct atlas_loader_traits<anim_atlas> static StringView name_of(const Cell& x); static StringView name_of(const Atlas& x); static String& name_of(Cell& x); - static void ensure_atlases_loaded(Storage& st); + static void load_atlas_list(Storage& st); static Pointer<Cell> make_invalid_atlas(Storage& st); static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); diff --git a/loader/atlas-loader-storage.hpp b/loader/atlas-loader-storage.hpp index ca3ccbab..aea94e48 100644 --- a/loader/atlas-loader-storage.hpp +++ b/loader/atlas-loader-storage.hpp @@ -13,8 +13,8 @@ struct atlas_storage static_assert(std::is_same_v<typename TRAITS::Atlas, ATLAS>); using Traits = TRAITS; - using Atlas = typename TRAITS::Atlas; - using Cell = typename TRAITS::Cell; + using Atlas = typename Traits::Atlas; + using Cell = typename Traits::Cell; tsl::robin_map<StringView, size_t, hash_string_view> name_map; std::vector<Cell> cell_array; diff --git a/loader/atlas-loader.hpp b/loader/atlas-loader.hpp index 3dc1707a..919e4c90 100644 --- a/loader/atlas-loader.hpp +++ b/loader/atlas-loader.hpp @@ -28,6 +28,10 @@ public: const std::shared_ptr<Atlas>& get_atlas(StringView name, loader_policy p); std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& cell); + bool cell_exists(StringView name); + const Cell& get_cell(StringView name); + void register_cell(Cell&& c); + const Cell& get_invalid_atlas(); }; diff --git a/loader/atlas-loader.inl b/loader/atlas-loader.inl index 08667d63..78bafaac 100644 --- a/loader/atlas-loader.inl +++ b/loader/atlas-loader.inl @@ -8,6 +8,7 @@ #include <memory> #include <cr/ArrayView.h> #include <cr/Optional.h> +#include <cr/Move.h> namespace floormat::loader_detail { @@ -28,7 +29,7 @@ auto atlas_loader<ATLAS, TRAITS>::ensure_atlas_list() -> ArrayView<const Cell> if (!s.name_map.empty()) [[likely]] return { s.cell_array.data(), s.cell_array.size() }; - t.ensure_atlases_loaded(s); + t.load_atlas_list(s); for (Cell& c : s.cell_array) { @@ -190,4 +191,33 @@ auto atlas_loader<ATLAS, TRAITS>::get_invalid_atlas() -> const Cell& return *s.invalid_atlas; } +template<typename ATLAS, typename TRAITS> +bool atlas_loader<ATLAS, TRAITS>::cell_exists(Corrade::Containers::StringView name) +{ + return s.name_map.contains(name); +} + +template<typename ATLAS, typename TRAITS> +auto atlas_loader<ATLAS, TRAITS>::get_cell(StringView name) -> const Cell& +{ + auto it = s.name_map.find(name); + fm_assert(it != s.name_map.end()); + return s.cell_array[ it->second ]; +} + +template<typename ATLAS, typename TRAITS> +void atlas_loader<ATLAS, TRAITS>::register_cell(Cell&& c) +{ + String& name{t.name_of(c)}; + if (name.isSmall()) + name = String{AllocatedInit, name}; + const std::shared_ptr<Atlas>& atlas{t.atlas_of(c)}; + fm_assert(!s.name_map.contains(name)); + fm_soft_assert(loader.check_atlas_name(name)); + fm_assert(!atlas || t.name_of(*atlas) == name); + const size_t index{s.cell_array.size()}; + s.cell_array.push_back(Utility::move(c)); + s.name_map[ t.name_of(s.cell_array.back()) ] = index; +} + } // namespace floormat::loader_detail diff --git a/loader/ground-atlas.cpp b/loader/ground-atlas.cpp index 9ca9cb9b..6e829b13 100644 --- a/loader/ground-atlas.cpp +++ b/loader/ground-atlas.cpp @@ -11,10 +11,9 @@ template class atlas_loader<ground_atlas>; std::shared_ptr<ground_atlas> loader_impl::get_ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) { - auto atlas = _ground_loader->make_atlas(name, { + return _ground_loader->make_atlas(name, { .atlas = {}, .name = {}, .size = size, .pass = pass, }); - return atlas; } atlas_loader<class ground_atlas>* loader_impl::make_ground_atlas_loader() @@ -22,7 +21,10 @@ atlas_loader<class ground_atlas>* loader_impl::make_ground_atlas_loader() return new atlas_loader<class ground_atlas>; } -auto loader_impl::ground_atlas_list() noexcept(false) -> ArrayView<const ground_cell> { return _ground_loader->ensure_atlas_list(); } +auto loader_impl::ground_atlas_list() noexcept(false) -> ArrayView<const ground_cell> +{ + return _ground_loader->ensure_atlas_list(); +} const ground_cell& loader_impl::make_invalid_ground_atlas() { diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp index ae6e17bc..e913d385 100644 --- a/loader/ground-traits.cpp +++ b/loader/ground-traits.cpp @@ -22,7 +22,7 @@ StringView ground_traits::name_of(const Cell& x) { return x.name; } StringView ground_traits::name_of(const Atlas& x) { return x.name(); } String& ground_traits::name_of(Cell& x) { return x.name; } -void ground_traits::ensure_atlases_loaded(Storage& s) +void ground_traits::load_atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); s.cell_array = ground_cell::load_atlases_from_json().vec; diff --git a/loader/ground-traits.hpp b/loader/ground-traits.hpp index 6eaf3444..91f6c3aa 100644 --- a/loader/ground-traits.hpp +++ b/loader/ground-traits.hpp @@ -19,7 +19,7 @@ template<> struct atlas_loader_traits<ground_atlas> static StringView name_of(const Cell& x); static StringView name_of(const Atlas& x); static String& name_of(Cell& x); - static void ensure_atlases_loaded(Storage& s); + static void load_atlas_list(Storage& s); static Pointer<Cell> make_invalid_atlas(Storage& st); static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index 182d30b2..634659cd 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -22,7 +22,7 @@ StringView wall_traits::name_of(const Cell& x) { return x.name; } StringView wall_traits::name_of(const Atlas& x) { return x.name(); } String& wall_traits::name_of(Cell& x) { return x.name; } -void wall_traits::ensure_atlases_loaded(Storage& s) +void wall_traits::load_atlas_list(Storage& s) { fm_debug_assert(s.name_map.empty()); s.cell_array = wall_cell::load_atlases_from_json().vec; diff --git a/loader/wall-traits.hpp b/loader/wall-traits.hpp index a3134b22..e773ef58 100644 --- a/loader/wall-traits.hpp +++ b/loader/wall-traits.hpp @@ -19,7 +19,7 @@ template<> struct atlas_loader_traits<wall_atlas> static StringView name_of(const Cell& x); static StringView name_of(const Atlas& x); static String& name_of(Cell& x); - static void ensure_atlases_loaded(Storage& st); + static void load_atlas_list(Storage& st); static Pointer<Cell> make_invalid_atlas(Storage& st); static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); static Optional<Cell> make_cell(StringView name); |