aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Script.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 15:40:01 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 15:40:01 +0100
commit7ec392eda3345606f0de75a432954b221cee82ce (patch)
tree48689f986a3c4042ec6b7704dad053f25ef898bf /src/crepe/api/Script.h
parent202725f481e64c4d95e370102ab93d4f8cf4af93 (diff)
add doxygen + check const correctness
Diffstat (limited to 'src/crepe/api/Script.h')
-rw-r--r--src/crepe/api/Script.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index ed247ad..e6fbb5c 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -7,11 +7,30 @@ namespace crepe {
class ScriptSystem;
class BehaviorScript;
+/**
+ * \brief Script interface
+ *
+ * This class is used as a base class for user-defined scripts that can be
+ * added to game objects using the \c BehaviorScript component.
+ */
class Script {
friend class crepe::ScriptSystem;
protected:
+ /**
+ * \brief Script initialization function
+ *
+ * This function is called during the ScriptSystem::update() routine *before*
+ * Script::update() if it (a) has not yet been called and (b) the \c
+ * BehaviorScript component holding this script instance is active.
+ */
virtual void init() {}
+ /**
+ * \brief Script update function
+ *
+ * This function is called during the ScriptSystem::update() routine if the
+ * \c BehaviorScript component holding this script instance is active.
+ */
virtual void update() {}
// NOTE: additional *events* (like unity's OnDisable and OnEnable) should be
// implemented as member methods in derivative user script classes and
@@ -19,11 +38,28 @@ protected:
// added event.
protected:
+ /**
+ * \brief Get single component of type \c T on this game object (utility)
+ *
+ * \tparam T Type of component
+ *
+ * \returns Reference to component
+ *
+ * \throws nullptr if this game object does not have a component matching
+ * type \c T
+ */
template <typename T>
- T & get_component();
+ T & get_component() const;
+ /**
+ * \brief Get all components of type \c T on this game object (utility)
+ *
+ * \tparam T Type of component
+ *
+ * \returns List of component references
+ */
template <typename T>
- std::vector<std::reference_wrapper<T>> get_components();
+ std::vector<std::reference_wrapper<T>> get_components() const;
private:
friend class crepe::BehaviorScript;