From a917bb7c28b383c3c684bf75732188bfff0060bb Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 22 Nov 2022 15:06:39 +0100 Subject: fit local-coords in a single byte --- serialize/tile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'serialize/tile.cpp') diff --git a/serialize/tile.cpp b/serialize/tile.cpp index abce91e1..8b756772 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -11,7 +11,11 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile_image_proto, atlas, variant) inline void to_json(nlohmann::json& j, const tile_image_ref& val) { j = tile_image_proto(val); } inline void from_json(const nlohmann::json& j, tile_image_ref& val) { val = tile_image_proto(j); } -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords, x, y) +struct local_coords_ final { + std::uint8_t x, y; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y) struct global_coords_ final { @@ -30,8 +34,8 @@ namespace nlohmann { void adl_serializer::to_json(json& j, const tile_image_ref& 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_ref& val) { using nlohmann::from_json; if (j.is_null()) val = {}; else from_json(j, val); } -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 local_coords& val) { using nlohmann::to_json; to_json(j, local_coords_{val.x, val.y}); } +void adl_serializer::from_json(const json& j, local_coords& val) { using nlohmann::from_json; local_coords_ proxy{}; from_json(j, proxy); val = {proxy.x, proxy.y}; } 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); } @@ -41,4 +45,3 @@ void adl_serializer::from_json(const json& j, global_coords& val) } // namespace nlohmann - -- cgit v1.2.3