aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/BehaviorScript.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-16 16:46:18 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-16 16:46:18 +0100
commitfc5dfd2873279d5003f8a02187a71b05a44892fa (patch)
treee36d40a1b26e9d4900b582c5f06c4d1dc2858d34 /src/crepe/api/BehaviorScript.h
parent572741fc845f430d225a4611a94aae7a2a544d12 (diff)
final touchups 2 for #26
Diffstat (limited to 'src/crepe/api/BehaviorScript.h')
-rw-r--r--src/crepe/api/BehaviorScript.h37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index f7d484a..9d85d4c 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -15,12 +15,21 @@ class Script;
/**
* \brief Script component
*
- * This class acts as a (component) wrapper around an instance of (a class
- * derivatived from) \c Script. \c BehaviorScript is the only ECS component
- * that stores member function implementations as data.
+ * This class acts as a (component) wrapper around an instance of (a class derivatived from) \c
+ * Script. \c BehaviorScript is the only ECS component that stores member function
+ * implementations as data.
*/
class BehaviorScript : public Component {
protected:
+ /**
+ * \param id Parent \c GameObject id
+ * \param component_manager Reference to component manager (passed through to \c Script
+ * instance)
+ *
+ * \note Calls to this constructor (should) always pass through \c GameObject::add_component,
+ * which has an exception for this specific component type. This was done so the user does
+ * not have to pass references used within \c Script to each \c BehaviorScript instance.
+ */
BehaviorScript(game_object_id_t id, ComponentManager & component_manager);
//! Only ComponentManager is allowed to instantiate BehaviorScript
friend class ComponentManager;
@@ -37,27 +46,23 @@ public:
BehaviorScript & set_script();
protected:
- //! ScriptSystem needs direct access to the script instance
- friend class ScriptSystem;
- //! Flag to indicate if script->init() has been called already
- bool initialized = false;
//! Script instance
std::unique_ptr<Script> script = nullptr;
- //! Reference to component manager
+ //! ScriptSystem needs direct access to the script instance
+ friend class ScriptSystem;
+
+protected:
+ //! Reference to component manager (passed to Script)
ComponentManager & component_manager;
- //! Script accesses the component manager directly via its parent
- // (BehaviorScript) reference
- 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.
+ * 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>();