summaryrefslogtreecommitdiffhomepage
path: root/serialize/tile.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-22 15:06:39 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-22 15:06:39 +0100
commita917bb7c28b383c3c684bf75732188bfff0060bb (patch)
tree4b59f92cab7126a2e1a3b00c05ada385004c3657 /serialize/tile.cpp
parent9bd0075cb57a0e08fff45a2b9967de287533aa44 (diff)
fit local-coords in a single byte
Diffstat (limited to 'serialize/tile.cpp')
-rw-r--r--serialize/tile.cpp11
1 files changed, 7 insertions, 4 deletions
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<tile_image_ref>::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<tile_image_ref>::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<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<local_coords>::to_json(json& j, const local_coords& val) { using nlohmann::to_json; to_json(j, local_coords_{val.x, val.y}); }
+void adl_serializer<local_coords>::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<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); }
@@ -41,4 +45,3 @@ void adl_serializer<global_coords>::from_json(const json& j, global_coords& val)
} // namespace nlohmann
-