summaryrefslogtreecommitdiffhomepage
path: root/serialize/world-impl.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'serialize/world-impl.hpp')
-rw-r--r--serialize/world-impl.hpp51
1 files changed, 13 insertions, 38 deletions
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index 07b80514..18aec72a 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -1,15 +1,7 @@
-#ifndef FM_SERIALIZE_WORLD_IMPL
-#error "not meant to be included directly"
-#endif
-
#pragma once
-#include "src/tile.hpp"
-#include "src/pass-mode.hpp"
-#include "src/rotation.hpp"
-#include "src/object-type.hpp"
-#include <bit>
#include <cstdio>
#include <concepts>
+#include <Corrade/Containers/StringView.h>
/* protocol changelog:
* 1) Initial version.
@@ -30,6 +22,7 @@
* 15) Add light alpha.
* 16) One more bit for light falloff enum.
* 17) Switch critter::offset_frac to unsigned.
+ * 20) Just rewrite the whole thing.
*/
namespace floormat {
@@ -40,8 +33,8 @@ struct object_proto;
namespace floormat::Serialize {
using tilemeta = uint8_t;
-using atlasid = uint16_t;
-using chunksiz = uint16_t;
+using atlasid = uint32_t;
+using chunksiz = uint32_t;
using proto_t = uint16_t;
template<typename T> struct int_traits;
@@ -51,32 +44,14 @@ template<std::signed_integral T> struct int_traits<T> { static constexpr T max =
namespace {
-#define file_magic ".floormat.save"
-
-constexpr inline proto_t proto_version = 19;
-
-constexpr inline size_t atlas_name_max = 128;
-constexpr inline auto null_atlas = (atlasid)-1LL;
-
-constexpr inline size_t critter_name_max = 128;
-constexpr inline size_t string_max = 512;
-
-constexpr inline proto_t min_proto_version = 1;
-constexpr inline auto chunk_magic = (uint16_t)~0xc0d3;
-constexpr inline auto scenery_magic = (uint16_t)~0xb00b;
-
-constexpr inline auto pass_mask = (1 << pass_mode_BITS)-1;
-
-template<typename T, size_t N, size_t off>
-constexpr inline auto highbits = (T(1) << N)-1 << sizeof(T)*8-N-off;
-
-template<size_t N, std::unsigned_integral T = uint8_t>
-constexpr T lowbits = N == sizeof(T)*8 ? (T)-1 : T((T{1} << N)-T{1});
-
-constexpr inline uint8_t meta_short_scenery_bit = highbits<uint8_t, 1, 0>;
-constexpr inline uint8_t meta_rotation_bits = highbits<uint8_t, rotation_BITS, 1>;
-constexpr inline uint8_t scenery_id_flag_mask = meta_short_scenery_bit | meta_rotation_bits;
-constexpr inline uint8_t scenery_id_max = int_traits<uint8_t>::max & ~scenery_id_flag_mask;
+constexpr inline proto_t proto_version = 20;
+constexpr inline proto_t min_proto_version = 20;
+constexpr inline auto file_magic = ".floormat.save"_s;
+constexpr inline auto chunk_magic = (uint16_t)0xdead;
+constexpr inline auto object_magic = (uint16_t)0xb00b;
+constexpr inline auto atlas_magic = (uint16_t)0xbeef;
+constexpr inline auto string_max = 256uz;
+constexpr inline auto null_atlas = (atlasid)-1;
} // namespace
@@ -103,7 +78,7 @@ struct FILE_raii final {
FILE_raii(FILE* s) noexcept : s{s} {}
~FILE_raii() noexcept { close(); }
operator FILE*() noexcept { return s; }
- void close() noexcept { if (s) ::fclose(s); s = nullptr; }
+ void close() noexcept { if (s) std::fclose(s); s = nullptr; }
private:
FILE* s;
};