From 3d7ae4c401d5bd6109a7fd25eb22e5bc77f0a4aa Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Mar 2023 19:40:11 +0100 Subject: src: rework scenery updates --- src/chunk.inl | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) (limited to 'src/chunk.inl') diff --git a/src/chunk.inl b/src/chunk.inl index bdb4f8ae..6b01510a 100644 --- a/src/chunk.inl +++ b/src/chunk.inl @@ -3,40 +3,29 @@ namespace floormat { -template void chunk::with_scenery_bbox_update(std::size_t i, F&& fun) +template +requires requires(F fun) { fun(); } +void chunk::with_scenery_update(std::size_t idx, F&& fun) { - static_assert(std::is_invocable_v); static_assert(std::is_convertible_v || std::is_same_v); - if (is_passability_modified()) - { - auto& s = scenery_at(i); - auto r0 = s.r; - bool modified = true; - if constexpr(!std::is_same_v>) - modified = fun(); - else - fun(); - if (r0 != s.r) - { - fm_debug_assert(modified); - mark_scenery_modified(); - } - } + + const auto& s = scenery_at(idx), s0 = s; + bbox bb0; bool b0 = _bbox_for_scenery(idx, bb0); + + bool modified = true; + if constexpr(!std::is_same_v>) + modified = fun(); else - { - bbox x0, x; - bool b0 = _bbox_for_scenery(i, x0); - if constexpr(std::is_same_v>) - { - fun(); - _replace_bbox(x0, x, b0, _bbox_for_scenery(i, x)); - } - else - { - if (fun()) - _replace_bbox(x0, x, b0, _bbox_for_scenery(i, x)); - } - } + fun(); + if (!modified) + return; + + if (bbox bb; !is_passability_modified()) + if (bool b = _bbox_for_scenery(idx, bb); + b != b0 || scenery::is_collision_modified(s0, s)) + _replace_bbox(bb0, bb, b0, b); + if (!is_scenery_modified() && scenery::is_mesh_modified(s0, s)) + mark_scenery_modified(false); } } // namespace floormat -- cgit v1.2.3