From a0734389692cc09af3344020506e7a8998e2d6a9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 22 Nov 2023 10:09:22 +0100 Subject: a --- loader/impl.hpp | 2 +- loader/wall-atlas.cpp | 39 ++++++--------------------------------- 2 files changed, 7 insertions(+), 34 deletions(-) (limited to 'loader') diff --git a/loader/impl.hpp b/loader/impl.hpp index 4bb21159..ec571ae4 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -51,7 +51,7 @@ struct loader_impl final : loader_ const wall_info& wall_atlas(StringView name, StringView dir) override; ArrayView wall_atlas_list() override; void get_wall_atlas_list(); - std::shared_ptr get_wall_atlas(StringView pathname); + std::shared_ptr get_wall_atlas(StringView name, StringView path); // >-----> tile >-----> tsl::robin_map> tile_atlas_map; diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index 99727e86..4ade3fbb 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace floormat { @@ -20,40 +21,12 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(wall_info, name, descr) namespace floormat::loader_detail { -std::shared_ptr loader_impl::get_wall_atlas(StringView filename) +std::shared_ptr loader_impl::get_wall_atlas(StringView name, StringView path) { - auto def = wall_atlas_def::deserialize(""_s.join({filename, ".json"_s})); - auto tex = texture(""_s, filename); - using namespace floormat::Wall; - using namespace floormat::Wall::detail; + auto def = wall_atlas_def::deserialize(""_s.join({path, ".json"_s})); + auto tex = texture(""_s, path); - const auto jroot = json_helper::from_json_(filename); - auto header = read_info_header(jroot); - auto frames = read_all_frames(jroot); - - size_t direction_count = 0; - for (const auto& [str, curdir] : wall_atlas::directions) - if (jroot.contains(std::string_view{str.data(), str.size()})) - direction_count++; - fm_soft_assert(direction_count > 0); - fm_debug_assert(direction_count <= (size_t)Direction_::COUNT); - - auto directions = Array{direction_count}; - std::array dir_array_indexes{}; - - uint8_t dir_idx = 0; - for (const auto& [str, curdir] : wall_atlas::directions) - { - if (!jroot.contains(std::string_view{str.data(), str.size()})) - continue; - auto i = (size_t)curdir; - fm_debug_assert(dir_idx < direction_count); - dir_array_indexes[i] = { .val = dir_idx }; - directions[dir_idx++] = read_direction_metadata(jroot, curdir); - } - fm_debug_assert(dir_idx == direction_count); - - auto atlas = std::make_shared(); + auto atlas = std::make_shared(std::move(def), path, tex); return atlas; } @@ -69,7 +42,7 @@ const wall_info& loader_impl::wall_atlas(StringView name, StringView dir) fm_assert(it->second != nullptr); if (!it->second->atlas) { - const_cast(it->second)->atlas = get_wall_atlas(path); + const_cast(it->second)->atlas = get_wall_atlas(it->second->name, path); } return *it->second; } -- cgit v1.2.3