From edb014053ebd3256b3bce16d8d5ac6479d905a2e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 27 Oct 2022 14:42:14 +0200 Subject: kill serializing the world for now --- serialize/json-helper.cpp | 19 ------------------- serialize/json-helper.hpp | 12 ++---------- serialize/tile.cpp | 7 +------ serialize/tile.hpp | 12 ------------ serialize/world.cpp | 46 ++-------------------------------------------- serialize/world.hpp | 7 +------ 6 files changed, 6 insertions(+), 97 deletions(-) (limited to 'serialize') diff --git a/serialize/json-helper.cpp b/serialize/json-helper.cpp index 8738065f..dae3ad96 100644 --- a/serialize/json-helper.cpp +++ b/serialize/json-helper.cpp @@ -25,23 +25,4 @@ void json_helper::to_json_(const json& j, const fspath& pathname, int indent) (open_stream(pathname) << j.dump(indent, '\t') << '\n').flush(); } -#define FORMAT cbor - -#define JOIN2(prefix, fmt) prefix ## fmt -#define JOIN(prefix, fmt) JOIN2(prefix, fmt) -#define FROM JOIN(from_, FORMAT) -#define TO JOIN(to_, FORMAT) - -auto json_helper::from_binary_(const fspath& pathname) -> json -{ - return json::FROM(open_stream(pathname)); -} - -void json_helper::to_binary_(const json& j, const fspath& pathname) -{ - auto s = open_stream(pathname); - json::TO(j, s); - s.flush(); -} - } // namespace floormat diff --git a/serialize/json-helper.hpp b/serialize/json-helper.hpp index b6fe1da2..9c9d208d 100644 --- a/serialize/json-helper.hpp +++ b/serialize/json-helper.hpp @@ -10,20 +10,12 @@ struct json_helper final { using fspath = std::filesystem::path; template static T from_json(const fspath& pathname); - template static void to_json(const T& self, const fspath& pathname); + template static void to_json(const T& self, const fspath& pathname, int indent = 1); static json from_json_(const fspath& pathname); static void to_json_(const json& j, const fspath& pathname, int indent); - - template static T from_binary(const fspath& pathname); - template static void to_binary(const T& self, const fspath& pathname); - static json from_binary_(const fspath& pathname); - static void to_binary_(const json& j, const fspath& pathname); }; template T json_helper::from_json(const fspath& pathname) { return from_json_(pathname); } -template void json_helper::to_json(const T& self, const fspath& pathname) { to_json_(json(self), pathname, indent); } - -template T json_helper::from_binary(const fspath& pathname) { return from_binary_(pathname); } -template void json_helper::to_binary(const T& self, const fspath& pathname) { to_binary_(json(self), pathname); } +template void json_helper::to_json(const T& self, const fspath& pathname, int indent) { to_json_(json(self), pathname, indent); } } // namespace floormat diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 8a5374ab..629ce52d 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -19,13 +19,8 @@ namespace nlohmann { void adl_serializer::to_json(json& j, const tile_image& val) { using nlohmann::to_json; if (val.atlas) to_json(j, val); else j = nullptr; } void adl_serializer::from_json(const json& j, tile_image& val) { using nlohmann::from_json; if (j.is_null()) val = {}; else from_json(j, val); } -void adl_serializer::to_json(json& j, const tile& val) { using nlohmann::to_json; to_json(j, val); } -void adl_serializer::from_json(const json& j, tile& val) { using nlohmann::from_json; from_json(j, val); } - -void adl_serializer::to_json(json& j, const chunk& val) { using nlohmann::to_json; to_json(j, val.tiles()); } -void adl_serializer::from_json(const json& j, chunk& val) { using nlohmann::from_json; from_json(j, val.tiles()); } - 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); } } // namespace nlohmann + diff --git a/serialize/tile.hpp b/serialize/tile.hpp index 09c23f9a..01673b2b 100644 --- a/serialize/tile.hpp +++ b/serialize/tile.hpp @@ -18,18 +18,6 @@ struct adl_serializer { static void from_json(const json& j, floormat::tile_image& val); }; -template<> -struct adl_serializer { - static void to_json(json& j, const floormat::tile& val); - static void from_json(const json& j, floormat::tile& val); -}; - -template<> -struct adl_serializer { - static void to_json(json& j, const floormat::chunk& val); - static void from_json(const json& j, floormat::chunk& val); -}; - template<> struct adl_serializer { static void to_json(json& j, const floormat::local_coords& val); diff --git a/serialize/world.cpp b/serialize/world.cpp index 7bdf8ba6..cd6ebd6b 100644 --- a/serialize/world.cpp +++ b/serialize/world.cpp @@ -1,10 +1,6 @@ #include "world.hpp" -#include "serialize/tile.hpp" -#include "serialize/tile-atlas.hpp" #include "src/global-coords.hpp" -#include "src/chunk.hpp" -#include "src/world.hpp" -#include +#include "serialize/tile.hpp" #include #if defined _MSC_VER @@ -30,49 +26,11 @@ namespace nlohmann { using namespace floormat; -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); -}; - -void adl_serializer>::to_json(json& j, const std::shared_ptr& val) -{ - using nlohmann::to_json; - if (!val) - j = nullptr; - else - j = *val; -} - -void adl_serializer>::from_json(const json& j, std::shared_ptr& val) -{ - using nlohmann::from_json; - if (j.is_null()) - val = nullptr; - else - *(val = std::make_shared()) = j; -} - 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}; } -void adl_serializer::to_json(json& j, const world& val) -{ - using nlohmann::to_json; - to_json(j, val.chunks()); -} - -void adl_serializer::from_json(const json& j, world& val) -{ - using T = std::remove_cvref_t; - T x{}; - using nlohmann::from_json; - from_json(j, x); - val = world{std::move(x)}; -} - } // namespace nlohmann + diff --git a/serialize/world.hpp b/serialize/world.hpp index dd7f5078..39abaaca 100644 --- a/serialize/world.hpp +++ b/serialize/world.hpp @@ -24,10 +24,5 @@ struct adl_serializer { static void from_json(const json& j, floormat::global_coords& val); }; -template<> -struct adl_serializer { - static void to_json(json& j, const floormat::world& val); - static void from_json(const json& j, floormat::world& val); -}; - } // namespace nlohmann + -- cgit v1.2.3