From f9aa198eef7b85eeba3bac4c4fe2d4578b836bbf Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 13 Oct 2024 20:52:08 +0200 Subject: WIP behavior script (problems) --- src/crepe/util/fmt.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/crepe/util/fmt.cpp (limited to 'src/crepe/util/fmt.cpp') diff --git a/src/crepe/util/fmt.cpp b/src/crepe/util/fmt.cpp new file mode 100644 index 0000000..3a43a6f --- /dev/null +++ b/src/crepe/util/fmt.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "fmt.h" + +using namespace std; + +string crepe::util::va_stringf(va_list args, const char * fmt) { + va_list args_copy; + va_copy(args_copy, args); + + size_t sz = vsnprintf(NULL, 0, fmt, args_copy) + 1; + char * msg = (char *) malloc(sz); + va_end(args_copy); + + vsnprintf(msg, sz, fmt, args); + + string out = msg; + free(msg); + + va_end(args); + + return out; +} + +string crepe::util::stringf(const char * fmt, ...) { + va_list args; + va_start(args, fmt); + string out = va_stringf(args, fmt); + va_end(args); + return out; +} + -- cgit v1.2.3 From a2c719948ff8af9abe267c4d1c9b16cd1e2fb317 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 17 Oct 2024 17:15:53 +0200 Subject: `make format` --- src/crepe/Component.cpp | 1 - src/crepe/Component.h | 1 + src/crepe/ComponentManager.cpp | 11 +++-------- src/crepe/ComponentManager.hpp | 9 ++++++--- src/crepe/ScriptSystem.cpp | 17 ++++++----------- src/crepe/ScriptSystem.h | 4 +--- src/crepe/System.h | 7 +++---- src/crepe/api/BehaviorScript.cpp | 7 ++----- src/crepe/api/BehaviorScript.h | 8 ++++---- src/crepe/api/BehaviorScript.hpp | 4 ++-- src/crepe/api/Script.cpp | 2 -- src/crepe/api/Script.h | 4 ++-- src/crepe/util/fmt.cpp | 5 ++--- src/crepe/util/fmt.h | 2 +- src/crepe/util/log.cpp | 3 +-- src/example/script.cpp | 11 ++++------- 16 files changed, 38 insertions(+), 58 deletions(-) (limited to 'src/crepe/util/fmt.cpp') diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index 737f30a..bce90f1 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -1,4 +1,3 @@ #include "Component.h" using namespace crepe; - diff --git a/src/crepe/Component.h b/src/crepe/Component.h index 00b2164..d9a01ac 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -5,6 +5,7 @@ namespace crepe { class Component { protected: Component() = default; + public: virtual ~Component() = default; // TODO: shouldn't this constructor be deleted because this class will never diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index 8aa9d4e..8bde33a 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -1,5 +1,5 @@ -#include "util/log.h" #include "ComponentManager.h" +#include "util/log.h" using namespace crepe; @@ -24,11 +24,6 @@ void ComponentManager::delete_all_components() { this->components.clear(); } -ComponentManager::ComponentManager() { - dbg_trace(); -} - -ComponentManager::~ComponentManager() { - dbg_trace(); -} +ComponentManager::ComponentManager() { dbg_trace(); } +ComponentManager::~ComponentManager() { dbg_trace(); } diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index e0242a2..2377a94 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -10,7 +10,8 @@ template T & ComponentManager::add_component(uint32_t id, Args &&... args) { using namespace std; - static_assert(is_base_of::value, "add_component must recieve a derivative class of Component"); + static_assert(is_base_of::value, + "add_component must recieve a derivative class of Component"); // Determine the type of T (this is used as the key of the unordered_map<>) type_index type = typeid(T); @@ -81,7 +82,8 @@ ComponentManager::get_components_by_id(uint32_t id) const { if (components.find(type) == components.end()) return component_vector; // Get the correct vector<> - const vector>> & component_array = components.at(type); + const vector>> & component_array + = components.at(type); // Make sure that the id (that we are looking for) is within the boundaries of the vector<> if (id >= component_array.size()) return component_vector; @@ -117,7 +119,8 @@ ComponentManager::get_components_by_type() const { if (components.find(type) == components.end()) return component_vector; // Get the correct vector<> - const vector>> & component_array = components.at(type); + const vector>> & component_array + = components.at(type); // Loop through the whole vector<> for (const vector> & component : component_array) { diff --git a/src/crepe/ScriptSystem.cpp b/src/crepe/ScriptSystem.cpp index 1a7bff4..5d882be 100644 --- a/src/crepe/ScriptSystem.cpp +++ b/src/crepe/ScriptSystem.cpp @@ -2,8 +2,8 @@ #include #include -#include "ScriptSystem.h" #include "ComponentManager.h" +#include "ScriptSystem.h" #include "api/BehaviorScript.h" #include "api/Script.h" #include "util/log.h" @@ -12,12 +12,8 @@ using namespace std; using namespace crepe; using namespace crepe::api; -ScriptSystem::ScriptSystem() { - dbg_trace(); -} -ScriptSystem::~ScriptSystem() { - dbg_trace(); -} +ScriptSystem::ScriptSystem() { dbg_trace(); } +ScriptSystem::~ScriptSystem() { dbg_trace(); } ScriptSystem & ScriptSystem::get_instance() { static ScriptSystem instance; @@ -29,14 +25,14 @@ void ScriptSystem::update() { dbg_trace(); forward_list