From 7867213a01fcabb1f05b1836c2ca59dc3bb2132f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 11 Jan 2024 13:54:53 +0100 Subject: rename tile_atlas -> ground_atlas --- serialize/ground-atlas.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ serialize/ground-atlas.hpp | 14 +++++++++++ serialize/tile-atlas.cpp | 58 ---------------------------------------------- serialize/tile-atlas.hpp | 14 ----------- serialize/tile.cpp | 4 ++-- serialize/world-reader.cpp | 8 +++---- serialize/world-writer.cpp | 2 +- 7 files changed, 79 insertions(+), 79 deletions(-) create mode 100644 serialize/ground-atlas.cpp create mode 100644 serialize/ground-atlas.hpp delete mode 100644 serialize/tile-atlas.cpp delete mode 100644 serialize/tile-atlas.hpp (limited to 'serialize') diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp new file mode 100644 index 00000000..76c8686e --- /dev/null +++ b/serialize/ground-atlas.cpp @@ -0,0 +1,58 @@ +#include "src/ground-atlas.hpp" +#include "serialize/ground-atlas.hpp" +#include "serialize/corrade-string.hpp" +#include "serialize/magnum-vector.hpp" +#include "loader/loader.hpp" +#include "serialize/pass-mode.hpp" +#include "compat/exception.hpp" +#include +#include +#include + +using namespace floormat; + +namespace { + +struct proxy { + StringView name; + Vector2ub size; + pass_mode passability; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) + +} // namespace + +namespace nlohmann { + +void adl_serializer>::to_json(json& j, const std::shared_ptr& x) +{ + using nlohmann::to_json; + if (!x) + j = nullptr; + else + to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); +} + +void adl_serializer>::from_json(const json& j, std::shared_ptr& val) +{ + if (j.is_null()) + val = nullptr; + else + { + using nlohmann::from_json; + proxy x; + from_json(j, x); + pass_mode p = ground_atlas::default_pass_mode; + if (j.contains("pass-mode")) + p = j["pass-mode"]; + val = loader.ground_atlas(x.name, x.size, p); + if (auto p2 = val->pass_mode(); p2 != p) + { + const auto name = val->name(); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); + } + } +} + +} // namespace nlohmann diff --git a/serialize/ground-atlas.hpp b/serialize/ground-atlas.hpp new file mode 100644 index 00000000..344e8714 --- /dev/null +++ b/serialize/ground-atlas.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "src/ground-atlas.hpp" +#include +#include + +namespace nlohmann { + +template<> +struct adl_serializer> final { + static void to_json(json& j, const std::shared_ptr& x); + static void from_json(const json& j, std::shared_ptr& x); +}; + +} // namespace nlohmann diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp deleted file mode 100644 index 88385339..00000000 --- a/serialize/tile-atlas.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "src/tile-atlas.hpp" -#include "serialize/tile-atlas.hpp" -#include "serialize/corrade-string.hpp" -#include "serialize/magnum-vector.hpp" -#include "loader/loader.hpp" -#include "serialize/pass-mode.hpp" -#include "compat/exception.hpp" -#include -#include -#include - -using namespace floormat; - -namespace { - -struct proxy { - StringView name; - Vector2ub size; - pass_mode passability; -}; - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) - -} // namespace - -namespace nlohmann { - -void adl_serializer>::to_json(json& j, const std::shared_ptr& x) -{ - using nlohmann::to_json; - if (!x) - j = nullptr; - else - to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); -} - -void adl_serializer>::from_json(const json& j, std::shared_ptr& val) -{ - if (j.is_null()) - val = nullptr; - else - { - using nlohmann::from_json; - proxy x; - from_json(j, x); - pass_mode p = tile_atlas::default_pass_mode; - if (j.contains("pass-mode")) - p = j["pass-mode"]; - val = loader.tile_atlas(x.name, x.size, p); - if (auto p2 = val->pass_mode(); p2 != p) - { - const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); - } - } -} - -} // namespace nlohmann diff --git a/serialize/tile-atlas.hpp b/serialize/tile-atlas.hpp deleted file mode 100644 index 0c65c55e..00000000 --- a/serialize/tile-atlas.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "src/tile-atlas.hpp" -#include -#include - -namespace nlohmann { - -template<> -struct adl_serializer> final { - static void to_json(json& j, const std::shared_ptr& x); - static void from_json(const json& j, std::shared_ptr& x); -}; - -} // namespace nlohmann diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 69cec8a2..cd9064a8 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -1,8 +1,8 @@ #include "serialize/tile.hpp" #include "src/tile.hpp" #include "src/global-coords.hpp" -#include "serialize/tile-atlas.hpp" -#include "src/tile-atlas.hpp" +#include "serialize/ground-atlas.hpp" +#include "src/ground-atlas.hpp" #include #include diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 05b880b8..5e66616b 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -7,7 +7,7 @@ #include "src/light.hpp" #include "loader/loader.hpp" #include "loader/scenery.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/anim-atlas.hpp" #include "src/chunk-scenery.hpp" #include "compat/strerror.hpp" @@ -215,9 +215,9 @@ void reader_state::read_chunks(reader_t& s) ? s.read() : uint8_t(s.read()); auto name = lookup_atlas(id); - if constexpr(std::is_same_v) + if constexpr(std::is_same_v) { - auto atlas = loader.tile_atlas(name); + auto atlas = loader.ground_atlas(name); fm_soft_assert(v < atlas->num_tiles()); return { atlas, v }; } @@ -232,7 +232,7 @@ void reader_state::read_chunks(reader_t& s) SET_CHUNK_SIZE(); //t.passability() = pass_mode(flags & pass_mask); if (flags & meta_ground) - t.ground() = make_atlas.operator()(); + t.ground() = make_atlas.operator()(); if (flags & meta_wall_n) t.wall_north() = make_atlas.operator()(); if (flags & meta_wall_w) diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index a89f039a..e32d3cdf 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -1,6 +1,6 @@ #define FM_SERIALIZE_WORLD_IMPL #include "world-impl.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/wall-atlas.hpp" #include "binary-writer.inl" #include "src/global-coords.hpp" -- cgit v1.2.3