summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/saves/quicksave - Copy (60).datbin0 -> 8413 bytes
-rw-r--r--editor/tests/walk.cpp2
-rw-r--r--serialize/old-savegame.cpp2
-rw-r--r--serialize/savegame.cpp17
-rw-r--r--src/critter.cpp14
-rw-r--r--src/critter.hpp2
-rw-r--r--test/critter.cpp2
7 files changed, 28 insertions, 11 deletions
diff --git a/doc/saves/quicksave - Copy (60).dat b/doc/saves/quicksave - Copy (60).dat
new file mode 100644
index 00000000..90f51ec1
--- /dev/null
+++ b/doc/saves/quicksave - Copy (60).dat
Binary files differ
diff --git a/editor/tests/walk.cpp b/editor/tests/walk.cpp
index ea764a9e..dccd5dab 100644
--- a/editor/tests/walk.cpp
+++ b/editor/tests/walk.cpp
@@ -171,6 +171,7 @@ void pf_test::update_pre(app& a, const Ns& dt)
if (!current.has_value)
return;
+#if 0
auto& m = a.main();
auto& C = *a.ensure_player_character(m.world()).ptr;
fm_assert(C.is_dynamic());
@@ -250,6 +251,7 @@ void pf_test::update_pre(app& a, const Ns& dt)
C.offset_frac = {};
current.has_value = false;
}
+#endif
}
} // namespace
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;
diff --git a/src/critter.cpp b/src/critter.cpp
index d1f3caa7..3602b530 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -153,7 +153,7 @@ void critter::update(size_t i, const Ns& dt)
const auto new_r = arrows_to_dir(movement.L, movement.R, movement.U, movement.D);
if (new_r == rotation_COUNT)
{
- offset_frac = {};
+ offset_frac_ = {};
delta = 0;
}
else
@@ -193,16 +193,17 @@ void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
for (unsigned j = 0; j < nvecs; j++)
{
const auto vec = rotation_to_vec(rotations[j]);
- using Frac = decltype(critter::offset_frac)::Type;
+ using Frac = decltype(critter::offset_frac_);
constexpr auto frac = (float{limits<Frac>::max}+1)/2;
constexpr auto inv_frac = 1 / frac;
const auto sign_vec = Math::sign(vec);
- const auto from_accum = Vector2(offset_frac) * sign_vec * inv_frac;
+ const auto from_accum = (offset_frac_*inv_frac) * sign_vec.normalized();
auto offset_ = vec + from_accum;
auto off_i = Vector2i(offset_);
if (!off_i.isZero())
{
- offset_frac = Math::Vector2<Frac>(Math::abs(Math::fmod(offset_, 1.f)) * frac);
+ auto rem = (offset_ - Vector2(off_i)).length();
+ offset_frac_ = Frac(rem * frac);
if (can_move_to(off_i))
{
can_move = true;
@@ -214,7 +215,8 @@ void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
else
{
can_move = true;
- offset_frac = Math::Vector2<Frac>(Math::min({2.f,2.f}, Math::abs(offset_)) * frac);
+ auto rem = offset_.length();
+ offset_frac_ = Frac(rem * frac);
break;
}
}
@@ -223,7 +225,7 @@ void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
if (!can_move) [[unlikely]]
{
delta = {};
- offset_frac = {};
+ offset_frac_ = {};
}
}
diff --git a/src/critter.hpp b/src/critter.hpp
index e51d37c2..f05c3352 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -39,7 +39,7 @@ struct critter final : object
String name;
float speed = 1;
- Vector2us offset_frac; // todo! switch to Vector2ui due to `allocate_frame_time'
+ uint16_t offset_frac_ = 0;
struct movement_s {
bool L : 1 = false,
diff --git a/test/critter.cpp b/test/critter.cpp
index f9df42fa..f7c04383 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -126,7 +126,7 @@ bool run(world& w, const function_view<Ns() const>& make_dt,
<< " dt:" << dt
<< " dist:" << point::distance_l2(pos, start)
<< " delta:" << npc.delta
- << " frac:" << npc.offset_frac;
+ << " frac:" << npc.offset_frac_;
};
auto fail = [b = grace.no_crash](const char* file, int line) {