diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-09 23:46:45 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-10 01:08:23 +0100 |
commit | c7caf58e53975ad0f1d2da88708697c7b1bb5c32 (patch) | |
tree | 75ade1b77ccc52d48dc19da3853211a5675f4134 | |
parent | e9082d38bf47c4083ef3469eb5779a79735f77cf (diff) |
loader, serialize: clean up a bit
-rw-r--r-- | loader/ground-traits.cpp | 7 | ||||
-rw-r--r-- | loader/vobj.cpp | 1 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 1 | ||||
-rw-r--r-- | loader/wall-cell.cpp | 3 | ||||
-rw-r--r-- | loader/wall-cell.hpp | 2 | ||||
-rw-r--r-- | loader/wall-traits.cpp | 2 | ||||
-rw-r--r-- | loader/wall-traits.hpp | 1 | ||||
-rw-r--r-- | serialize/anim.cpp | 1 | ||||
-rw-r--r-- | serialize/ground-atlas.cpp | 1 | ||||
-rw-r--r-- | serialize/magnum-vector.cpp | 7 |
10 files changed, 14 insertions, 12 deletions
diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp index 0ec42f0e..e9a82b24 100644 --- a/loader/ground-traits.cpp +++ b/loader/ground-traits.cpp @@ -31,17 +31,18 @@ void ground_traits::ensure_atlases_loaded(Storage& st) fm_assert(st.name_map.empty()); st.cell_array = ground_cell::load_atlases_from_json().vec; + st.name_map.reserve(st.cell_array.size()); fm_assert(!st.cell_array.empty()); fm_assert(st.name_map.empty()); constexpr bool add_invalid = true; if constexpr(add_invalid) + { for (auto& x : st.cell_array) fm_soft_assert(x.name != loader.INVALID); - - if constexpr(true) // NOLINT(*-simplify-boolean-expr) - st.cell_array.push_back(make_invalid_atlas(st)); // add invalid atlas + st.cell_array.push_back(make_invalid_atlas(st)); + } st.name_map.reserve(st.cell_array.size()); diff --git a/loader/vobj.cpp b/loader/vobj.cpp index d437df69..010cc642 100644 --- a/loader/vobj.cpp +++ b/loader/vobj.cpp @@ -36,6 +36,7 @@ void adl_serializer<vobj>::to_json(json& j, const vobj& val) void adl_serializer<vobj>::from_json(const json& j, vobj& val) { + val = {}; val.name = j["name"]; if (j.contains("description")) val.descr = j["description"]; diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index b07c73f2..67e4fdf8 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -1,5 +1,4 @@ #include "loader/impl.hpp" -#include "compat/vector-wrapper.hpp" #include "src/wall-atlas.hpp" #include "loader/wall-cell.hpp" #include "loader/wall-traits.hpp" diff --git a/loader/wall-cell.cpp b/loader/wall-cell.cpp index 6003ad77..92034659 100644 --- a/loader/wall-cell.cpp +++ b/loader/wall-cell.cpp @@ -11,8 +11,7 @@ using nlohmann::json; [[maybe_unused]] static void from_json(const json& j, wall_cell& val) { - val = {}; - val.name = j["name"]; + val = { .atlas = {}, .name = j["name"], }; fm_soft_assert(loader.check_atlas_name(val.name)); } diff --git a/loader/wall-cell.hpp b/loader/wall-cell.hpp index 507a09c2..e8cd15d5 100644 --- a/loader/wall-cell.hpp +++ b/loader/wall-cell.hpp @@ -9,8 +9,8 @@ class wall_atlas; struct wall_cell { - String name; std::shared_ptr<wall_atlas> atlas; + String name; static vector_wrapper<const wall_cell> load_atlases_from_json(); }; diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp index 9fbe4286..8f1c2e23 100644 --- a/loader/wall-traits.cpp +++ b/loader/wall-traits.cpp @@ -59,7 +59,7 @@ auto wall_traits::make_invalid_atlas(Storage& st) -> const Cell& {{ {.val = 0}, {}, }}, {1u}, }, name, loader.make_error_texture(frame_size)); - st.invalid_atlas = Pointer<wall_cell>{InPlaceInit, wall_cell{ .name = name, .atlas = std::move(a) } }; + st.invalid_atlas = Pointer<wall_cell>{InPlaceInit, wall_cell{ .atlas = std::move(a), .name = name, } }; return *st.invalid_atlas; } diff --git a/loader/wall-traits.hpp b/loader/wall-traits.hpp index 50576e2c..72492d98 100644 --- a/loader/wall-traits.hpp +++ b/loader/wall-traits.hpp @@ -22,7 +22,6 @@ template<> struct atlas_loader_traits<wall_atlas> static const Cell& make_invalid_atlas(Storage& st); static std::shared_ptr<Atlas> make_atlas(StringView name, const Cell& c); - static const Cell& make_placeholder_cell() noexcept; }; } // namespace floormat::loader_detail diff --git a/serialize/anim.cpp b/serialize/anim.cpp index 4b5dee77..cd1f5e5c 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -152,6 +152,7 @@ void adl_serializer<anim_scale>::from_json(const json& j, anim_scale& val) { fm_soft_assert(j.is_array()); fm_soft_assert(j.size() == 2); + val = {}; StringView type = j[0]; if (type == "factor"_s) { diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp index 11ef40ef..6844019c 100644 --- a/serialize/ground-atlas.cpp +++ b/serialize/ground-atlas.cpp @@ -26,6 +26,7 @@ void adl_serializer<ground_def>::to_json(json& j, const ground_def& x) void adl_serializer<ground_def>::from_json(const json& j, ground_def& val) { using nlohmann::from_json; + val = {}; val.name = j["name"]; val.size = j["size"]; if (j.contains("pass-mode")) diff --git a/serialize/magnum-vector.cpp b/serialize/magnum-vector.cpp index 2a31877e..8e9bfaeb 100644 --- a/serialize/magnum-vector.cpp +++ b/serialize/magnum-vector.cpp @@ -1,6 +1,7 @@ #include "magnum-vector.hpp" #include "compat/format.hpp" #include "compat/exception.hpp" +#include "corrade-string.hpp" #include <Magnum/Math/Vector.h> #include <cstdio> #include <string> @@ -10,12 +11,12 @@ namespace floormat::Serialize { namespace { -[[noreturn]] void throw_failed_to_parse_vector2(const std::string& str) +[[noreturn]] void throw_failed_to_parse_vector2(StringView str) { fm_throw("failed to parse Vector2 '{}'"_cf, str); } -[[noreturn]] void throw_vector2_overflow(const std::string& str) +[[noreturn]] void throw_vector2_overflow(StringView str) { fm_throw("numeric overflow in Vector2 '{}'"_cf, str); } @@ -63,7 +64,7 @@ struct vec2_serializer static void from_json(const json& j, Vector<2, T>& val) { using namespace floormat; - std::string str = j; + StringView str = j; using type = std::conditional_t<std::is_signed_v<T>, intmax_t, uintmax_t>; constexpr auto format_string = std::is_signed_v<T> ? "%jd x %jd%n" : "%ju x %ju%n"; type x = 0, y = 0; |