summaryrefslogtreecommitdiffhomepage
path: root/src/chunk.inl
blob: 132657ab6b2182fd29c7f0e7e5b7ac530cb39855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include "chunk.hpp"
#include "scenery.hpp"

namespace floormat {

template<typename F>
requires requires(F fun) { fun(); }
void chunk::with_scenery_update(entity& s, F&& fun)
{
    static_assert(std::is_convertible_v<decltype(fun()), bool> || std::is_same_v<void, decltype(fun())>);

    // todo handle coord & offset fields

    auto ch = s.coord.chunk();
    entity_proto s0(s);
    bbox bb0; bool b0 = _bbox_for_scenery(s, bb0);

    bool modified = true;
    if constexpr(!std::is_same_v<void, std::decay_t<decltype(fun())>>)
        modified = fun();
    else
        fun();
    if (!modified)
        return;

    if (s.coord.chunk() != ch) // todo
        return;

    if (bbox bb; !is_passability_modified())
        if (bool b = _bbox_for_scenery(s, bb); b != b0 || bb != bb0)
            _replace_bbox(bb0, bb, b0, b);
    if (!is_scenery_modified() && !s.is_dynamic() && entity_proto(s) != s0)
        mark_scenery_modified(false);
}

} // namespace floormat