diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-13 15:40:01 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-13 15:40:01 +0100 |
commit | 7ec392eda3345606f0de75a432954b221cee82ce (patch) | |
tree | 48689f986a3c4042ec6b7704dad053f25ef898bf /src/crepe | |
parent | 202725f481e64c4d95e370102ab93d4f8cf4af93 (diff) |
add doxygen + check const correctness
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 8 | ||||
-rw-r--r-- | src/crepe/api/Config.h | 3 | ||||
-rw-r--r-- | src/crepe/api/Script.h | 40 | ||||
-rw-r--r-- | src/crepe/api/Script.hpp | 8 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 2 | ||||
-rw-r--r-- | src/crepe/facade/Sound.cpp | 9 | ||||
-rw-r--r-- | src/crepe/facade/Sound.h | 6 | ||||
-rw-r--r-- | src/crepe/facade/SoundContext.h | 11 | ||||
-rw-r--r-- | src/crepe/system/PhysicsSystem.h | 1 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.h | 19 | ||||
-rw-r--r-- | src/crepe/system/System.h | 10 |
11 files changed, 102 insertions, 15 deletions
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index c20842d..4160a72 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -10,6 +10,13 @@ class ScriptSystem; class ComponentManager; 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. + */ class BehaviorScript : public Component { protected: friend class crepe::ComponentManager; @@ -24,6 +31,7 @@ public: protected: friend class crepe::ScriptSystem; + //! Script instance std::unique_ptr<Script> script = nullptr; }; diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index 8fd381e..dad7e08 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -7,7 +7,6 @@ namespace crepe { class Config { private: Config() = default; - public: ~Config() = default; @@ -26,7 +25,7 @@ public: /** * \brief Log level * - * Only messages with equal or higher priority than this value will be + * Only messages with equal or higher severity than this value will be * logged. */ Log::Level level = Log::Level::INFO; 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; diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index d96c0e8..afe653f 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -1,6 +1,7 @@ #pragma once #include "../ComponentManager.h" +#include "../Exception.h" #include "BehaviorScript.h" #include "Script.h" @@ -8,16 +9,17 @@ namespace crepe { template <typename T> -T & Script::get_component() { +T & Script::get_component() const { std::vector<std::reference_wrapper<T>> all_components = this->get_components<T>(); - if (all_components.size() < 1) throw nullptr; // TODO + if (all_components.size() < 1) + throw Exception("Script: no component found with type = %s", typeid(T).name()); return all_components.back().get(); } template <typename T> -std::vector<std::reference_wrapper<T>> Script::get_components() { +std::vector<std::reference_wrapper<T>> Script::get_components() const { ComponentManager & mgr = ComponentManager::get_instance(); return mgr.get_components_by_id<T>(this->parent->game_object_id); } diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 8ddeac5..de0d0ea 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -26,7 +26,7 @@ Texture::~Texture() { void Texture::load(unique_ptr<Asset> res) { SDLContext & ctx = SDLContext::get_instance(); - this->texture = std::move(ctx.texture_from_path(res->canonical())); + this->texture = std::move(ctx.texture_from_path(res->get_canonical())); } int Texture::get_width() const { diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp index 49fb8dc..a65b052 100644 --- a/src/crepe/facade/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -4,19 +4,20 @@ #include "SoundContext.h" using namespace crepe; +using namespace std; -Sound::Sound(std::unique_ptr<Asset> res) { +Sound::Sound(unique_ptr<Asset> res) { dbg_trace(); this->load(std::move(res)); } Sound::Sound(const char * src) { dbg_trace(); - this->load(std::make_unique<Asset>(src)); + this->load(make_unique<Asset>(src)); } -void Sound::load(std::unique_ptr<Asset> res) { - this->sample.load(res->canonical()); +void Sound::load(unique_ptr<Asset> res) { + this->sample.load(res->get_canonical().c_str()); } void Sound::play() { diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h index 183bd7c..402482f 100644 --- a/src/crepe/facade/Sound.h +++ b/src/crepe/facade/Sound.h @@ -8,6 +8,12 @@ namespace crepe { +/** + * \brief Sound resource facade + * + * This class is a wrapper around a \c SoLoud::Wav instance, which holds a + * single sample. It is part of the sound facade. + */ class Sound { public: /** diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h index d3123d2..d703c16 100644 --- a/src/crepe/facade/SoundContext.h +++ b/src/crepe/facade/SoundContext.h @@ -6,19 +6,24 @@ namespace crepe { +/** + * \brief Sound engine facade + * + * This class is a wrapper around a \c SoLoud::Soloud instance, which provides + * the methods for playing \c Sound instances. It is part of the sound facade. + */ class SoundContext { private: + // singleton SoundContext(); virtual ~SoundContext(); - - // singleton - static SoundContext & get_instance(); SoundContext(const SoundContext &) = delete; SoundContext(SoundContext &&) = delete; SoundContext & operator=(const SoundContext &) = delete; SoundContext & operator=(SoundContext &&) = delete; private: + static SoundContext & get_instance(); SoLoud::Soloud engine; friend class Sound; }; diff --git a/src/crepe/system/PhysicsSystem.h b/src/crepe/system/PhysicsSystem.h index cc13b70..cb6160e 100644 --- a/src/crepe/system/PhysicsSystem.h +++ b/src/crepe/system/PhysicsSystem.h @@ -1,6 +1,7 @@ #pragma once namespace crepe { + /** * \brief System that controls all physics * diff --git a/src/crepe/system/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index f3d26d4..9d57640 100644 --- a/src/crepe/system/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -8,12 +8,31 @@ namespace crepe { class Script; +/** + * \brief Script system + * + * The script system is responsible for all \c BehaviorScript components, and + * calls the methods on classes derived from \c Script. + */ class ScriptSystem : public System { public: + /** + * \brief Call Script::update() on all active \c BehaviorScript instances + * + * This routine updates all scripts sequentially using the Script::update() + * method. It also calls Script::init() if this has not been done before on + * the \c BehaviorScript instance. + */ void update(); private: // TODO: to forward_list<reference_wrapper> + /** + * \brief Aggregate all active \c BehaviorScript components and return a list + * of references to their \c Script instances (utility) + * + * \returns List of active \c Script instances + */ std::forward_list<Script *> get_scripts() const; }; diff --git a/src/crepe/system/System.h b/src/crepe/system/System.h index 3b81bef..ec4507f 100644 --- a/src/crepe/system/System.h +++ b/src/crepe/system/System.h @@ -2,8 +2,18 @@ namespace crepe { +/** + * \brief Base ECS system class + * + * This class is used as the base for all system classes. Classes derived from + * System must implement the System::update() method and copy Script::Script + * with the `using`-syntax. + */ class System { public: + /** + * \brief Process all components this system is responsible for. + */ virtual void update() = 0; public: |