summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-06-08 02:27:41 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-06-08 02:27:41 +0200
commit6945fbda28d0111f846458f4c4d63beb14d02f8d (patch)
tree472084a7b1fd4f2eefb41f18d0ab913072c32d53
parent6cb94b6c8c0bcd8812605044bb56c4af2b6abe17 (diff)
wa
-rw-r--r--src/chunk-collision.cpp56
-rw-r--r--src/chunk.cpp31
-rw-r--r--src/chunk.hpp18
-rw-r--r--src/hole.cpp9
-rw-r--r--src/hole.hpp2
-rw-r--r--src/object.cpp12
-rw-r--r--src/object.hpp2
7 files changed, 76 insertions, 54 deletions
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index 3263d738..a393554e 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -65,7 +65,7 @@ bool add_holes_from_chunk(chunk::RTree& rtree, chunk& c, Vector2b chunk_offset)
return has_holes;
}
-#if 0
+#if 1
CORRADE_NEVER_INLINE
bool find_hole_in_bbox(CutResult<float>::rect& hole, chunk::RTree& rtree, Vector2 min, Vector2 max)
{
@@ -140,7 +140,7 @@ void chunk::ensure_passability() noexcept
_pass_modified = false;
_rtree->RemoveAll();
- //Debug{} << ".. reset passability";
+ //Debug{} << ".. reset passability" << _coord;
bool has_holes = false;
{
@@ -215,13 +215,22 @@ bool chunk::_bbox_for_scenery(const object& s, bbox& value) noexcept
return _bbox_for_scenery(s, s.coord.local(), s.offset, s.bbox_offset, s.bbox_size, value);
}
-void chunk::_remove_bbox_static_() { mark_passability_modified(); }
-void chunk::_add_bbox_static_() { mark_passability_modified(); }
+void chunk::_remove_bbox_static_(const std::shared_ptr<object>& e)
+{
+ mark_passability_modified();
+ e->maybe_mark_neighbor_chunks_modified();
+}
+
+void chunk::_add_bbox_static_(const std::shared_ptr<object>& e)
+{
+ mark_passability_modified();
+ e->maybe_mark_neighbor_chunks_modified();
+}
-void chunk::_remove_bbox_(const bbox& x, bool upd, bool is_dynamic)
+void chunk::_remove_bbox_(const std::shared_ptr<object>& e, const bbox& x, bool upd, bool is_dynamic)
{
if (!is_dynamic || upd)
- _remove_bbox_static(x);
+ _remove_bbox_static(e, x);
else
_remove_bbox_dynamic(x);
}
@@ -233,9 +242,9 @@ void chunk::_remove_bbox_dynamic(const bbox& x)
//Debug{} << "bbox <<< dynamic" << x.data.pass << x.data.data << x.start << x.end << _rtree->Count();
}
-void chunk::_remove_bbox_static([[maybe_unused]] const bbox& x)
+void chunk::_remove_bbox_static(const std::shared_ptr<object>& e, [[maybe_unused]] const bbox& x)
{
- _remove_bbox_static_();
+ _remove_bbox_static_(e);
//Debug{} << "bbox <<< static " << x.data.pass << x.data.data << x.start << x.end << _rtree->Count();
}
@@ -246,22 +255,22 @@ void chunk::_add_bbox_dynamic(const bbox& x)
//Debug{} << "bbox >>> dynamic" << x.data.pass << x.data.data << x.start << x.end << _rtree->Count();
}
-void chunk::_add_bbox_static([[maybe_unused]]const bbox& x)
+void chunk::_add_bbox_static(const std::shared_ptr<object>& e, [[maybe_unused]]const bbox& x)
{
- _add_bbox_static_();
+ _add_bbox_static_(e);
//Debug{} << "bbox >>> static " << x.data.pass << x.data.data << x.start << x.end << _rtree->Count();
}
-void chunk::_add_bbox_(const bbox& x, bool upd, bool is_dynamic)
+void chunk::_add_bbox_(const std::shared_ptr<object>& e, const bbox& x, bool upd, bool is_dynamic)
{
if (!is_dynamic || upd)
- _add_bbox_static(x);
+ _add_bbox_static(e, x);
else
_add_bbox_dynamic(x);
}
template<bool Dynamic>
-void chunk::_replace_bbox_impl(const bbox& x0, const bbox& x1, bool b0, bool b1)
+void chunk::_replace_bbox_impl(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x1, bool b0, bool b1)
{
if (_pass_modified)
return;
@@ -277,19 +286,19 @@ void chunk::_replace_bbox_impl(const bbox& x0, const bbox& x1, bool b0, bool b1)
if constexpr(Dynamic)
_remove_bbox_dynamic(x0);
else
- _remove_bbox_static(x0);
+ _remove_bbox_static(e, x0);
[[fallthrough]];
case 1 << 1 | 0 << 0:
if constexpr(Dynamic)
_add_bbox_dynamic(x1);
else
- _add_bbox_static(x1);
+ _add_bbox_static(e, x1);
return;
case 0 << 1 | 1 << 0:
if constexpr(Dynamic)
_remove_bbox_dynamic(x0);
else
- _remove_bbox_static(x0);
+ _remove_bbox_static(e, x0);
return;
case 0 << 1 | 0 << 0:
return;
@@ -299,13 +308,20 @@ void chunk::_replace_bbox_impl(const bbox& x0, const bbox& x1, bool b0, bool b1)
std::unreachable();
}
-void chunk::_replace_bbox_dynamic(const bbox& x0, const bbox& x, bool b0, bool b) { _replace_bbox_impl<true>(x0, x, b0, b); }
-void chunk::_replace_bbox_static(const bbox& x0, const bbox& x, bool b0, bool b) { _replace_bbox_impl<false>(x0, x, b0, b); }
+void chunk::_replace_bbox_dynamic(const bbox& x0, const bbox& x, bool b0, bool b)
+{
+ _replace_bbox_impl<true>(nullptr, x0, x, b0, b);
+}
+
+void chunk::_replace_bbox_static(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x, bool b0, bool b)
+{
+ _replace_bbox_impl<false>(e, x0, x, b0, b);
+}
-void chunk::_replace_bbox_(const bbox& x0, const bbox& x, bool b0, bool b, bool upd, bool is_dynamic)
+void chunk::_replace_bbox_(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x, bool b0, bool b, bool upd, bool is_dynamic)
{
if (!is_dynamic || upd)
- _replace_bbox_static(x0, x, b0, b);
+ _replace_bbox_static(e, x0, x, b0, b);
else
_replace_bbox_dynamic(x0, x, b0, b);
}
diff --git a/src/chunk.cpp b/src/chunk.cpp
index bf305fc5..2ecf668b 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -146,7 +146,7 @@ void chunk::add_object_pre(const std::shared_ptr<object>& e)
if (!_pass_modified) [[likely]]
{
if (!dyn || upd)
- _add_bbox_static_();
+ _add_bbox_static_(e);
else if (bbox bb; _bbox_for_scenery(*e, bb))
_add_bbox_dynamic(bb);
}
@@ -186,23 +186,22 @@ void chunk::remove_object(size_t i)
fm_assert(_objects_sorted);
fm_debug_assert(i < _objects.size());
+ const auto& eʹ = _objects[i];
+ auto& e = *eʹ;
+ fm_assert(e.c == this);
+ fm_assert(!e.gone);
+
+ const auto dyn = e.is_dynamic(), upd = e.updates_passability();
+ if (!dyn)
+ mark_scenery_modified();
+
+ if (!_pass_modified) [[likely]]
{
- const auto& e = *_objects[i];
- fm_assert(e.c == this);
- fm_assert(!e.gone);
-
- const auto dyn = e.is_dynamic(), upd = e.updates_passability();
- if (!dyn)
- mark_scenery_modified();
- if (!_pass_modified) [[likely]]
- {
- if (!dyn || upd)
- _remove_bbox_static_();
- else if (bbox bb; _bbox_for_scenery(e, bb))
- _remove_bbox_dynamic(bb);
- }
+ if (!dyn || upd)
+ _remove_bbox_static_(eʹ);
+ else if (bbox bb; _bbox_for_scenery(e, bb))
+ _remove_bbox_dynamic(bb);
}
-
arrayRemove(_objects, i);
}
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 94d1e3ca..e429f2de 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -164,20 +164,20 @@ private:
[[nodiscard]] static bool _bbox_for_scenery(const object& s, local_coords local, Vector2b offset,
Vector2b bbox_offset, Vector2ub bbox_size, bbox& value) noexcept;
- void _remove_bbox_(const bbox& x, bool upd, bool is_dynamic);
+ void _remove_bbox_(const std::shared_ptr<object>& e, const bbox& x, bool upd, bool is_dynamic);
void _remove_bbox_dynamic(const bbox& x);
- void _remove_bbox_static(const bbox& x);
- void _remove_bbox_static_();
+ void _remove_bbox_static(const std::shared_ptr<object>& e, const bbox& x);
+ void _remove_bbox_static_(const std::shared_ptr<object>& e);
- void _add_bbox_(const bbox& x, bool upd, bool is_dynamic);
+ void _add_bbox_(const std::shared_ptr<object>& e, const bbox& x, bool upd, bool is_dynamic);
void _add_bbox_dynamic(const bbox& x);
- void _add_bbox_static(const bbox& x);
- void _add_bbox_static_();
+ void _add_bbox_static(const std::shared_ptr<object>& e, const bbox& x);
+ void _add_bbox_static_(const std::shared_ptr<object>& e);
- template<bool Dynamic> void _replace_bbox_impl(const bbox& x0, const bbox& x, bool b0, bool b);
- void _replace_bbox_(const bbox& x0, const bbox& x, bool b0, bool b, bool upd, bool is_dynamic);
+ template<bool Dynamic> void _replace_bbox_impl(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x, bool b0, bool b);
+ void _replace_bbox_(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x, bool b0, bool b, bool upd, bool is_dynamic);
void _replace_bbox_dynamic(const bbox& x0, const bbox& x, bool b0, bool b);
- void _replace_bbox_static(const bbox& x0, const bbox& x, bool b0, bool b);
+ void _replace_bbox_static(const std::shared_ptr<object>& e, const bbox& x0, const bbox& x, bool b0, bool b);
GL::Mesh make_wall_mesh();
diff --git a/src/hole.cpp b/src/hole.cpp
index e9c6c14f..7a50566d 100644
--- a/src/hole.cpp
+++ b/src/hole.cpp
@@ -55,7 +55,6 @@ hole::~hole() noexcept
{
if (c->is_teardown()) [[unlikely]]
return;
- mark_chunk_modified();
}
void hole::update(const std::shared_ptr<object>&, size_t&, const Ns&) {}
@@ -69,7 +68,7 @@ hole::operator hole_proto() const
return ret;
}
-void hole::mark_chunk_modified()
+void hole::maybe_mark_neighbor_chunks_modified()
{
for (auto* const cʹ : c->world().neighbors(c->coord()))
if (cʹ)
@@ -94,7 +93,7 @@ void hole::set_height(uint8_t heightʹ)
if (height != heightʹ)
{
non_const(height) = heightʹ;
- mark_chunk_modified();
+ maybe_mark_neighbor_chunks_modified();
}
}
@@ -103,7 +102,7 @@ void hole::set_z_offset(uint8_t z)
if (z_offset != z)
{
non_const(z_offset) = z;
- mark_chunk_modified();
+ maybe_mark_neighbor_chunks_modified();
}
}
@@ -115,7 +114,7 @@ void hole::set_enabled(bool on_render, bool on_physics, bool on_both)
if (flags.on_physics != on_physics || on_both != flags.enabled)
{
non_const(flags).on_physics = on_physics;
- mark_chunk_modified();
+ maybe_mark_neighbor_chunks_modified();
}
non_const(flags).enabled = on_both;
diff --git a/src/hole.hpp b/src/hole.hpp
index 52895e0b..25db9886 100644
--- a/src/hole.hpp
+++ b/src/hole.hpp
@@ -54,7 +54,7 @@ struct hole final : object
friend class world;
private:
- void mark_chunk_modified();
+ void maybe_mark_neighbor_chunks_modified() override;
};
template<typename T>
diff --git a/src/object.cpp b/src/object.cpp
index 49f56227..200179e5 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -228,7 +228,7 @@ void object::teleport_to(size_t& i, global_coords coord_, Vector2b offset_, rota
if (coord_ == coord && offset_ == offset)
return;
- const bool dynamic = is_dynamic(), upd = updates_passability();
+ const bool dyn = is_dynamic(), upd = updates_passability();
chunk::bbox bb0, bb1;
const auto bb_offset = rotate_point(bbox_offset, r, new_r);
@@ -238,7 +238,7 @@ void object::teleport_to(size_t& i, global_coords coord_, Vector2b offset_, rota
if (coord_.chunk3() == coord.chunk3())
{
- c->_replace_bbox_(bb0, bb1, b0, b1, upd, dynamic);
+ c->_replace_bbox_(eʹ, bb0, bb1, b0, b1, upd, dyn);
non_const(coord) = coord_;
set_bbox_(offset_, bb_offset, bb_size, pass);
non_const(r) = new_r;
@@ -343,7 +343,12 @@ void object::set_bbox(Vector2b offset_, Vector2b bb_offset_, Vector2ub bb_size_,
const bool b0 = c->_bbox_for_scenery(*this, bb0);
set_bbox_(offset_, bb_offset_, bb_size_, pass);
const bool b = c->_bbox_for_scenery(*this, bb);
- c->_replace_bbox_(bb0, bb, b0, b, upd, dyn);
+ if (upd)
+ maybe_mark_neighbor_chunks_modified();
+ else if (!dyn)
+ c->mark_passability_modified();
+ else
+ c->_replace_bbox_dynamic(bb0, bb, b0, b);
}
bool object::can_activate(size_t) const { return false; }
@@ -356,6 +361,7 @@ object_type object::type_of() const noexcept { return type(); }
bool object::is_dynamic() const { return atlas->info().fps > 0; }
bool object::updates_passability() const { return false; }
+void object::maybe_mark_neighbor_chunks_modified() {}
void object::init_script(const std::shared_ptr<object>&) {}
void object::destroy_script_pre(const std::shared_ptr<object>&, script_destroy_reason) {}
diff --git a/src/object.hpp b/src/object.hpp
index 8d71645b..d65f6a67 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -89,6 +89,8 @@ struct object
virtual bool is_dynamic() const;
virtual bool updates_passability() const;
+ virtual void maybe_mark_neighbor_chunks_modified();
+
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
bool move_to(size_t& i, Vector2i delta, rotation new_r);