From 689c4bf27316c6271bb922d4f64436121cfe72bc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 23 Mar 2024 14:04:15 +0100 Subject: w --- serialize/old-savegame.cpp | 2 +- serialize/savegame.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'serialize') diff --git a/serialize/old-savegame.cpp b/serialize/old-savegame.cpp index 8159419b..111d29f3 100644 --- a/serialize/old-savegame.cpp +++ b/serialize/old-savegame.cpp @@ -431,7 +431,7 @@ void reader_state::read_chunks(reader_t& s) } SET_CHUNK_SIZE(); auto e = _world->make_object(oid, {ch, local}, proto); - e->offset_frac = offset_frac; + e->offset_frac_ = (uint16_t)((Vector2(offset_frac)*(1.f/65355)).length()*32768); (void)e; break; } diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index 5c22b98a..8e7039e5 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -110,8 +110,9 @@ struct visitor_ // 21: oops, forgot the object counter // 22: add object::speed // 23: switch object::delta to 32-bit + // 24: switch object::offset_frac from Vector2us to uint16_t - static constexpr inline proto_t proto_version = 23; + static constexpr inline proto_t proto_version = 24; const proto_t& PROTO; visitor_(const proto_t& proto) : PROTO{proto} {} @@ -226,10 +227,22 @@ struct visitor_ void visit(critter& obj, F&& f) { do_visit(obj.name, f); + if (PROTO >= 22) [[likely]] do_visit(obj.speed, f); fm_soft_assert(obj.speed >= 0); - do_visit(obj.offset_frac, f); + + if (PROTO >= 24) [[likely]] + do_visit(obj.offset_frac_, f); + else + { + static_assert(std::is_same_v); + Vector2us foo1; + do_visit(foo1, f); + auto foo2 = Vector2(foo1)*(1.f/65535); + auto foo3 = foo2.length()*32768; + obj.offset_frac_ = uint16_t(foo3); + } constexpr struct { uint8_t bits; -- cgit v1.2.3