summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-21 12:38:27 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-21 12:53:07 +0100
commit0592e91d317ad7bd3224d169dc9b06f438732f30 (patch)
tree11c90d966da24f9ebd5ef4b39bc00092dc388274 /src
parentc49e460e3c20f7c31ea1068b7d6ac3987f3c4b3b (diff)
src/entity: simplify update() return value
Diffstat (limited to 'src')
-rw-r--r--src/character.cpp21
-rw-r--r--src/entity.cpp10
-rw-r--r--src/entity.hpp2
3 files changed, 18 insertions, 15 deletions
diff --git a/src/character.cpp b/src/character.cpp
index 08de4e99..93a3ab88 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -100,7 +100,8 @@ Vector2 character::depth_offset() const { return {}; }
Vector2 character::ordinal_offset(Vector2b offset) const
{
- return Vector2(offset);
+ (void)offset;
+ return {};
}
bool character::update(size_t i, float dt)
@@ -118,12 +119,13 @@ bool character::update(size_t i, float dt)
auto coord_ = coord;
if (nframes == 0)
- {
- if (r == new_r) [[unlikely]]
- return false;
- rotate(i, new_r);
- return coord.chunk() != coord_.chunk();
- }
+ return false;
+
+ bool ret = false;
+
+ if (r != new_r)
+ if (is_dynamic())
+ rotate(i, new_r);
const auto vec = move_vec(lr, ud);
c->ensure_passability();
@@ -136,12 +138,13 @@ bool character::update(size_t i, float dt)
offset_frac = Vector2s(Vector2(std::fmod(offset_[0], 1.f), std::fmod(offset_[1], 1.f)) * frac);
auto off_i = Vector2i(offset_);
if (can_move_to(off_i))
- i = move_to(i, off_i, new_r);
+ ret |= move_to(i, off_i, new_r);
else
break;
++frame %= atlas->info().nframes;
}
- return coord.chunk() != coord_.chunk();
+
+ return ret;
}
entity_type character::type() const noexcept { return entity_type::character; }
diff --git a/src/entity.cpp b/src/entity.cpp
index ff0f77a9..4ecd950e 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -153,10 +153,10 @@ bool entity::can_move_to(Vector2i delta)
return can_move_to(delta, coord, offset, bbox_offset, bbox_size);
}
-size_t entity::move_to(size_t i, Vector2i delta, rotation new_r)
+bool entity::move_to(size_t& i, Vector2i delta, rotation new_r)
{
if (!can_rotate(new_r))
- return i;
+ return false;
auto& es = c->_entities;
fm_debug_assert(i < es.size());
@@ -167,7 +167,7 @@ size_t entity::move_to(size_t i, Vector2i delta, rotation new_r)
const auto [coord_, offset_] = normalize_coords(coord, offset, delta);
if (coord_ == coord && offset_ == offset)
- return i;
+ return false;
if (!is_dynamic())
c->mark_scenery_modified();
@@ -186,7 +186,7 @@ size_t entity::move_to(size_t i, Vector2i delta, rotation new_r)
const_cast<rotation&>(r) = new_r;
//for (auto i = 0_uz; const auto& x : es) fm_debug("%zu %s %f", i++, x->atlas->name().data(), x->ordinal());
//fm_debug("insert (%hd;%hd|%hhd;%hhd) %td -> %zu | %f", coord_.chunk().x, coord_.chunk().y, coord_.local().x, coord_.local().y, pos1, es.size(), e.ordinal());
- return i;
+ return false;
}
else
{
@@ -204,7 +204,7 @@ size_t entity::move_to(size_t i, Vector2i delta, rotation new_r)
const_cast<rotation&>(r) = new_r;
const_cast<struct chunk*&>(c) = &c2;
es.insert(it, std::move(e_));
- return ret;
+ return true;
}
}
diff --git a/src/entity.hpp b/src/entity.hpp
index cb5eea3b..f696b43b 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -76,7 +76,7 @@ struct entity
bool is_dynamic() const;
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
- size_t move_to(size_t i, Vector2i delta, rotation new_r);
+ bool move_to(size_t& i, Vector2i delta, rotation new_r);
protected:
entity(object_id id, struct chunk& c, const entity_proto& proto);