aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.cpp7
-rw-r--r--src/crepe/api/BehaviorScript.h13
-rw-r--r--src/crepe/api/GameObject.cpp6
-rw-r--r--src/crepe/api/GameObject.h13
-rw-r--r--src/crepe/api/Script.h3
5 files changed, 22 insertions, 20 deletions
diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp
index c5fecef..7bbace0 100644
--- a/src/crepe/api/BehaviorScript.cpp
+++ b/src/crepe/api/BehaviorScript.cpp
@@ -1,8 +1,15 @@
#include "BehaviorScript.h"
#include "Component.h"
+#include "GameObject.h"
using namespace crepe;
BehaviorScript::BehaviorScript(game_object_id_t id, ComponentManager & mgr)
: Component(id),
component_manager(mgr) {}
+
+template <>
+BehaviorScript & GameObject::add_component<BehaviorScript>() {
+ ComponentManager & mgr = this->component_manager;
+ return mgr.add_component<BehaviorScript>(this->id, mgr);
+}
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index f156081..a49fc96 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -3,6 +3,7 @@
#include <memory>
#include "../Component.h"
+#include "GameObject.h"
namespace crepe {
@@ -44,6 +45,18 @@ private:
friend class Script;
};
+/**
+ * \brief Add a BehaviorScript component to this game object
+ *
+ * The \c BehaviorScript class is the only exception to the ECS harmony, and
+ * requires a reference to the component manager passed to its constructor in
+ * order to function normally. This is because the \c BehaviorScript (and \c
+ * Script) classes are the only component-related classes that store
+ * implemented member functions as data.
+ */
+template <>
+BehaviorScript & GameObject::add_component<BehaviorScript>();
+
} // namespace crepe
#include "BehaviorScript.hpp"
diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp
index e05cea1..4f3c639 100644
--- a/src/crepe/api/GameObject.cpp
+++ b/src/crepe/api/GameObject.cpp
@@ -33,9 +33,3 @@ void GameObject::set_parent(const GameObject & parent) {
= mgr.get_components_by_id<Metadata>(parent.id);
parent_metadata.at(0).get().children.push_back(this->id);
}
-
-template <>
-BehaviorScript & GameObject::add_component<BehaviorScript>() {
- ComponentManager & mgr = this->component_manager;
- return mgr.add_component<BehaviorScript>(this->id, mgr);
-}
diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h
index e4a2539..73ff0b8 100644
--- a/src/crepe/api/GameObject.h
+++ b/src/crepe/api/GameObject.h
@@ -8,7 +8,6 @@
namespace crepe {
class ComponentManager;
-class BehaviorScript;
/**
* \brief Represents a GameObject
@@ -70,18 +69,6 @@ protected:
ComponentManager & component_manager;
};
-/**
- * \brief Add a BehaviorScript component to this game object
- *
- * The \c BehaviorScript class is the only exception to the ECS harmony, and
- * requires a reference to the component manager passed to its constructor in
- * order to function normally. This is because the \c BehaviorScript (and \c
- * Script) classes are the only component-related classes that store
- * implemented member functions as data.
- */
-template <>
-BehaviorScript & GameObject::add_component<BehaviorScript>();
-
} // namespace crepe
#include "GameObject.hpp"
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 837420f..051ea00 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -32,7 +32,7 @@ protected:
template <typename T>
std::vector<std::reference_wrapper<T>> get_components();
-private:
+protected:
// NOTE: Script must have a constructor without arguments so the game
// programmer doesn't need to manually add `using Script::Script` to their
// concrete script class.
@@ -40,6 +40,7 @@ private:
//! Only \c BehaviorScript instantiates Script
friend class BehaviorScript;
+private:
// These references are set by BehaviorScript immediately after calling the
// constructor of Script.
BehaviorScript * parent_ref = nullptr;