summaryrefslogtreecommitdiffhomepage
path: root/src/critter-script.cpp
blob: ede5c5d739b512e054bdbb4b7637f65f9300e392 (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
38
39
40
41
42
43
44
45
46
#include "critter-script.inl"
#include "compat/assert.hpp"

namespace floormat {

namespace {

CORRADE_ALWAYS_INLINE
void touch_ptr(const std::shared_ptr<critter>& p)
{
    (void)p;
#if fm_ASAN
    volatile char foo = *reinterpret_cast<volatile const char*>(&*p);
    (void)foo;
//#else
//    fm_debug_assert(p);
#endif
}

struct empty_critter_script final : critter_script
{
    empty_critter_script();
    void on_init(const std::shared_ptr<critter>& c) override;
    void on_update(const std::shared_ptr<critter>& c, size_t& i, const Ns& dt) override;
    void on_destroy(const std::shared_ptr<critter>& c, script_destroy_reason reason) override;
    void delete_self() noexcept override;
};

empty_critter_script::empty_critter_script() : critter_script{nullptr} {}
void empty_critter_script::on_init(const std::shared_ptr<critter>& p) { touch_ptr(p); }
void empty_critter_script::on_update(const std::shared_ptr<critter>& p, size_t&, const Ns&) { touch_ptr(p); }
void empty_critter_script::on_destroy(const std::shared_ptr<critter>& p, script_destroy_reason) { touch_ptr(p); }
void empty_critter_script::delete_self() noexcept {}

empty_critter_script empty_script_ = {};

} // namespace

critter_script* const critter_script::empty_script = &empty_script_;

critter_script::critter_script(const std::shared_ptr<critter>&) {}
critter_script::~critter_script() noexcept {}

template class Script<critter_script, critter>;

} // namespace floormat