summaryrefslogtreecommitdiffhomepage
path: root/src/critter-script.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/critter-script.hpp')
-rw-r--r--src/critter-script.hpp38
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