From dc93b1e9b3e05dfd3e271aaccbee1210180a6906 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 7 Nov 2024 21:19:01 +0100 Subject: update clang-format and run `make format` over my (loek)s files --- src/example/db.cpp | 4 ++-- src/example/proxy.cpp | 20 ++++++++++---------- src/example/savemgr.cpp | 13 ++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src/example') diff --git a/src/example/db.cpp b/src/example/db.cpp index c046421..8c06a84 100644 --- a/src/example/db.cpp +++ b/src/example/db.cpp @@ -1,12 +1,12 @@ -#include #include +#include #include using namespace crepe; using namespace std; // run before main -static auto _ = [] () { +static auto _ = []() { auto & cfg = Config::get_instance(); cfg.log.level = LogLevel::TRACE; return 0; diff --git a/src/example/proxy.cpp b/src/example/proxy.cpp index 9f54f96..0afff41 100644 --- a/src/example/proxy.cpp +++ b/src/example/proxy.cpp @@ -5,15 +5,15 @@ #include #include -#include #include +#include using namespace std; using namespace crepe; -void test_ro_ref(const int & val) { } -void test_rw_ref(int & val) { } -void test_ro_val(int val) { } +void test_ro_ref(const int & val) {} +void test_rw_ref(int & val) {} +void test_ro_val(int val) {} int main() { auto & cfg = Config::get_instance(); @@ -21,18 +21,19 @@ int main() { int real_value = 0; - ValueBroker broker { - [&real_value] (const int & target) { - dbg_logf("set %s to %s", to_string(real_value).c_str(), to_string(target).c_str()); + ValueBroker broker{ + [&real_value](const int & target) { + dbg_logf("set %s to %s", to_string(real_value).c_str(), + to_string(target).c_str()); real_value = target; }, - [&real_value] () -> const int & { + [&real_value]() -> const int & { dbg_logf("get %s", to_string(real_value).c_str()); return real_value; }, }; - Proxy proxy { broker }; + Proxy proxy{broker}; broker.set(54); proxy = 84; @@ -43,4 +44,3 @@ int main() { return 0; } - diff --git a/src/example/savemgr.cpp b/src/example/savemgr.cpp index c8dd2bc..436fb5a 100644 --- a/src/example/savemgr.cpp +++ b/src/example/savemgr.cpp @@ -4,21 +4,21 @@ */ #include -#include -#include -#include #include +#include +#include +#include using namespace crepe; // unrelated setup code -int _ = [] () { +int _ = []() { // make sure all log messages get printed auto & cfg = Config::get_instance(); cfg.log.level = LogLevel::TRACE; return 0; // satisfy compiler -} (); +}(); int main() { const char * key = "mygame.test"; @@ -27,7 +27,7 @@ int main() { dbg_logf("has key = %s", mgr.has(key) ? "true" : "false"); ValueBroker prop = mgr.get(key, 0); - Proxy val = mgr.get(key, 0); + Proxy val = mgr.get(key, 0); dbg_logf("val = %d", mgr.get(key).get()); prop.set(1); @@ -42,4 +42,3 @@ int main() { return 0; } - -- cgit v1.2.3 From 455bb50a5007daf46b8719fff2a6292da6a294bf Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 13 Nov 2024 11:39:45 +0100 Subject: fix physics test --- src/crepe/Component.cpp | 2 +- src/crepe/Component.h | 22 +++++---------- src/crepe/ComponentManager.h | 7 ++++- src/crepe/ComponentManager.hpp | 5 +--- src/crepe/api/Animator.cpp | 4 +-- src/crepe/api/Animator.h | 2 +- src/crepe/api/BehaviorScript.cpp | 3 ++ src/crepe/api/BehaviorScript.h | 3 +- src/crepe/api/BehaviorScript.hpp | 1 + src/crepe/api/CMakeLists.txt | 6 ++-- src/crepe/api/Camera.cpp | 4 +-- src/crepe/api/Camera.h | 2 +- src/crepe/api/GameObject.cpp | 8 ++++++ src/crepe/api/GameObject.h | 13 +++++++++ src/crepe/api/Metadata.cpp | 4 +-- src/crepe/api/Metadata.h | 2 +- src/crepe/api/ParticleEmitter.cpp | 4 +-- src/crepe/api/ParticleEmitter.h | 2 +- src/crepe/api/Rigidbody.cpp | 4 +-- src/crepe/api/Rigidbody.h | 2 +- src/crepe/api/SceneManager.cpp | 17 +++++------- src/crepe/api/SceneManager.h | 16 +++++------ src/crepe/api/Script.h | 7 ++++- src/crepe/api/Script.hpp | 4 +-- src/crepe/api/Sprite.cpp | 4 +-- src/crepe/api/Sprite.h | 2 +- src/crepe/api/Transform.cpp | 4 +-- src/crepe/api/Transform.h | 28 +++++++++---------- src/crepe/api/Vector2.cpp | 15 +--------- src/crepe/api/Vector2.h | 15 +++------- src/crepe/system/CMakeLists.txt | 6 ++-- src/crepe/system/ParticleSystem.cpp | 5 ++-- src/crepe/system/ParticleSystem.h | 15 ++++++---- src/crepe/system/PhysicsSystem.cpp | 2 +- src/crepe/system/PhysicsSystem.h | 12 ++++---- src/crepe/system/ScriptSystem.h | 3 +- src/example/script.cpp | 10 +++---- src/test/CMakeLists.txt | 2 +- src/test/PhysicsTest.cpp | 55 ++++++++++++++++++++----------------- 39 files changed, 164 insertions(+), 158 deletions(-) (limited to 'src/example') diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index c133739..d11a37e 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -2,5 +2,5 @@ using namespace crepe; -Component::Component(const Data & data) : data(data) {} +Component::Component(game_object_id_t id) : game_object_id(id) {} diff --git a/src/crepe/Component.h b/src/crepe/Component.h index c6d72df..12c10cb 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -14,23 +14,20 @@ class ComponentManager; */ class Component { public: - struct Data { - //! The ID of the GameObject this component belongs to - const game_object_id_t id; - //! The manager of this component - ComponentManager & component_manager; - }; + //! Whether the component is active + bool active = true; + //! The id of the GameObject this component belongs to + const game_object_id_t game_object_id; protected: /** - * \param base Data + * \param id The id of the GameObject this component belongs to */ - Component(const Data & base); + Component(game_object_id_t id); //! Only the ComponentManager can create components - friend class crepe::ComponentManager; + friend class ComponentManager; public: - virtual ~Component() = default; /** * \brief Get the maximum number of instances for this component * @@ -41,11 +38,6 @@ public: * \return The maximum number of instances for this component */ virtual int get_instances_max() const { return -1; } - -public: - Data data; - //! Whether the component is active - bool active = true; }; } // namespace crepe diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index e37bc4a..1d67e69 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -24,7 +24,7 @@ public: ComponentManager(); // dbg_trace ~ComponentManager(); // dbg_trace -public: +protected: /** * \brief Add a component to the ComponentManager * @@ -39,6 +39,11 @@ public: */ template T & add_component(game_object_id_t id, Args &&... args); + //! GameObject is used as an interface to add components instead of the + // component manager directly + friend class GameObject; + +public: /** * \brief Delete all components of a specific type and id * diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 89a8536..98efb49 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -31,10 +31,7 @@ T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { // Create a new component of type T (arguments directly forwarded). The // constructor must be called by ComponentManager. - T * instance_ptr = new T(Component::Data { - .id = id, - .component_manager = *this, - }, forward(args)...); + T * instance_ptr = new T(id, forward(args)...); if (instance_ptr == nullptr) throw std::bad_alloc(); T & instance_ref = *instance_ptr; diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index ad60981..cbf415d 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -9,8 +9,8 @@ using namespace crepe; -Animator::Animator(const Component::Data & data, Sprite & ss, int row, int col, int col_animator) - : Component(data), +Animator::Animator(game_object_id_t id, Sprite & ss, int row, int col, int col_animator) + : Component(id), spritesheet(ss), row(row), col(col) { diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index f66dc1a..75b8139 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -36,7 +36,7 @@ public: * * This constructor sets up the Animator with the given parameters, and initializes the animation system. */ - Animator(const Component::Data & data, Sprite & spritesheet, int row, int col, + Animator(game_object_id_t id, Sprite & spritesheet, int row, int col, int col_animate); ~Animator(); // dbg_trace diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index ce1cfde..41c144c 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -1,4 +1,7 @@ #include "BehaviorScript.h" +#include "Component.h" using namespace crepe; +BehaviorScript::BehaviorScript(game_object_id_t id, ComponentManager & mgr) : Component(id), component_manager(mgr) {} + diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 8d21a72..f156081 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -12,7 +12,7 @@ class Script; class BehaviorScript : public Component { protected: - using Component::Component; + BehaviorScript(game_object_id_t id, ComponentManager & component_manager); //! Only ComponentManager is allowed to instantiate BehaviorScript friend class ComponentManager; @@ -36,6 +36,7 @@ protected: //! Flag to indicate if script->init() has been called already bool initialized = false; std::unique_ptr