summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-06 16:04:38 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-06 17:31:11 +0100
commit270a1ddbb91995c501fcd407045bf1fc4324ea15 (patch)
treeb0b92354bdf67a01b22e59ccdb1fedd6637006a1 /serialize
parent2d57d7a8baf9ef6912dba92b518ec2b9c040f26d (diff)
src/object: switch delta to 32-bit
Diffstat (limited to 'serialize')
-rw-r--r--serialize/old-savegame.cpp34
-rw-r--r--serialize/savegame.cpp12
2 files changed, 38 insertions, 8 deletions
diff --git a/serialize/old-savegame.cpp b/serialize/old-savegame.cpp
index bee5662d..8159419b 100644
--- a/serialize/old-savegame.cpp
+++ b/serialize/old-savegame.cpp
@@ -471,12 +471,18 @@ void reader_state::read_chunks(reader_t& s)
if (const auto* val = std::get_if<generic_scenery_proto>(&sc.subtype))
{
if (val->active)
- sc.delta << s;
+ {
+ uint16_t delta_; delta_ << s;
+ sc.delta = uint32_t(sc.delta) * 65536u;
+ }
}
else if (const auto* val = std::get_if<door_scenery_proto>(&sc.subtype))
{
if (val->active)
- sc.delta << s;
+ {
+ uint16_t delta_; delta_ << s;
+ sc.delta = uint32_t(sc.delta) * 65536u;
+ }
}
}
auto e = _world->make_object<scenery, false>(oid, {ch, local}, sc);
@@ -581,9 +587,17 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords_ ch, size_t i)
if (val->active)
{
if (PROTO >= 4) [[likely]]
- sc.delta << s;
+ {
+ uint16_t delta_;
+ delta_ << s;
+ sc.delta = uint32_t(delta_) * 65536u;
+ }
else
- sc.delta = (uint16_t)Math::clamp(int(s.read<float>() * 65535), 0, 65535);
+ {
+ auto x = (double)s.read<float>();
+ fm_soft_assert(x >= 0 && x <= 1);
+ sc.delta = (uint32_t)(x * (uint32_t)-1);
+ }
}
}
else if (auto* val = std::get_if<door_scenery_proto>(&sc.subtype))
@@ -591,9 +605,17 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords_ ch, size_t i)
if (val->active)
{
if (PROTO >= 4) [[likely]]
- sc.delta << s;
+ {
+ uint16_t delta_;
+ delta_ << s;
+ sc.delta = uint32_t(delta_) * 65536u;
+ }
else
- sc.delta = (uint16_t)Math::clamp(int(s.read<float>() * 65535), 0, 65535);
+ {
+ auto x = (double)s.read<float>();
+ fm_soft_assert(x >= 0 && x <= 1);
+ sc.delta = (uint32_t)(x * (uint32_t)-1);
+ }
}
}
}
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp
index 0fb3c4b1..6442ba6f 100644
--- a/serialize/savegame.cpp
+++ b/serialize/savegame.cpp
@@ -109,8 +109,9 @@ struct visitor_
// 20: complete rewrite
// 21: oops, forgot the object counter
// 22: add object::speed
+ // 23: switch object::delta to 32-bit
- static constexpr inline proto_t proto_version = 22;
+ static constexpr inline proto_t proto_version = 23;
const proto_t& PROTO;
visitor_(const proto_t& proto) : PROTO{proto} {}
@@ -176,7 +177,14 @@ struct visitor_
do_visit_nonconst(obj.offset, f);
do_visit_nonconst(obj.bbox_offset, f);
do_visit_nonconst(obj.bbox_size, f);
- do_visit_nonconst(obj.delta, f);
+ if (PROTO >= 23) [[likely]]
+ do_visit_nonconst(obj.delta, f);
+ else
+ {
+ auto delta_ = uint16_t(obj.delta >> 16);
+ do_visit(delta_, f);
+ obj.delta = delta_ * 65536u;
+ }
do_visit_nonconst(obj.frame, f);
do_visit_nonconst(obj.r, f);
do_visit_nonconst(obj.pass, f);