summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-23 14:04:15 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-23 14:04:15 +0100
commit689c4bf27316c6271bb922d4f64436121cfe72bc (patch)
tree8286a6fa463c07d8a40e51a0e882a08ed4d24b28 /serialize
parent17f15d8b6137ba33a3cf275ba1bc7067c0f95dde (diff)
w
Diffstat (limited to 'serialize')
-rw-r--r--serialize/old-savegame.cpp2
-rw-r--r--serialize/savegame.cpp17
2 files changed, 16 insertions, 3 deletions
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<critter, false>(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<uint16_t, decltype(critter::offset_frac_)>);
+ 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;