aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.cpp2
-rw-r--r--src/crepe/api/AssetManager.cpp2
-rw-r--r--src/crepe/api/AudioSource.cpp23
-rw-r--r--src/crepe/api/AudioSource.h39
-rw-r--r--src/crepe/api/BehaviorScript.h10
-rw-r--r--src/crepe/api/BehaviorScript.hpp2
-rw-r--r--src/crepe/api/Camera.cpp2
-rw-r--r--src/crepe/api/Config.h6
-rw-r--r--src/crepe/api/LoopTimer.cpp2
-rw-r--r--src/crepe/api/SaveManager.cpp2
-rw-r--r--src/crepe/api/Script.h45
-rw-r--r--src/crepe/api/Script.hpp9
-rw-r--r--src/crepe/api/Sprite.cpp2
-rw-r--r--src/crepe/api/Texture.cpp4
-rw-r--r--src/crepe/api/Transform.cpp2
15 files changed, 67 insertions, 85 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 58fee2a..863dce6 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -1,7 +1,7 @@
#include <cstdint>
-#include "util/log.h"
+#include "util/Log.h"
#include "Animator.h"
#include "Component.h"
diff --git a/src/crepe/api/AssetManager.cpp b/src/crepe/api/AssetManager.cpp
index b891760..3925758 100644
--- a/src/crepe/api/AssetManager.cpp
+++ b/src/crepe/api/AssetManager.cpp
@@ -1,4 +1,4 @@
-#include "util/log.h"
+#include "util/Log.h"
#include "AssetManager.h"
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp
deleted file mode 100644
index 63fd0d7..0000000
--- a/src/crepe/api/AudioSource.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <memory>
-
-#include "../facade/Sound.h"
-
-#include "AudioSource.h"
-
-using namespace crepe;
-
-AudioSource::AudioSource(std::unique_ptr<Asset> audio_clip) {
- this->sound = std::make_unique<crepe::Sound>(std::move(audio_clip));
-}
-
-void AudioSource::play() { return this->play(false); }
-
-void AudioSource::play(bool looping) {
- this->sound->set_looping(looping);
- this->sound->play();
-}
-
-void AudioSource::stop() {
- this->sound->pause();
- this->sound->rewind();
-}
diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h
deleted file mode 100644
index 1e24ae8..0000000
--- a/src/crepe/api/AudioSource.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include <memory>
-
-#include "../Asset.h"
-#include "../Component.h"
-
-namespace crepe {
-
-class Sound;
-
-//! Audio source component
-class AudioSource : public Component {
-public:
- AudioSource(std::unique_ptr<Asset> audio_clip);
- virtual ~AudioSource() = default;
-
-public:
- //! Start or resume this audio source
- void play();
- void play(bool looping);
- //! Stop this audio source
- void stop();
-
-public:
- //! Sample file location
- std::unique_ptr<Asset> audio_clip;
- //! TODO: ?????
- bool play_on_awake;
- //! Repeat the current audio clip during playback
- bool loop;
- //! Normalized volume (0.0 - 1.0)
- float volume;
-
-private:
- std::unique_ptr<Sound> sound;
-};
-
-} // namespace crepe
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index 6b1fec7..4160a72 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -10,13 +10,20 @@ 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;
using Component::Component;
public:
- virtual ~BehaviorScript() = default;
+ ~BehaviorScript() = default;
public:
template <class T>
@@ -24,6 +31,7 @@ public:
protected:
friend class crepe::ScriptSystem;
+ //! Script instance
std::unique_ptr<Script> script = nullptr;
};
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
index 4751607..bc157fd 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -2,7 +2,7 @@
#include <type_traits>
-#include "../util/log.h"
+#include "../util/Log.h"
#include "BehaviorScript.h"
#include "Script.h"
diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp
index 6355a03..6f0deb1 100644
--- a/src/crepe/api/Camera.cpp
+++ b/src/crepe/api/Camera.cpp
@@ -1,7 +1,7 @@
#include <cstdint>
-#include "util/log.h"
+#include "util/Log.h"
#include "Camera.h"
#include "Color.h"
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 8c9e643..e3f86bf 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -1,6 +1,6 @@
#pragma once
-#include "../util/log.h"
+#include "../util/Log.h"
namespace crepe {
@@ -26,10 +26,10 @@ 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.
*/
- LogLevel level = LogLevel::INFO;
+ Log::Level level = Log::Level::INFO;
/**
* \brief Colored log output
*
diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp
index 8f09e41..b3aec22 100644
--- a/src/crepe/api/LoopTimer.cpp
+++ b/src/crepe/api/LoopTimer.cpp
@@ -1,7 +1,7 @@
#include <chrono>
#include "../facade/SDLContext.h"
-#include "../util/log.h"
+#include "../util/Log.h"
#include "LoopTimer.h"
diff --git a/src/crepe/api/SaveManager.cpp b/src/crepe/api/SaveManager.cpp
index 43276c5..2974b91 100644
--- a/src/crepe/api/SaveManager.cpp
+++ b/src/crepe/api/SaveManager.cpp
@@ -1,5 +1,5 @@
#include "../facade/DB.h"
-#include "../util/log.h"
+#include "../util/Log.h"
#include "Config.h"
#include "SaveManager.h"
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 49e625f..e6fbb5c 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -3,18 +3,34 @@
#include <vector>
namespace crepe {
-class ScriptSystem;
-}
-
-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
@@ -22,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..7ec3ebe 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,18 @@
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 = {}",
+ 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/Sprite.cpp b/src/crepe/api/Sprite.cpp
index 6f0433f..ac0079e 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -1,6 +1,6 @@
#include <memory>
-#include "../util/log.h"
+#include "../util/Log.h"
#include "facade/SDLContext.h"
#include "Component.h"
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
index 5ebd23d..de0d0ea 100644
--- a/src/crepe/api/Texture.cpp
+++ b/src/crepe/api/Texture.cpp
@@ -1,7 +1,7 @@
#include <SDL2/SDL_render.h>
#include "../facade/SDLContext.h"
-#include "../util/log.h"
+#include "../util/Log.h"
#include "Asset.h"
#include "Texture.h"
@@ -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/api/Transform.cpp b/src/crepe/api/Transform.cpp
index e401120..e9108c4 100644
--- a/src/crepe/api/Transform.cpp
+++ b/src/crepe/api/Transform.cpp
@@ -1,4 +1,4 @@
-#include "util/log.h"
+#include "../util/Log.h"
#include "Transform.h"