summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/imgui.cpp2
-rw-r--r--editor/inspect-types.cpp2
-rw-r--r--src/character.cpp2
-rw-r--r--src/entity.cpp22
-rw-r--r--src/entity.hpp13
5 files changed, 26 insertions, 15 deletions
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index d4bb7f65..fd8a5c72 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -155,7 +155,7 @@ void app::do_popup_menu()
inspectors.push_back(std::exchange(_popup_target, {}));
ImGui::SeparatorText("Modify");
if (auto next_rot = sc->atlas->next_rotation_from(sc->r);
- next_rot != sc->r && ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r))
+ ImGui::MenuItem("Rotate", nullptr, false, next_rot != sc->r && sc->can_rotate(next_rot)))
sc->rotate(i, next_rot);
if (ImGui::MenuItem("Delete", nullptr, false))
sc->chunk().remove_entity(sc->index());
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index f43bdc7a..2bca8a3c 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -63,7 +63,7 @@ struct entity_accessors<scenery> {
#ifdef TEST_STR
entity::type<String>::field{"string"_s,
[](const scenery&) { return my_str; },
- [](scenery&, String value) { my_str = std::move(value); },
+ [](scenery&, String value) { my_str = std::move_to(value); },
constantly(constraints::max_length{8}),
},
#endif
diff --git a/src/character.cpp b/src/character.cpp
index f63b35e9..31376925 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -125,7 +125,7 @@ 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(i, off_i, new_r);
+ i = move_to(i, off_i, new_r);
++frame %= atlas->info().nframes;
}
//Debug{} << "pos" << Vector2i(pos.local());
diff --git a/src/entity.cpp b/src/entity.cpp
index 8df9a9ce..20435f45 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -90,9 +90,17 @@ size_t entity::index() const
bool entity::can_rotate(global_coords coord, rotation new_r, rotation old_r, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size)
{
- bbox_offset = rotate_point(bbox_offset, old_r, new_r);
- bbox_size = rotate_size(bbox_size, old_r, new_r);
- return can_move_to({}, coord, offset, bbox_offset, bbox_size);
+ const auto bbox_offset_ = rotate_point(bbox_offset, old_r, new_r);
+ const auto bbox_size_ = rotate_size(bbox_size, old_r, new_r);
+ if (bbox_offset_.isZero() && bbox_size_[0] == bbox_size_[1] ||
+ bbox_offset_ == bbox_offset && bbox_size_ == bbox_size)
+ return true;
+ return can_move_to({}, coord, offset, bbox_offset_, bbox_size_);
+}
+
+bool entity::can_rotate(rotation new_r)
+{
+ return can_rotate(coord, new_r, r, offset, bbox_offset, bbox_size);
}
void entity::rotate(size_t, rotation new_r)
@@ -152,17 +160,17 @@ bool entity::can_move_to(Vector2i delta)
return can_move_to(delta, coord, offset, bbox_offset, bbox_size);
}
-size_t entity::move(size_t i, Vector2i delta, rotation new_r)
+size_t entity::move_to(size_t i, Vector2i delta, rotation new_r)
{
+ if (!can_rotate(coord, new_r, r, offset, bbox_offset, bbox_size))
+ return i;
+
auto& es = c->_entities;
fm_debug_assert(i < es.size());
auto e_ = es[i];
auto& w = *c->_world;
const auto [coord_, offset_] = normalize_coords(coord, offset, delta);
- if (!can_rotate(coord, new_r, r, offset, bbox_offset, bbox_size))
- return i;
-
if (coord_ == coord && offset_ == offset)
return i;
diff --git a/src/entity.hpp b/src/entity.hpp
index 3f82842d..490f0b7d 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -62,14 +62,17 @@ struct entity
virtual bool can_activate(size_t i) const;
virtual bool activate(size_t i);
virtual bool update(size_t i, float dt) = 0;
- [[nodiscard]] virtual bool can_rotate(global_coords coord, rotation r, rotation old_r, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size);
virtual void rotate(size_t i, rotation r);
+ virtual bool can_rotate(global_coords coord, rotation new_r, rotation old_r, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size);
+ virtual bool can_move_to(Vector2i delta, global_coords coord, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_aize);
+ virtual void set_bbox(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass);
static Pair<global_coords, Vector2b> normalize_coords(global_coords coord, Vector2b cur_offset, Vector2i delta);
- [[nodiscard]] virtual bool can_move_to(Vector2i delta);
- [[nodiscard]] bool can_move_to(Vector2i delta, global_coords coord, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_aize);
- size_t move(size_t i, Vector2i delta, rotation new_r);
- virtual void set_bbox(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass);
+
+ 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 is_dynamic() const;
friend struct world;