diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-03 19:40:11 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-03 20:34:02 +0100 |
| commit | 3d7ae4c401d5bd6109a7fd25eb22e5bc77f0a4aa (patch) | |
| tree | 7c673746944b85fbafae891ac69594326b15b517 /src/chunk.inl | |
| parent | 6d0a594e618f165eb2823bb31eb3cfe21ec1e7c5 (diff) | |
src: rework scenery updates
Diffstat (limited to 'src/chunk.inl')
| -rw-r--r-- | src/chunk.inl | 51 |
1 files changed, 20 insertions, 31 deletions
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<typename F> void chunk::with_scenery_bbox_update(std::size_t i, F&& fun) +template<typename F> +requires requires(F fun) { fun(); } +void chunk::with_scenery_update(std::size_t idx, F&& fun) { - static_assert(std::is_invocable_v<F>); static_assert(std::is_convertible_v<decltype(fun()), bool> || std::is_same_v<void, decltype(fun())>); - if (is_passability_modified()) - { - auto& s = scenery_at(i); - auto r0 = s.r; - bool modified = true; - if constexpr(!std::is_same_v<void, std::decay_t<decltype(fun())>>) - 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<void, std::decay_t<decltype(fun())>>) + modified = fun(); else - { - bbox x0, x; - bool b0 = _bbox_for_scenery(i, x0); - if constexpr(std::is_same_v<void, std::decay_t<decltype(fun())>>) - { - 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 |
