summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-05 11:12:33 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-05 12:42:49 +0200
commit77252b17c70cc986159360bf8a1913c816b53f80 (patch)
treea5f2a18b91d27d891ef645904f96d12bff7fb538
parent1e7acf4ec72647a48adad961ae41a7446418b908 (diff)
src/critter: clean up before implementing pathfinding
-rw-r--r--serialize/world-impl.hpp3
-rw-r--r--serialize/world-reader.cpp4
-rw-r--r--src/critter.cpp13
-rw-r--r--src/critter.hpp2
4 files changed, 13 insertions, 9 deletions
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index f01276be..df0657ce 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -29,6 +29,7 @@
* 14) Always store object offset, rework how sc_exact works.
* 15) Add light alpha.
* 16) One more bit for light falloff enum.
+ * 17) Switch critter::offset_frac to unsigned.
*/
namespace floormat {
@@ -49,7 +50,7 @@ template<typename T> constexpr inline T int_max = std::numeric_limits<T>::max();
#define file_magic ".floormat.save"
-constexpr inline proto_t proto_version = 16;
+constexpr inline proto_t proto_version = 17;
constexpr inline size_t atlas_name_max = 128;
constexpr inline auto null_atlas = (atlasid)-1LL;
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 53b675ea..b912b5d7 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -268,9 +268,11 @@ void reader_state::read_chunks(reader_t& s)
proto.frame = s.read<uint8_t>();
else
proto.frame << s;
- Vector2s offset_frac;
+ Vector2us offset_frac;
offset_frac[0] << s;
offset_frac[1] << s;
+ if (PROTO < 17) [[unlikely]]
+ offset_frac = {};
const bool exact = id & meta_short_scenery_bit;
SET_CHUNK_SIZE();
diff --git a/src/critter.cpp b/src/critter.cpp
index 6f324077..ddb98cb1 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -151,8 +151,9 @@ Vector2 critter::ordinal_offset(Vector2b offset) const
void critter::update(size_t i, float dt)
{
const auto new_r = arrows_to_dir(b_L, b_R, b_U, b_D);
- if (new_r == rotation{rotation_COUNT})
+ if (new_r == rotation_COUNT)
{
+ offset_frac = {};
delta = 0;
return;
}
@@ -169,7 +170,6 @@ void critter::update(size_t i, float dt)
move_vec(rotation_to_vec(_2)),
};
-
if (r != new_r)
if (is_dynamic())
rotate(i, new_r);
@@ -181,10 +181,11 @@ void critter::update(size_t i, float dt)
for (auto j = 0uz; j < 3; j++)
{
auto vec = move_vecs[j];
- constexpr auto frac = Vector2(32767);
- constexpr auto inv_frac = 1.f / frac;
- auto offset_ = vec + Vector2(offset_frac) * inv_frac;
- offset_frac = Vector2s(Vector2(std::fmod(offset_[0], 1.f), std::fmod(offset_[1], 1.f)) * frac);
+ constexpr auto frac = 65535u;
+ constexpr auto inv_frac = 1.f / (float)frac;
+ const auto sign_vec = Vector2(sgn(vec[0]), sgn(vec[1]));
+ auto offset_ = vec + Vector2(offset_frac) * sign_vec * inv_frac;
+ offset_frac = Vector2us(Vector2(std::fabs(std::fmod(offset_[0], 1.f)), std::fabs(std::fmod(offset_[1], 1.f))) * frac);
auto off_i = Vector2i(offset_);
if (!off_i.isZero())
if (can_move_to(off_i))
diff --git a/src/critter.hpp b/src/critter.hpp
index 34ff9b33..3d7375b0 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -32,7 +32,7 @@ struct critter final : object
float depth_offset() const override;
String name;
- Vector2s offset_frac;
+ Vector2us offset_frac;
bool b_L : 1 = false, b_R : 1 = false, b_U : 1 = false, b_D : 1 = false;
bool playable : 1 = false;