diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-30 00:28:21 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-30 00:28:21 +0100 |
commit | 01a8ae2ddf4b52fb9a7d5d46e433c19a5efcfa8d (patch) | |
tree | 01adb13c9c97a34b814a965d64ed72fd48aad86e /serialize | |
parent | 1b5a4bb5084c79a79da50affc5d9c8cd94fd47d7 (diff) |
tile, serialize/save: limit tile atlas size to 0xff
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/world-impl.hpp | 2 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 4 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 11 |
3 files changed, 5 insertions, 12 deletions
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index 210b6836..af79b451 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -11,7 +11,6 @@ namespace floormat::Serialize { using tilemeta = std::uint8_t; -using varid = decltype(tile_image_proto::variant); using atlasid = std::uint16_t; using chunksiz = std::uint16_t; using proto_t = std::uint16_t; @@ -38,7 +37,6 @@ enum : tilemeta { meta_wall_n = 1 << (pass_bits + 1), meta_wall_w = 1 << (pass_bits + 2), meta_short_atlasid = 1 << (pass_bits + 3), - meta_short_variant = 1 << (pass_bits + 4), }; } // namespace floormat::Serialize diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 2ec62015..f792de1a 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -67,8 +67,8 @@ void reader_state::read_chunks(reader_t& s) tile_ref t = chunk[i]; using uchar = std::uint8_t; const auto make_atlas = [&]() -> tile_image_proto { - auto id = flags & meta_short_atlasid ? (atlasid)(s.read<uchar>()) : s.read<atlasid>(); - auto v = flags & meta_short_variant ? (varid) (s.read<uchar>()) : s.read<varid>(); + auto id = flags & meta_short_atlasid ? atlasid{s.read<uchar>()} : s.read<atlasid>(); + auto v = s.read<variant_t>(); auto atlas = lookup_atlas(id); fm_assert(v < atlas->num_tiles()); return { atlas, v }; diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index 747610c1..ed62fcf5 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -38,7 +38,7 @@ private: std::unordered_map<const void*, interned_atlas> tile_images; }; -constexpr auto tile_size = sizeof(tilemeta) + (sizeof(atlasid) + sizeof(varid)) * 3; +constexpr auto tile_size = sizeof(tilemeta) + (sizeof(atlasid) + sizeof(variant_t)) * 3; constexpr auto chunkbuf_size = sizeof(chunk_magic) + sizeof(chunk_coords) + tile_size * TILE_COUNT; @@ -107,14 +107,9 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) constexpr auto ashortp = [](atlasid id) { return id == null_atlas || id == (uchar)id; }; - constexpr auto vshortp = [](const tile_image_proto& img) { - return !img.atlas || img.variant == (uchar)img.variant; - }; if (flags != 0 && ashortp(img_g) && ashortp(img_n) && ashortp(img_w)) flags |= meta_short_atlasid; - if (flags != 0 && vshortp(ground) && vshortp(wall_north) && vshortp(wall_west)) - flags |= meta_short_variant; fm_debug_assert((x.pass_mode & pass_mask) == x.pass_mode); flags |= x.pass_mode; @@ -131,9 +126,9 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) check_atlas(wall_west); #endif - const auto write = [&](atlasid x, varid v) { + const auto write = [&](atlasid x, variant_t v) { flags & meta_short_atlasid ? s << (uchar) x : s << x; - flags & meta_short_variant ? s << (uchar) v : s << v; + s << v; }; if (img_g != null_atlas) |