From b7f3cff0904214f7161fed16bb5162b26260d386 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 27 Feb 2024 21:04:41 +0100 Subject: add speed field to object (yet unused) --- serialize/savegame.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'serialize/savegame.cpp') diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index c737db57..ba126746 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -108,8 +108,11 @@ struct visitor_ // 19: see old-savegame.cpp // 20: complete rewrite // 21: oops, forgot the object counter + // 22: add object::speed - static constexpr inline proto_t proto_version = 21; + static constexpr inline proto_t proto_version = 22; + const proto_t& PROTO; + visitor_(const proto_t& proto) : PROTO{proto} {} template CORRADE_ALWAYS_INLINE void do_visit_nonconst(const T& value, F&& fun) @@ -166,9 +169,12 @@ struct visitor_ fm_throw("invalid object type {}"_cf, (int)type); //do_visit(*obj.c, f); - auto pt = obj.coord.local(); - do_visit(pt, f); - non_const(obj.coord) = {ch, pt}; + { auto pt = obj.coord.local(); + do_visit(pt, f); + non_const(obj.coord) = {ch, pt}; + } + if (PROTO >= 22) [[likely]] + do_visit(obj.speed, f); do_visit_nonconst(obj.offset, f); do_visit_nonconst(obj.bbox_offset, f); do_visit_nonconst(obj.bbox_size, f); @@ -338,6 +344,8 @@ constexpr size_t vector_initial_size = 128, hash_initial_size = vector_initial_s struct writer final : visitor_ { + static const proto_t fake_proto; + const world& w; struct serialized_atlas @@ -363,7 +371,10 @@ struct writer final : visitor_ buffer header_buf{}, string_buf{}; - writer(const world& w) : w{w} {} // avoid spurious warning until GCC 14: warning: missing initializer for member :: + writer(const world& w) : + visitor_{ fake_proto }, + w{ w } + {} struct size_counter { @@ -663,6 +674,8 @@ void my_fwrite(FILE_raii& f, const buffer& buf, char(&errbuf)[128]) fm_abort("fwrite: %s", get_error_string(errbuf, error).data()); } +const visitor_::proto_t writer::fake_proto = proto_version; + } // namespace void world::serialize(StringView filename) @@ -738,7 +751,7 @@ struct reader final : visitor_ class world& w; loader_policy asset_policy; - reader(class world& w, loader_policy asset_policy) : w{w}, asset_policy{asset_policy} {} + reader(class world& w, loader_policy asset_policy) : visitor_{PROTO}, w{w}, asset_policy{asset_policy} {} using visitor_::visit; -- cgit v1.2.3