diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-06 16:04:38 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-06 17:31:11 +0100 |
commit | 270a1ddbb91995c501fcd407045bf1fc4324ea15 (patch) | |
tree | b0b92354bdf67a01b22e59ccdb1fedd6637006a1 /serialize/old-savegame.cpp | |
parent | 2d57d7a8baf9ef6912dba92b518ec2b9c040f26d (diff) |
src/object: switch delta to 32-bit
Diffstat (limited to 'serialize/old-savegame.cpp')
-rw-r--r-- | serialize/old-savegame.cpp | 34 |
1 files changed, 28 insertions, 6 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); + } } } } |