summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-04-05 23:19:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-04-06 15:22:00 +0200
commite532875c8e6d8fcad81c231a950adf93f8f114b6 (patch)
treee49362ec55bda8d8c95e1d74514b2026882440f4 /src
parentb925773d084d5fc050112999ae16050a6d36859d (diff)
critter script wip
Diffstat (limited to 'src')
-rw-r--r--src/critter-script-base.cpp10
-rw-r--r--src/critter-script.cpp7
-rw-r--r--src/critter-script.hpp40
-rw-r--r--src/critter-script.inl23
4 files changed, 80 insertions, 0 deletions
diff --git a/src/critter-script-base.cpp b/src/critter-script-base.cpp
new file mode 100644
index 00000000..4808e7b5
--- /dev/null
+++ b/src/critter-script-base.cpp
@@ -0,0 +1,10 @@
+#include "critter-script.inl"
+
+namespace floormat {
+
+template class script_wrapper<critter_script>;
+
+base_script::~base_script() noexcept = default;
+base_script::base_script() noexcept = default;
+
+} // namespace floormat
diff --git a/src/critter-script.cpp b/src/critter-script.cpp
new file mode 100644
index 00000000..e2355a64
--- /dev/null
+++ b/src/critter-script.cpp
@@ -0,0 +1,7 @@
+#include "critter-script.hpp"
+
+namespace floormat {
+
+
+
+} // namespace floormat
diff --git a/src/critter-script.hpp b/src/critter-script.hpp
new file mode 100644
index 00000000..9bd3d977
--- /dev/null
+++ b/src/critter-script.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+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;
+ // todo can_activate, activate
+};
+
+extern template class script_wrapper<critter_script>;
+
+} // namespace floormat
diff --git a/src/critter-script.inl b/src/critter-script.inl
new file mode 100644
index 00000000..db6b7000
--- /dev/null
+++ b/src/critter-script.inl
@@ -0,0 +1,23 @@
+#pragma once
+#include "critter-script.hpp"
+#include "compat/assert.hpp"
+
+namespace floormat {
+
+template <typename T> script_wrapper<T>::script_wrapper(T* ptr): ptr{ptr} { fm_assert(ptr); }
+
+template <typename T>
+script_wrapper<T>::~script_wrapper() noexcept
+{
+ ptr->delete_self();
+#ifndef FM_NO_DEBUG
+ ptr = nullptr;
+#endif
+}
+
+template <typename T> const T& script_wrapper<T>::operator*() const noexcept { return *ptr; }
+template <typename T> T& script_wrapper<T>::operator*() noexcept { return *ptr; }
+template <typename T> const T* script_wrapper<T>::operator->() const noexcept { return ptr; }
+template <typename T> T* script_wrapper<T>::operator->() noexcept { return ptr; }
+
+} // namespace floormat