diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-06 04:37:52 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-06 04:37:52 +0200 |
commit | 9d2cd3743e7d0e66e36275ec38cadc232ac094ca (patch) | |
tree | 76919e9ce6ec7e6023cfe186a87d1f913e535145 | |
parent | f2e145831c9228de3f7aa2c02b35cbf597704300 (diff) |
should be good now
-rw-r--r-- | src/critter-script-empty.cpp | 44 | ||||
-rw-r--r-- | src/critter-script-walk.cpp | 10 | ||||
-rw-r--r-- | src/critter-script.cpp (renamed from src/critter-script-base.cpp) | 3 | ||||
-rw-r--r-- | src/critter-script.hpp | 2 | ||||
-rw-r--r-- | src/critter-script.inl | 1 | ||||
-rw-r--r-- | src/critter.cpp | 2 | ||||
-rw-r--r-- | src/script.hpp | 6 |
7 files changed, 27 insertions, 41 deletions
diff --git a/src/critter-script-empty.cpp b/src/critter-script-empty.cpp index da712941..73a714ca 100644 --- a/src/critter-script-empty.cpp +++ b/src/critter-script-empty.cpp @@ -5,21 +5,11 @@ 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 { - const void* type_id() const override; + StringView name() const override; + const void* id() const override; + 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; @@ -28,31 +18,21 @@ struct empty_critter_script final : critter_script constexpr StringView script_name = name_of<empty_critter_script>; -const void* empty_critter_script::type_id() const +StringView empty_critter_script::name() const { - return &script_name; + return "empty"_s; } -void empty_critter_script::on_init(const std::shared_ptr<critter>& p) -{ - DBG_nospace << "> script init critter:" << (void*)&*p << " id:" << p->id << (p->name ? " name:" : "") << p->name; - touch_ptr(p); -} -void empty_critter_script::on_update(const std::shared_ptr<critter>& p, size_t&, const Ns&) +const void* empty_critter_script::id() const { - //DBG_nospace << " script update critter:" << (void*)&*p << " id:" << p->id << (p->name ? " name:" : "") << p->name; - touch_ptr(p); -} -void empty_critter_script::on_destroy(const std::shared_ptr<critter>& p, script_destroy_reason r) -{ - DBG_nospace << " script destroy critter:" << (void*)&*p << " id:" << p->id << " reason:" << (int)r << (p->name ? " name:" : "") << p->name; - touch_ptr(p); -} -void empty_critter_script::delete_self() noexcept -{ - DBG_nospace << "< script delete critter"; + return &script_name; } +void empty_critter_script::on_init(const std::shared_ptr<critter>&) {} +void empty_critter_script::on_update(const std::shared_ptr<critter>&, size_t&, const Ns&) {} +void empty_critter_script::on_destroy(const std::shared_ptr<critter>&, script_destroy_reason) {} +void empty_critter_script::delete_self() noexcept { } + constinit empty_critter_script empty_script_ = {}; } // namespace diff --git a/src/critter-script-walk.cpp b/src/critter-script-walk.cpp index 564c3023..8799aed5 100644 --- a/src/critter-script-walk.cpp +++ b/src/critter-script-walk.cpp @@ -15,9 +15,7 @@ namespace { bool walk_line(point dest, const std::shared_ptr<critter>& c, size_t& i, const Ns& dt) { - Debug{} << "move from" << c->position() << "to" << dest; auto res = c->move_toward(i, dt, dest); - DBG_nospace << "blocked:" << res.blocked << " moved:" << res.moved; return res.blocked || c->position() == dest; } @@ -26,7 +24,8 @@ struct walk_script final : critter_script struct line_tag_t {}; struct path_tag_t {}; - const void* type_id() const override; + StringView name() const override; + const void* id() const override; 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; @@ -79,12 +78,15 @@ void walk_script::on_update(const std::shared_ptr<critter>& c, size_t& i, const done: Debug{} << " finished walking"; + m.AUTO = false; c->script.do_clear(c); } constexpr StringView script_name = name_of<walk_script>; -const void* walk_script::type_id() const +StringView walk_script::name() const { return "walk"_s; } + +const void* walk_script::id() const { return &script_name; } diff --git a/src/critter-script-base.cpp b/src/critter-script.cpp index a321d2cd..746a84dd 100644 --- a/src/critter-script-base.cpp +++ b/src/critter-script.cpp @@ -2,7 +2,6 @@ namespace floormat { - - +object_type critter_script::type() const { return object_type::critter; } } // namespace floormat diff --git a/src/critter-script.hpp b/src/critter-script.hpp index 630baa4b..a8258ea0 100644 --- a/src/critter-script.hpp +++ b/src/critter-script.hpp @@ -24,6 +24,8 @@ struct critter_script : base_script // todo! move to src/scripts dir + object_type type() const override; + enum class walk_mode : uint8_t { none, line, path, }; static Pointer<critter_script> make_walk_script(point to, const path_search_result& path, walk_mode mode); }; diff --git a/src/critter-script.inl b/src/critter-script.inl index a9ce6561..6b467099 100644 --- a/src/critter-script.inl +++ b/src/critter-script.inl @@ -6,5 +6,4 @@ namespace floormat { - } // namespace floormat diff --git a/src/critter.cpp b/src/critter.cpp index 98e5ae1c..4a4fa617 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -367,7 +367,7 @@ void critter::update(const std::shared_ptr<object>& ptrʹ, size_t& i, const Ns& fm_debug_assert(&*ptrʹ == this); check_script_update_1(script.state()); - //script->on_update(std::static_pointer_cast<critter>(ptrʹ), i, dt); + script->on_update(std::static_pointer_cast<critter>(ptrʹ), i, dt); #if 0 // for now, objects can't delete themselves if (check_script_update_2(script.state())) [[unlikely]] return; diff --git a/src/script.hpp b/src/script.hpp index 59b914cc..5461a208 100644 --- a/src/script.hpp +++ b/src/script.hpp @@ -1,6 +1,7 @@ #pragma once #include "script-enums.hpp" #include "compat/defs.hpp" +#include "src/object-type.hpp" #include <memory> namespace floormat @@ -12,9 +13,12 @@ struct base_script { fm_DECLARE_DELETED_COPY_MOVE_ASSIGNMENTS(base_script); + virtual StringView name() const = 0; + virtual const void* id() const = 0; + virtual object_type type() const = 0; + constexpr base_script() noexcept = default; virtual ~base_script() noexcept; - virtual const void* type_id() const = 0; static StringView state_name(script_lifecycle x); static void _assert_state(script_lifecycle old_state, script_lifecycle s, const char* file, int line); |