diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-08 11:16:28 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-08 19:40:24 +0200 |
commit | 457cdf24489c20f0f9b9b9877bf9e875aa643f91 (patch) | |
tree | 5c01a4cbe3935784e30b3a2a2912e62aa00ef29a /src/critter-script.hpp | |
parent | b25edf465d08750fb5f93068cd8b8d5cd9d0dcec (diff) |
wip
Diffstat (limited to 'src/critter-script.hpp')
-rw-r--r-- | src/critter-script.hpp | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/critter-script.hpp b/src/critter-script.hpp index 676a8a73..75f8156d 100644 --- a/src/critter-script.hpp +++ b/src/critter-script.hpp @@ -1,40 +1,24 @@ #pragma once +#include "script.hpp" +#include <memory> namespace floormat { struct critter; struct Ns; -struct base_script -{ - virtual ~base_script() noexcept; - virtual void delete_self() = 0; - base_script() noexcept; -}; - -template<typename T> -class script_wrapper final -{ - static_assert(std::is_base_of_v<base_script, T>); - T* ptr; - -public: - explicit script_wrapper(T* ptr); - ~script_wrapper() noexcept; - - const T& operator*() const noexcept; - T& operator*() noexcept; - const T* operator->() const noexcept; - T* operator->() noexcept; -}; - struct critter_script : base_script { - critter_script(critter& c); - virtual void update(critter& c, size_t& i, const Ns& dt) = 0; + critter_script(const std::shared_ptr<critter>& c); + ~critter_script() noexcept override; + + virtual void on_init(const std::shared_ptr<critter>& c) = 0; + virtual void on_update(const std::shared_ptr<critter>& c, size_t& i, const Ns& dt) = 0; + virtual void on_destroy(const std::shared_ptr<critter>& c, script_destroy_reason reason) = 0; + virtual void delete_self() = 0; // todo can_activate, activate -}; -extern template class script_wrapper<critter_script>; + static critter_script* const empty_script; +}; } // namespace floormat |