aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorjaroWMR <jarorutjes07@gmail.com>2024-10-23 12:32:06 +0200
committerjaroWMR <jarorutjes07@gmail.com>2024-10-23 12:32:06 +0200
commit96da34c1f973525ee57b71ea031d11a966903150 (patch)
treef02d9e743ae852715397bd406b54f5de5fa5d29f /src/crepe/api
parentcead795b7ff7135e13caf9ad3b76628070391458 (diff)
parent30d84ef9ad4a0010288db18294766fd4d5ed6f4a (diff)
merged with master
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.cpp1
-rw-r--r--src/crepe/api/BehaviorScript.h30
-rw-r--r--src/crepe/api/BehaviorScript.hpp19
-rw-r--r--src/crepe/api/CMakeLists.txt2
-rw-r--r--src/crepe/api/Script.cpp3
-rw-r--r--src/crepe/api/Script.h21
6 files changed, 71 insertions, 5 deletions
diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp
index 74788ec..063d225 100644
--- a/src/crepe/api/BehaviorScript.cpp
+++ b/src/crepe/api/BehaviorScript.cpp
@@ -1,6 +1,7 @@
#include "../util/log.h"
#include "BehaviorScript.h"
+#include "Script.h"
using namespace crepe::api;
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index 1d05a75..6ce6798 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -1,16 +1,36 @@
#pragma once
-#include "../Component.h"
-#include "../Script.h"
+#include <memory>
+
+#include "Component.h"
+#include "Script.h"
+
+namespace crepe {
+class ScriptSystem;
+class ComponentManager;
+} // namespace crepe
namespace crepe::api {
-class BehaviorScript : public Script, public Component {
- // only allow ComponentManager to instantiate scripts
- friend class ComponentManager;
+class Script;
+class BehaviorScript : public Component {
protected:
+ friend class crepe::ComponentManager;
BehaviorScript();
+
+public:
+ virtual ~BehaviorScript() = default;
+
+public:
+ template <class T>
+ BehaviorScript & set_script();
+
+protected:
+ friend class crepe::ScriptSystem;
+ std::unique_ptr<Script> script = nullptr;
};
} // namespace crepe::api
+
+#include "BehaviorScript.hpp"
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
new file mode 100644
index 0000000..a6bd81c
--- /dev/null
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <type_traits>
+
+#include "../util/log.h"
+#include "BehaviorScript.h"
+
+namespace crepe::api {
+
+template <class T>
+BehaviorScript & BehaviorScript::set_script() {
+ static_assert(std::is_base_of<Script, T>::value);
+ dbg_trace();
+ Script * s = new T();
+ this->script = std::unique_ptr<Script>(s);
+ return *this;
+}
+
+} // namespace crepe::api
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 86623de..6b337be 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -1,10 +1,12 @@
target_sources(crepe PUBLIC
# AudioSource.cpp
BehaviorScript.cpp
+ Script.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
# AudioSource.h
BehaviorScript.h
+ Script.h
)
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
new file mode 100644
index 0000000..5016ed0
--- /dev/null
+++ b/src/crepe/api/Script.cpp
@@ -0,0 +1,3 @@
+#include "Script.h"
+
+using namespace crepe::api;
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
new file mode 100644
index 0000000..0036d1f
--- /dev/null
+++ b/src/crepe/api/Script.h
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace crepe {
+class ScriptSystem;
+}
+
+namespace crepe::api {
+
+class Script {
+ friend class crepe::ScriptSystem;
+
+protected:
+ virtual void init() {}
+ virtual void update() {}
+ // NOTE: additional *events* (like unity's OnDisable and OnEnable) should be
+ // implemented as member methods in derivative user script classes and
+ // registered in init(), otherwise this class will balloon in size with each
+ // added event.
+};
+
+} // namespace crepe::api