aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-12 19:46:15 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-12 19:46:15 +0100
commit297d621987c224db26eadfb9bde9235741387496 (patch)
tree9b21b5900ce8982f10c52e7312dbf3c471afdb73 /src/crepe
parent80a80f385874ea109b54454b58e84037aa6092cc (diff)
more cleanup + script utilities
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Animator.cpp2
-rw-r--r--src/crepe/api/BehaviorScript.hpp3
-rw-r--r--src/crepe/api/Camera.cpp2
-rw-r--r--src/crepe/api/Script.h78
-rw-r--r--src/crepe/api/Script.hpp23
-rw-r--r--src/crepe/api/Sprite.cpp2
-rw-r--r--src/crepe/api/Transform.cpp2
-rw-r--r--src/crepe/facade/DB.cpp2
-rw-r--r--src/crepe/facade/SDLContext.cpp2
-rw-r--r--src/crepe/facade/Sound.cpp2
-rw-r--r--src/crepe/facade/SoundContext.cpp2
-rw-r--r--src/crepe/facade/Texture.cpp2
-rw-r--r--src/crepe/manager/ComponentManager.cpp2
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp2
-rw-r--r--src/crepe/manager/ResourceManager.cpp2
-rw-r--r--src/crepe/system/ScriptSystem.cpp1
-rw-r--r--src/crepe/util/Log.cpp1
-rw-r--r--src/crepe/util/Log.h21
-rw-r--r--src/crepe/util/dbg.h19
19 files changed, 93 insertions, 77 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 4ce4bf0..203cef3 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -1,5 +1,5 @@
-#include "util/Log.h"
+#include "util/dbg.h"
#include "Animator.h"
#include "Component.h"
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
index b9bb1e2..353d5e2 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -2,8 +2,6 @@
#include <type_traits>
-#include "../util/Log.h"
-
#include "BehaviorScript.h"
#include "Script.h"
@@ -11,7 +9,6 @@ namespace crepe {
template <class T, typename... Args>
BehaviorScript & BehaviorScript::set_script(Args &&... args) {
- dbg_trace();
static_assert(std::is_base_of<Script, T>::value);
this->script = std::unique_ptr<Script>(new T(std::forward<Args>(args)...));
diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp
index 179dc18..19a3296 100644
--- a/src/crepe/api/Camera.cpp
+++ b/src/crepe/api/Camera.cpp
@@ -1,4 +1,4 @@
-#include "util/Log.h"
+#include "util/dbg.h"
#include "Camera.h"
#include "Component.h"
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index c797db0..18a029b 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -8,6 +8,7 @@
#include "../system/CollisionSystem.h"
#include "../types.h"
#include "../util/OptionalRef.h"
+#include "../util/Log.h"
namespace crepe {
@@ -58,83 +59,85 @@ protected:
protected:
/**
- * \name Utility functions
+ * \name Component query functions
+ * \see ComponentManager
* \{
*/
-
/**
* \brief Get single component of type \c T on this game object
- *
* \tparam T Type of component
- *
* \returns Reference to component
- *
* \throws std::runtime_error if this game object does not have a component with type \c T
*/
template <typename T>
T & get_component() const;
- // TODO: make get_component calls for component types that can have more than 1 instance
- // cause compile-time errors
-
/**
* \brief Get all components of type \c T on this game object
- *
* \tparam T Type of component
- *
* \returns List of component references
*/
template <typename T>
RefVector<T> get_components() const;
-
- /**
- * \copydoc ComponentManager::get_components_by_id
- * \see ComponentManager::get_components_by_id
- */
+ //! \copydoc ComponentManager::get_components_by_id
template <typename T>
RefVector<T> get_components_by_id(game_object_id_t id) const;
- /**
- * \copydoc ComponentManager::get_components_by_name
- * \see ComponentManager::get_components_by_name
- */
+ //! \copydoc ComponentManager::get_components_by_name
template <typename T>
RefVector<T> get_components_by_name(const std::string & name) const;
- /**
- * \copydoc ComponentManager::get_components_by_tag
- * \see ComponentManager::get_components_by_tag
- */
+ //! \copydoc ComponentManager::get_components_by_tag
template <typename T>
RefVector<T> get_components_by_tag(const std::string & tag) const;
+ //! \}
/**
- * \brief Log a message using Log::logf
- *
- * \tparam Args Log::logf parameters
- * \param args Log::logf parameters
+ * \name Logging functions
+ * \see Log
+ * \{
*/
- template <typename... Args>
- void logf(Args &&... args);
+ //! \copydoc Log::logf
+ template <class... Args>
+ void logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args);
+ //! \copydoc Log::logf
+ template <class... Args>
+ void logf(std::format_string<Args...> fmt, Args &&... args);
+ // \}
/**
- * \brief Subscribe to an event with an explicit channel
- * \see EventManager::subscribe
+ * \name Event manager functions
+ * \see EventManager
+ * \{
*/
+ //! \copydoc EventManager::subscribe
template <typename EventType>
void subscribe(const EventHandler<EventType> & callback, event_channel_t channel);
- /**
- * \brief Subscribe to an event on EventManager::CHANNEL_ALL
- * \see EventManager::subscribe
- */
+ //! \copydoc EventManager::subscribe
template <typename EventType>
void subscribe(const EventHandler<EventType> & callback);
+ //! \copydoc EventManager::trigger_event
+ template <typename EventType>
+ void trigger_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL);
+ //! \copydoc EventManager::queue_event
+ template <typename EventType>
+ void queue_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL);
+ //! \}
/**
- * \brief Set the next scene using SceneManager
- * \see SceneManager::set_next_scene
+ * \name Scene-related functions
+ * \see SceneManager
+ * \{
*/
+ //! \copydoc SceneManager::set_next_scene
void set_next_scene(const std::string & name);
+ //! \}
+ /**
+ * \name Save data management functions
+ * \see SaveManager
+ * \{
+ */
//! Retrieve SaveManager reference
SaveManager & get_save_manager() const;
+ //! \}
//! Replay management functions
struct replay { // NOLINT
@@ -152,7 +155,6 @@ protected:
replay(OptionalRef<Mediator> & mediator) : mediator(mediator) {}
friend class Script;
} replay{mediator};
-
//! \}
private:
diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp
index 547fb8b..2553fd1 100644
--- a/src/crepe/api/Script.hpp
+++ b/src/crepe/api/Script.hpp
@@ -24,9 +24,14 @@ RefVector<T> Script::get_components() const {
return this->get_components_by_id<T>(this->game_object_id);
}
-template <typename... Args>
-void Script::logf(Args &&... args) {
- Log::logf(std::forward<Args>(args)...);
+template <class... Args>
+void Script::logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args) {
+ Log::logf(level, fmt, std::forward<Args>(args)...);
+}
+
+template <class... Args>
+void Script::logf(std::format_string<Args...> fmt, Args &&... args) {
+ Log::logf(fmt, std::forward<Args>(args)...);
}
template <typename EventType>
@@ -55,6 +60,18 @@ void Script::subscribe(const EventHandler<EventType> & callback) {
this->subscribe_internal(callback, EventManager::CHANNEL_ALL);
}
+template <typename EventType>
+void Script::trigger_event(const EventType & event, event_channel_t channel) {
+ EventManager & mgr = this->mediator->event_manager;
+ mgr.trigger_event(event, channel);
+}
+
+template <typename EventType>
+void Script::queue_event(const EventType & event, event_channel_t channel) {
+ EventManager & mgr = this->mediator->event_manager;
+ mgr.queue_event(event, channel);
+}
+
template <typename T>
RefVector<T> Script::get_components_by_id(game_object_id_t id) const {
Mediator & mediator = this->mediator;
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
index ba684ba..0107c7b 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -1,6 +1,6 @@
#include <cmath>
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "api/Asset.h"
#include "Component.h"
diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp
index 5fc886b..32b44e1 100644
--- a/src/crepe/api/Transform.cpp
+++ b/src/crepe/api/Transform.cpp
@@ -1,4 +1,4 @@
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "Transform.h"
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp
index 95cf606..d45cd82 100644
--- a/src/crepe/facade/DB.cpp
+++ b/src/crepe/facade/DB.cpp
@@ -1,6 +1,6 @@
#include <cstring>
-#include "util/Log.h"
+#include "util/dbg.h"
#include "DB.h"
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 20bb030..fccc15f 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -19,7 +19,7 @@
#include "../api/Color.h"
#include "../api/Config.h"
#include "../api/Sprite.h"
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "manager/Mediator.h"
#include "SDLContext.h"
diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp
index 97e455e..b1e6463 100644
--- a/src/crepe/facade/Sound.cpp
+++ b/src/crepe/facade/Sound.cpp
@@ -1,5 +1,5 @@
#include "../api/Asset.h"
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "Sound.h"
diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp
index b1f8cb3..5091e07 100644
--- a/src/crepe/facade/SoundContext.cpp
+++ b/src/crepe/facade/SoundContext.cpp
@@ -1,4 +1,4 @@
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "SoundContext.h"
diff --git a/src/crepe/facade/Texture.cpp b/src/crepe/facade/Texture.cpp
index b63403d..23a9c8e 100644
--- a/src/crepe/facade/Texture.cpp
+++ b/src/crepe/facade/Texture.cpp
@@ -1,4 +1,4 @@
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "facade/SDLContext.h"
#include "manager/Mediator.h"
diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp
index 5f5c050..bc104d3 100644
--- a/src/crepe/manager/ComponentManager.cpp
+++ b/src/crepe/manager/ComponentManager.cpp
@@ -1,7 +1,7 @@
#include "../api/GameObject.h"
#include "../api/Metadata.h"
#include "../types.h"
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "ComponentManager.h"
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index 9819632..a98a29d 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -1,7 +1,7 @@
#include <chrono>
#include <thread>
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "LoopTimerManager.h"
diff --git a/src/crepe/manager/ResourceManager.cpp b/src/crepe/manager/ResourceManager.cpp
index a141a46..5713183 100644
--- a/src/crepe/manager/ResourceManager.cpp
+++ b/src/crepe/manager/ResourceManager.cpp
@@ -1,4 +1,4 @@
-#include "util/Log.h"
+#include "util/dbg.h"
#include "ResourceManager.h"
diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp
index ab79fc3..11da618 100644
--- a/src/crepe/system/ScriptSystem.cpp
+++ b/src/crepe/system/ScriptSystem.cpp
@@ -1,3 +1,4 @@
+#include "../util/dbg.h"
#include "../api/BehaviorScript.h"
#include "../api/Script.h"
#include "../manager/ComponentManager.h"
diff --git a/src/crepe/util/Log.cpp b/src/crepe/util/Log.cpp
index 84d80a8..e11a8d9 100644
--- a/src/crepe/util/Log.cpp
+++ b/src/crepe/util/Log.cpp
@@ -3,6 +3,7 @@
#include "../api/Config.h"
+#include "LogColor.h"
#include "Log.h"
using namespace crepe;
diff --git a/src/crepe/util/Log.h b/src/crepe/util/Log.h
index fc0bb3a..b43fe30 100644
--- a/src/crepe/util/Log.h
+++ b/src/crepe/util/Log.h
@@ -2,27 +2,6 @@
#include <format>
-// allow user to disable debug macros
-#ifndef CREPE_DISABLE_MACROS
-
-#include "LogColor.h"
-
-// utility macros
-#define _crepe_logf_here(level, fmt, ...) \
- crepe::Log::logf(level, "{}" fmt, \
- crepe::LogColor().fg_white(false).str(std::format( \
- "{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__)), \
- __VA_ARGS__)
-
-// very illegal global function-style macros
-// NOLINTBEGIN
-#define dbg_logf(fmt, ...) _crepe_logf_here(crepe::Log::Level::DEBUG, ": " fmt, __VA_ARGS__)
-#define dbg_log(str) _crepe_logf_here(crepe::Log::Level::DEBUG, ": {}", str)
-#define dbg_trace() _crepe_logf_here(crepe::Log::Level::TRACE, "", "")
-// NOLINTEND
-
-#endif
-
namespace crepe {
/**
diff --git a/src/crepe/util/dbg.h b/src/crepe/util/dbg.h
new file mode 100644
index 0000000..500e959
--- /dev/null
+++ b/src/crepe/util/dbg.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Log.h"
+#include "LogColor.h"
+
+// utility macros
+#define _crepe_logf_here(level, fmt, ...) \
+ crepe::Log::logf(level, "{}" fmt, \
+ crepe::LogColor().fg_white(false).str(std::format( \
+ "{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__)), \
+ __VA_ARGS__)
+
+// very illegal global function-style macros
+// NOLINTBEGIN
+#define dbg_logf(fmt, ...) _crepe_logf_here(crepe::Log::Level::DEBUG, ": " fmt, __VA_ARGS__)
+#define dbg_log(str) _crepe_logf_here(crepe::Log::Level::DEBUG, ": {}", str)
+#define dbg_trace() _crepe_logf_here(crepe::Log::Level::TRACE, "", "")
+// NOLINTEND
+