summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--serialize/world-impl.hpp60
-rw-r--r--serialize/world-writer.cpp45
2 files changed, 36 insertions, 69 deletions
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index 18aec72a..7eb6c7c9 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -3,39 +3,12 @@
#include <concepts>
#include <Corrade/Containers/StringView.h>
-/* protocol changelog:
- * 1) Initial version.
- * 2) Tile atlas variant now always a uint8_t. Was uint16_t or uint8_t
- * depending on value of the tile flag (1 << 6) which is now removed.
- * 3) Serialize scenery. Tile flag (1 << 6) added.
- * 4) Scenery dt now stored as fixed-point uint16_t.
- * 5) Serialize scenery pixel offset.
- * 6) Serialize scenery bboxes.
- * 7) Serialize scenery bbox_size offset.
- * 8) Entity subtypes.
- * 9) Interned strings.
- * 10) Chunk Z level.
- * 11) RLE empty tiles.
- * 12) Don't write object name twice.
- * 13) Entity counter initialized to 1024.
- * 14) Always store object offset, rework how sc_exact works.
- * 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 {
-struct object;
-struct object_proto;
-} // namespace floormat
-
namespace floormat::Serialize {
using tilemeta = uint8_t;
using atlasid = uint32_t;
using chunksiz = uint32_t;
-using proto_t = uint16_t;
+using proto_t = uint32_t;
template<typename T> struct int_traits;
@@ -44,29 +17,9 @@ template<std::signed_integral T> struct int_traits<T> { static constexpr T max =
namespace {
-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
-template<typename T> concept object_subtype = std::is_base_of_v<object, T> || std::is_base_of_v<object_proto, T>;
-
-enum : tilemeta {
- meta_ground = 1 << 2,
- meta_wall_n = 1 << 3,
- meta_wall_w = 1 << 4,
- meta_rle = 1 << 7,
-
- meta_short_atlasid_ = 1 << 5,
- meta_short_variant_ = 1 << 6,
- meta_scenery_ = 1 << 7,
-};
+} // namespace
} // namespace floormat::Serialize
@@ -74,14 +27,7 @@ namespace floormat {
namespace {
-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) std::fclose(s); s = nullptr; }
-private:
- FILE* s;
-};
+
} // namespace
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp
index b6e5846b..213ae3e1 100644
--- a/serialize/world-writer.cpp
+++ b/serialize/world-writer.cpp
@@ -22,7 +22,7 @@
#include <Corrade/Utility/Path.h>
#include <tsl/robin_map.h>
-#if 1
+#if 0
#ifdef __CLION_IDE__
#undef fm_assert
#define fm_assert(...) (void)(__VA_ARGS__)
@@ -32,19 +32,38 @@
namespace floormat::Serialize {
namespace {
- struct string_container
+
+constexpr inline proto_t 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 null_atlas = (atlasid)-1;
+
+struct string_container
+{
+ StringView str;
+ bool operator==(const string_container&) const = default;
+
+ friend void swap(string_container& a, string_container& b)
{
- StringView str;
- bool operator==(const string_container&) const = default;
+ auto tmp = a.str;
+ a.str = b.str;
+ b.str = tmp;
+ }
+};
- friend void swap(string_container& a, string_container& b)
- {
- auto tmp = a.str;
- a.str = b.str;
- b.str = tmp;
- }
- };
-}
+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) std::fclose(s); s = nullptr; }
+private:
+ FILE* s;
+};
+
+} // namespace
} // namespace floormat::Serialize
@@ -89,7 +108,9 @@ struct buffer
data{std::make_unique<char[]>(len)},
size{len}
{
+#if !(defined __has_feature && __has_feature(address_sanitizer))
std::memset(&data[0], 0xfe, size);
+#endif
}
};