From f677d0d5ac2376f6cb60a6125be53b06f338a3d2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 27 Oct 2022 17:17:35 +0200 Subject: cleanup some serialization stuff --- serialize/tile-atlas.cpp | 1 - serialize/tile.cpp | 19 +++++++++++++++++-- serialize/tile.hpp | 16 ++++++++++++++-- serialize/world.cpp | 36 ------------------------------------ serialize/world.hpp | 28 ---------------------------- 5 files changed, 31 insertions(+), 69 deletions(-) delete mode 100644 serialize/world.cpp delete mode 100644 serialize/world.hpp (limited to 'serialize') 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 #include 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 @@ -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::from_json(const json& j, tile_image& val) { usi void adl_serializer::to_json(json& j, const local_coords& val) { using nlohmann::to_json; to_json(j, val); } void adl_serializer::from_json(const json& j, local_coords& val) { using nlohmann::from_json; from_json(j, val); } +void adl_serializer::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); } +void adl_serializer::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); } + +void adl_serializer::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); } +void adl_serializer::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 { static void from_json(const json& j, floormat::local_coords& val); }; +template<> +struct adl_serializer { + 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 { + 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 - -#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::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); } -void adl_serializer::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); } - -void adl_serializer::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); } -void adl_serializer::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 - -namespace floormat { - -struct chunk_coords; -struct global_coords; -struct chunk; -struct world; - -} // namespace floormat - -namespace nlohmann { - -template<> -struct adl_serializer { - 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 { - static void to_json(json& j, const floormat::global_coords& val); - static void from_json(const json& j, floormat::global_coords& val); -}; - -} // namespace nlohmann - -- cgit v1.2.3