diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-27 17:17:35 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-27 17:17:35 +0200 |
| commit | f677d0d5ac2376f6cb60a6125be53b06f338a3d2 (patch) | |
| tree | 2c9a6fbeeb53946f5db2ada6b195035ee38639d9 | |
| parent | edb014053ebd3256b3bce16d8d5ac6479d905a2e (diff) | |
cleanup some serialization stuff
| -rw-r--r-- | anim-crop-tool/main.cpp | 5 | ||||
| -rw-r--r-- | compat/prelude.hpp | 1 | ||||
| -rw-r--r-- | editor/json.cpp | 3 | ||||
| -rw-r--r-- | serialize/tile-atlas.cpp | 1 | ||||
| -rw-r--r-- | serialize/tile.cpp | 19 | ||||
| -rw-r--r-- | serialize/tile.hpp | 16 | ||||
| -rw-r--r-- | serialize/world.cpp | 36 | ||||
| -rw-r--r-- | serialize/world.hpp | 28 | ||||
| -rw-r--r-- | src/precomp.hpp | 4 | ||||
| -rw-r--r-- | src/tile.hpp | 3 |
10 files changed, 38 insertions, 78 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 353a6be1..e77821f5 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -1,5 +1,6 @@ #include "atlas.hpp" #include "serialize/anim.hpp" +#include "serialize/magnum-vector2i.hpp" #include "serialize/json-helper.hpp" #include "compat/defs.hpp" #include "compat/sysexits.hpp" @@ -244,7 +245,7 @@ int main(int argc, char** argv) if (!opts_ok) return usage(args); - auto anim_info = json_helper::from_json<anim>(opts.input_file); + auto anim_info = floormat::json_helper::from_json<anim>(opts.input_file); if (!check_atlas_name(anim_info.object_name)) { @@ -290,7 +291,7 @@ int main(int argc, char** argv) << std::strerror(errno); // NOLINT(concurrency-mt-unsafe) return EX_CANTCREAT; } - json_helper::to_json<anim>(anim_info, opts.output_dir/(base_name + ".json")); + floormat::json_helper::to_json<anim>(anim_info, opts.output_dir/(base_name + ".json")); return 0; } diff --git a/compat/prelude.hpp b/compat/prelude.hpp index c21f9d27..f953a2b3 100644 --- a/compat/prelude.hpp +++ b/compat/prelude.hpp @@ -1,5 +1,4 @@ #pragma once -#include "integer-types.hpp" namespace Corrade::Containers {} namespace Magnum {} diff --git a/editor/json.cpp b/editor/json.cpp index f3317d5e..40c26952 100644 --- a/editor/json.cpp +++ b/editor/json.cpp @@ -1,9 +1,6 @@ #include "app.hpp" #include "floormat/main.hpp" #include "src/world.hpp" -#include "serialize/json-helper.hpp" -#include "serialize/tile-atlas.hpp" -#include "serialize/world.hpp" #include <Corrade/Utility/Path.h> namespace floormat { diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index fcbb371d..874a7054 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -2,7 +2,6 @@ #include "serialize/tile-atlas.hpp" #include "serialize/magnum-vector2i.hpp" #include "loader.hpp" -#include "compat/assert.hpp" #include <tuple> #include <nlohmann/json.hpp> diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 629ce52d..8da51af9 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -1,6 +1,6 @@ -#include "src/tile.hpp" -#include "src/chunk.hpp" #include "serialize/tile.hpp" +#include "src/tile.hpp" +#include "src/global-coords.hpp" #include "serialize/tile-atlas.hpp" #include <nlohmann/json.hpp> @@ -9,6 +9,14 @@ namespace floormat { NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile_image, atlas, variant) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile, ground_image, wall_north, wall_west, passability) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords, x, y) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y) + +struct global_coords_ final { + chunk_coords chunk; + local_coords local; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(global_coords_, chunk, local) } // namespace floormat @@ -22,5 +30,12 @@ void adl_serializer<tile_image>::from_json(const json& j, tile_image& val) { usi void adl_serializer<local_coords>::to_json(json& j, const local_coords& val) { using nlohmann::to_json; to_json(j, val); } void adl_serializer<local_coords>::from_json(const json& j, local_coords& val) { using nlohmann::from_json; from_json(j, val); } +void adl_serializer<chunk_coords>::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); } +void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); } + +void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); } +void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; global_coords_ x; from_json(j, x); val = {x.chunk, x.local}; } + + } // namespace nlohmann diff --git a/serialize/tile.hpp b/serialize/tile.hpp index 01673b2b..1d629fe6 100644 --- a/serialize/tile.hpp +++ b/serialize/tile.hpp @@ -4,9 +4,9 @@ namespace floormat { struct tile_image; -struct tile; -struct chunk; struct local_coords; +struct chunk_coords; +struct global_coords; } // namespace floormat @@ -24,4 +24,16 @@ struct adl_serializer<floormat::local_coords> { static void from_json(const json& j, floormat::local_coords& val); }; +template<> +struct adl_serializer<floormat::chunk_coords> { + static void to_json(json& j, const floormat::chunk_coords& val); + static void from_json(const json& j, floormat::chunk_coords& val); +}; + +template<> +struct adl_serializer<floormat::global_coords> { + static void to_json(json& j, const floormat::global_coords& val); + static void from_json(const json& j, floormat::global_coords& val); +}; + } // namespace nlohmann diff --git a/serialize/world.cpp b/serialize/world.cpp deleted file mode 100644 index cd6ebd6b..00000000 --- a/serialize/world.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "world.hpp" -#include "src/global-coords.hpp" -#include "serialize/tile.hpp" -#include <nlohmann/json.hpp> - -#if defined _MSC_VER -#pragma warning(disable : 4996) -#elif defined __GNUG__ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -namespace floormat { - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y) - -struct global_coords_ final { - chunk_coords chunk; - local_coords local; -}; - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(global_coords_, chunk, local) - -} // namespace floormat - -namespace nlohmann { - -using namespace floormat; - -void adl_serializer<chunk_coords>::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); } -void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); } - -void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); } -void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; global_coords_ x; from_json(j, x); val = {x.chunk, x.local}; } - -} // namespace nlohmann - diff --git a/serialize/world.hpp b/serialize/world.hpp deleted file mode 100644 index 39abaaca..00000000 --- a/serialize/world.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include <nlohmann/json_fwd.hpp> - -namespace floormat { - -struct chunk_coords; -struct global_coords; -struct chunk; -struct world; - -} // namespace floormat - -namespace nlohmann { - -template<> -struct adl_serializer<floormat::chunk_coords> { - static void to_json(json& j, const floormat::chunk_coords& val); - static void from_json(const json& j, floormat::chunk_coords& val); -}; - -template<> -struct adl_serializer<floormat::global_coords> { - static void to_json(json& j, const floormat::global_coords& val); - static void from_json(const json& j, floormat::global_coords& val); -}; - -} // namespace nlohmann - diff --git a/src/precomp.hpp b/src/precomp.hpp index 126643f3..de7a10e6 100644 --- a/src/precomp.hpp +++ b/src/precomp.hpp @@ -1,6 +1,8 @@ #pragma once -#include "compat/prelude.hpp" +#include "compat/integer-types.hpp" +#include "compat/defs.hpp" +#include "compat/assert.hpp" #include <cstddef> #include <cstdint> diff --git a/src/tile.hpp b/src/tile.hpp index 499acd97..c49b95b0 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -1,8 +1,7 @@ #pragma once #include "compat/defs.hpp" -#include "compat/assert.hpp" +#include "compat/integer-types.hpp" #include "tile-defs.hpp" -#include <cstdint> #include <memory> namespace floormat { |
