summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--serialize/old-savegame.cpp34
-rw-r--r--serialize/savegame.cpp12
-rw-r--r--src/critter.cpp2
-rw-r--r--src/object.hpp5
-rw-r--r--test/save/quicksave - Copy (0039).datbin0 -> 8415 bytes
5 files changed, 42 insertions, 11 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);
diff --git a/src/critter.cpp b/src/critter.cpp
index abb80865..72c06133 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -157,7 +157,7 @@ void critter::update_movement(size_t i, Ns dt, rotation new_r)
fm_assert(is_dynamic());
const auto hz = atlas->info().fps;
- const auto nframes = alloc_frame_time<uint16_t>(dt, delta, hz, speed);
+ const auto nframes = alloc_frame_time<uint32_t>(dt, delta, hz, speed);
if (nframes == 0)
return;
diff --git a/src/object.hpp b/src/object.hpp
index b77b0f42..4ada39d4 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -21,7 +21,8 @@ struct object_proto
std::shared_ptr<anim_atlas> atlas;
Vector2b offset, bbox_offset;
Vector2ub bbox_size = Vector2ub(tile_size_xy);
- uint16_t delta = 0, frame = 0;
+ uint32_t delta = 0;
+ uint16_t frame = 0;
object_type type : 3 = object_type::none;
rotation r : rotation_BITS = rotation::N;
pass_mode pass : pass_mode_BITS = pass_mode::see_through; // todo move to struct scenery, add inherit bit
@@ -47,7 +48,7 @@ struct object
const global_coords coord;
const Vector2b offset, bbox_offset;
const Vector2ub bbox_size;
- uint16_t delta = 0; // todo! switch to Vector2ui due to `allocate_frame_time'
+ uint32_t delta = 0;
uint16_t frame = 0;
const rotation r = rotation::N; // todo remove bitfield?
const pass_mode pass = pass_mode::see_through;
diff --git a/test/save/quicksave - Copy (0039).dat b/test/save/quicksave - Copy (0039).dat
new file mode 100644
index 00000000..fa2f9e99
--- /dev/null
+++ b/test/save/quicksave - Copy (0039).dat
Binary files differ