From fac06d488e635583307cd4a916a611500fb64c16 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 13 Nov 2024 13:10:25 +0100 Subject: cleanup + fix examples --- src/example/ecs.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/example/ecs.cpp') diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index e61c398..9a008ea 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -9,13 +9,20 @@ using namespace crepe; using namespace std; int main() { + ComponentManager mgr{}; + // Create a few GameObjects try { - GameObject body(0, "body", "person", Vector2{0, 0}, 0, 1); - GameObject right_leg(1, "rightLeg", "person", Vector2{1, 1}, 0, 1); - GameObject left_leg(2, "leftLeg", "person", Vector2{1, 1}, 0, 1); - GameObject right_foot(3, "rightFoot", "person", Vector2{2, 2}, 0, 1); - GameObject left_foot(4, "leftFoot", "person", Vector2{2, 2}, 0, 1); + GameObject & body + = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); + GameObject & right_leg + = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); + GameObject & left_leg + = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); + GameObject & right_foot + = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); + GameObject & left_foot + = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); // Set the parent of each GameObject right_foot.set_parent(right_leg); @@ -30,7 +37,6 @@ int main() { } // Get the Metadata and Transform components of each GameObject - ComponentManager & mgr = ComponentManager::get_instance(); vector> metadata = mgr.get_components_by_type(); vector> transform -- cgit v1.2.3 From 0aa97807cb9b7f1d1850449dd5a5e45b961445ce Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 13 Nov 2024 18:46:06 +0100 Subject: fix scene_manager example --- src/crepe/ComponentManager.cpp | 8 +++----- src/crepe/ComponentManager.h | 2 +- src/crepe/api/Scene.cpp | 2 +- src/crepe/api/Scene.h | 10 ++++++++-- src/crepe/api/SceneManager.hpp | 9 ++++++--- src/example/components_internal.cpp | 2 +- src/example/ecs.cpp | 15 +++++---------- src/example/physics.cpp | 3 +-- src/example/rendering.cpp | 6 +++--- src/example/scene_manager.cpp | 25 +++++++++++++++---------- src/example/script.cpp | 2 +- 11 files changed, 45 insertions(+), 39 deletions(-) (limited to 'src/example/ecs.cpp') diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index c6b658c..1e23609 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -25,13 +25,11 @@ void ComponentManager::delete_all_components() { ComponentManager::ComponentManager() { dbg_trace(); } ComponentManager::~ComponentManager() { dbg_trace(); } -GameObject & ComponentManager::new_object(const string & name, +GameObject ComponentManager::new_object(const string & name, const string & tag, const Vector2 & position, double rotation, double scale) { - GameObject * object = new GameObject(*this, this->next_id, name, tag, - position, rotation, scale); - this->objects.push_front(unique_ptr(object)); + GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; this->next_id++; - return *object; + return object; } diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index 75606e0..31a8bfa 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -101,7 +101,7 @@ public: std::vector> get_components_by_type() const; // TODO: doxygen - GameObject & new_object(const std::string & name, + GameObject new_object(const std::string & name, const std::string & tag = "", const Vector2 & position = {0, 0}, double rotation = 0, double scale = 0); diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index 933edf4..008d689 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -2,4 +2,4 @@ using namespace crepe; -Scene::Scene(const std::string & name) : name(name) {} +Scene::Scene(ComponentManager & mgr, const std::string & name) : component_manager(mgr), name(name) {} diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index f8bcc3d..334f306 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -4,14 +4,20 @@ namespace crepe { +class ComponentManager; + class Scene { public: - Scene(const std::string & name); + Scene(ComponentManager & mgr, const std::string & name); virtual ~Scene() = default; + virtual void load_scene() = 0; public: - std::string name; + const std::string name; + +protected: + ComponentManager & component_manager; }; } // namespace crepe diff --git a/src/crepe/api/SceneManager.hpp b/src/crepe/api/SceneManager.hpp index 8bad7b2..714f690 100644 --- a/src/crepe/api/SceneManager.hpp +++ b/src/crepe/api/SceneManager.hpp @@ -1,13 +1,16 @@ +#pragma once + #include "SceneManager.h" namespace crepe { template void SceneManager::add_scene(const std::string & name) { - static_assert(std::is_base_of::value, - "T must be derived from Scene"); + using namespace std; + static_assert(is_base_of::value, "T must be derived from Scene"); - scenes.emplace_back(make_unique(name)); + Scene * scene = new T(this->component_manager, name); + this->scenes.emplace_back(unique_ptr(scene)); // The first scene added, is the one that will be loaded at the beginning if (next_scene.empty()) { diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp index 7a8a08a..eeecdc0 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -30,7 +30,7 @@ int main() { GameObject * game_object[OBJ_COUNT]; for (int i = 0; i < OBJ_COUNT; ++i) { - GameObject & obj = mgr.new_object("Name", "Tag"); + GameObject obj = mgr.new_object("Name", "Tag"); obj.add_component("test"); obj.add_component(0, 0, i); } diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 9a008ea..06fc563 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -13,16 +13,11 @@ int main() { // Create a few GameObjects try { - GameObject & body - = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); - GameObject & right_leg - = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); - GameObject & left_leg - = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); - GameObject & right_foot - = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); - GameObject & left_foot - = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); + GameObject body = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); + GameObject right_leg = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); + GameObject left_leg = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); + GameObject right_foot = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); + GameObject left_foot = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); // Set the parent of each GameObject right_foot.set_parent(right_leg); diff --git a/src/example/physics.cpp b/src/example/physics.cpp index 2ebf779..ad663a0 100644 --- a/src/example/physics.cpp +++ b/src/example/physics.cpp @@ -11,8 +11,7 @@ using namespace std; int main(int argc, char * argv[]) { ComponentManager mgr{}; - GameObject & game_object - = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0); + GameObject game_object = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0); game_object.add_component(Rigidbody::Data{ .mass = 1, .gravity_scale = 1, diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index 74c00e2..abd11b1 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -23,9 +23,9 @@ int main() { ComponentManager mgr{}; RenderSystem sys{mgr}; - auto & obj = mgr.new_object("name", "tag", Vector2{0, 0}, 1, 1); - auto & obj1 = mgr.new_object("name", "tag", Vector2{500, 0}, 1, 0.1); - auto & obj2 = mgr.new_object("name", "tag", Vector2{800, 0}, 1, 0.1); + GameObject obj = mgr.new_object("name", "tag", Vector2{0, 0}, 1, 1); + GameObject obj1 = mgr.new_object("name", "tag", Vector2{500, 0}, 1, 0.1); + GameObject obj2 = mgr.new_object("name", "tag", Vector2{800, 0}, 1, 0.1); // Normal adding components { diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp index 5cd7336..1c982aa 100644 --- a/src/example/scene_manager.cpp +++ b/src/example/scene_manager.cpp @@ -12,24 +12,26 @@ using namespace std; class ConcreteScene1 : public Scene { public: - ConcreteScene1(string name) : Scene(name) {} + using Scene::Scene; void load_scene() { - GameObject object1(0, "scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); - GameObject object2(1, "scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); - GameObject object3(2, "scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); + auto & mgr = this->component_manager; + GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); + GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); + GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); } }; class ConcreteScene2 : public Scene { public: - ConcreteScene2(string name) : Scene(name) {} + using Scene::Scene; void load_scene() { - GameObject object1(0, "scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); - GameObject object2(1, "scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); - GameObject object3(2, "scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); - GameObject object4(3, "scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); + auto & mgr = this->component_manager; + GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); + GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); + GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); + GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); } }; @@ -41,7 +43,9 @@ int main() { scene_mgr.add_scene("scene1"); scene_mgr.add_scene("scene2"); - // There is no need to call set_next_scene() at the beginnen, because the first scene will be automatically set as the next scene + // There is no need to call set_next_scene() at the beginning because the + // first scene will be automatically set as the next scene + // Load scene1 (the first scene added) scene_mgr.load_next_scene(); @@ -73,3 +77,4 @@ int main() { return 0; } + diff --git a/src/example/script.cpp b/src/example/script.cpp index c82764c..a23295b 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -39,7 +39,7 @@ int main() { ScriptSystem system{component_manager}; // Create game object with Transform and BehaviorScript components - auto & obj = component_manager.new_object("name"); + GameObject obj = component_manager.new_object("name"); obj.add_component().set_script(); // Update all scripts. This should result in MyScript::update being called -- cgit v1.2.3 From d69f1642cb397d68d591718f83028e14620ab340 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 13 Nov 2024 19:22:23 +0100 Subject: `make format` --- src/crepe/ComponentManager.cpp | 10 +++++----- src/crepe/ComponentManager.h | 6 +++--- src/crepe/api/Scene.cpp | 4 +++- src/example/ecs.cpp | 12 ++++++++---- src/example/scene_manager.cpp | 22 ++++++++++++++-------- 5 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src/example/ecs.cpp') diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index 1e23609..7af0380 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -25,11 +25,11 @@ void ComponentManager::delete_all_components() { ComponentManager::ComponentManager() { dbg_trace(); } ComponentManager::~ComponentManager() { dbg_trace(); } -GameObject ComponentManager::new_object(const string & name, - const string & tag, - const Vector2 & position, - double rotation, double scale) { - GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; +GameObject ComponentManager::new_object(const string & name, const string & tag, + const Vector2 & position, + double rotation, double scale) { + GameObject object{*this, this->next_id, name, tag, + position, rotation, scale}; this->next_id++; return object; } diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index 31a8bfa..51c84a4 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -102,9 +102,9 @@ public: // TODO: doxygen GameObject new_object(const std::string & name, - const std::string & tag = "", - const Vector2 & position = {0, 0}, - double rotation = 0, double scale = 0); + const std::string & tag = "", + const Vector2 & position = {0, 0}, + double rotation = 0, double scale = 0); private: /** diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index 008d689..88aa82d 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -2,4 +2,6 @@ using namespace crepe; -Scene::Scene(ComponentManager & mgr, const std::string & name) : component_manager(mgr), name(name) {} +Scene::Scene(ComponentManager & mgr, const std::string & name) + : component_manager(mgr), + name(name) {} diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 06fc563..5f83da1 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -14,10 +14,14 @@ int main() { // Create a few GameObjects try { GameObject body = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); - GameObject right_leg = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); - GameObject left_leg = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); - GameObject right_foot = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); - GameObject left_foot = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); + GameObject right_leg + = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); + GameObject left_leg + = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); + GameObject right_foot + = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); + GameObject left_foot + = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); // Set the parent of each GameObject right_foot.set_parent(right_leg); diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp index 1c982aa..24ab72e 100644 --- a/src/example/scene_manager.cpp +++ b/src/example/scene_manager.cpp @@ -16,9 +16,12 @@ public: void load_scene() { auto & mgr = this->component_manager; - GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); - GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); - GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); + GameObject object1 + = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); + GameObject object2 + = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); + GameObject object3 + = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); } }; @@ -28,10 +31,14 @@ public: void load_scene() { auto & mgr = this->component_manager; - GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); - GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); - GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); - GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); + GameObject object1 + = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); + GameObject object2 + = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); + GameObject object3 + = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); + GameObject object4 + = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); } }; @@ -77,4 +84,3 @@ int main() { return 0; } - -- cgit v1.2.3 From fdd5c471dffd4a204a91e8d1d70567fa56ea29a5 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 15 Nov 2024 20:49:37 +0100 Subject: `make format` --- src/crepe/Component.h | 1 + src/crepe/ComponentManager.cpp | 4 ++-- src/crepe/ComponentManager.h | 7 +++---- src/crepe/api/Animator.cpp | 3 +-- src/crepe/api/Camera.cpp | 4 +++- src/crepe/api/GameObject.cpp | 12 +++++++++--- src/crepe/api/GameObject.h | 4 +++- src/crepe/api/LoopManager.cpp | 4 +--- src/crepe/api/LoopManager.hpp | 2 +- src/crepe/api/Script.hpp | 3 ++- src/crepe/api/Vector2.cpp | 20 +++++--------------- src/crepe/facade/DB.cpp | 15 ++++++--------- src/crepe/facade/Sound.cpp | 4 +--- src/crepe/system/RenderSystem.cpp | 4 +--- src/crepe/util/Log.h | 15 ++++++--------- src/crepe/util/Log.hpp | 3 +-- src/example/ecs.cpp | 12 ++++-------- src/example/scene_manager.cpp | 21 +++++++-------------- src/test/PhysicsTest.cpp | 12 ++++-------- 19 files changed, 61 insertions(+), 89 deletions(-) (limited to 'src/example/ecs.cpp') diff --git a/src/crepe/Component.h b/src/crepe/Component.h index 68b28ef..5279fb3 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -26,6 +26,7 @@ protected: Component(game_object_id_t id); //! Only the ComponentManager can create components friend class ComponentManager; + public: virtual ~Component() = default; diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index 67c6fc7..e310577 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -26,8 +26,8 @@ void ComponentManager::delete_all_components() { } GameObject ComponentManager::new_object(const string & name, const string & tag, - const Vector2 & position, - double rotation, double scale) { + const Vector2 & position, double rotation, + double scale) { GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; this->next_id++; return object; diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index a14cb46..99d45d9 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -100,10 +100,9 @@ public: std::vector> get_components_by_type() const; // TODO: doxygen - GameObject new_object(const std::string & name, - const std::string & tag = "", - const Vector2 & position = {0, 0}, - double rotation = 0, double scale = 0); + GameObject new_object(const std::string & name, const std::string & tag = "", + const Vector2 & position = {0, 0}, double rotation = 0, + double scale = 0); private: /** diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index cccbc67..464b0fd 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,8 +7,7 @@ using namespace crepe; -Animator::Animator(game_object_id_t id, Sprite & ss, int row, int col, - int col_animator) +Animator::Animator(game_object_id_t id, Sprite & ss, int row, int col, int col_animator) : Component(id), spritesheet(ss), row(row), diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index eb99f7f..5835bdd 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -6,7 +6,9 @@ using namespace crepe; -Camera::Camera(game_object_id_t id, const Color & bg_color) : Component(id), bg_color(bg_color) { +Camera::Camera(game_object_id_t id, const Color & bg_color) + : Component(id), + bg_color(bg_color) { dbg_trace(); } diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 2b836e1..287e81d 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -7,7 +7,11 @@ using namespace crepe; using namespace std; -GameObject::GameObject(ComponentManager & component_manager, game_object_id_t id, const std::string & name, const std::string & tag, const Vector2 & position, double rotation, double scale) : id(id), component_manager(component_manager) { +GameObject::GameObject(ComponentManager & component_manager, game_object_id_t id, + const std::string & name, const std::string & tag, + const Vector2 & position, double rotation, double scale) + : id(id), + component_manager(component_manager) { // Add Transform and Metadata components ComponentManager & mgr = this->component_manager; @@ -19,10 +23,12 @@ void GameObject::set_parent(const GameObject & parent) { ComponentManager & mgr = this->component_manager; // Set parent on own Metadata component - vector> this_metadata = mgr.get_components_by_id(this->id); + vector> this_metadata + = mgr.get_components_by_id(this->id); this_metadata.at(0).get().parent = parent.id; // Add own id to children list of parent's Metadata component - vector> parent_metadata = mgr.get_components_by_id(parent.id); + vector> parent_metadata + = mgr.get_components_by_id(parent.id); parent_metadata.at(0).get().children.push_back(this->id); } diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index cf6765a..34ef8bb 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -29,7 +29,9 @@ private: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - GameObject(ComponentManager & component_manager, game_object_id_t id, const std::string & name, const std::string & tag, const Vector2 & position, double rotation, double scale); + GameObject(ComponentManager & component_manager, game_object_id_t id, + const std::string & name, const std::string & tag, const Vector2 & position, + double rotation, double scale); //! ComponentManager instances GameObject friend class ComponentManager; diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index f0788ab..6303e2b 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -22,9 +22,7 @@ LoopManager::LoopManager() { this->load_system(); } -ComponentManager & LoopManager::get_component_manager() { - return this->component_manager; -} +ComponentManager & LoopManager::get_component_manager() { return this->component_manager; } void LoopManager::process_input() { SDLContext::get_instance().handle_events(this->game_running); diff --git a/src/crepe/api/LoopManager.hpp b/src/crepe/api/LoopManager.hpp index 85a329b..0b14fdb 100644 --- a/src/crepe/api/LoopManager.hpp +++ b/src/crepe/api/LoopManager.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include #include +#include #include "../system/System.h" diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index 13b8077..c4e07e8 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -12,7 +12,8 @@ T & Script::get_component() const { using namespace std; vector> all_components = this->get_components(); if (all_components.size() < 1) - throw runtime_error(format("Script: no component found with type = {}", typeid(T).name())); + throw runtime_error( + format("Script: no component found with type = {}", typeid(T).name())); return all_components.back().get(); } diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp index 97b74ac..30b968e 100644 --- a/src/crepe/api/Vector2.cpp +++ b/src/crepe/api/Vector2.cpp @@ -2,17 +2,11 @@ using namespace crepe; -Vector2 Vector2::operator-(const Vector2 & other) const { - return {x - other.x, y - other.y}; -} +Vector2 Vector2::operator-(const Vector2 & other) const { return {x - other.x, y - other.y}; } -Vector2 Vector2::operator+(const Vector2 & other) const { - return {x + other.x, y + other.y}; -} +Vector2 Vector2::operator+(const Vector2 & other) const { return {x + other.x, y + other.y}; } -Vector2 Vector2::operator*(double scalar) const { - return {x * scalar, y * scalar}; -} +Vector2 Vector2::operator*(double scalar) const { return {x * scalar, y * scalar}; } Vector2 & Vector2::operator*=(const Vector2 & other) { x *= other.x; @@ -34,10 +28,6 @@ Vector2 & Vector2::operator+=(double other) { Vector2 Vector2::operator-() const { return {-x, -y}; } -bool Vector2::operator==(const Vector2 & other) const { - return x == other.x && y == other.y; -} +bool Vector2::operator==(const Vector2 & other) const { return x == other.x && y == other.y; } -bool Vector2::operator!=(const Vector2 & other) const { - return !(*this == other); -} +bool Vector2::operator!=(const Vector2 & other) const { return !(*this == other); } diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp index 00acf04..d5d19dc 100644 --- a/src/crepe/facade/DB.cpp +++ b/src/crepe/facade/DB.cpp @@ -18,7 +18,8 @@ DB::DB(const string & path) { this->db = {db, [](libdb::DB * db) { db->close(db, 0); }}; // load or create database file - ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, libdb::DB_BTREE, DB_CREATE, 0); + ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, libdb::DB_BTREE, DB_CREATE, + 0); if (ret != 0) throw runtime_error(format("db->open: {}", libdb::db_strerror(ret))); // create cursor @@ -42,22 +43,18 @@ string DB::get(const string & key) { memset(&db_val, 0, sizeof(libdb::DBT)); int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST); - if (ret == 0) - return {static_cast(db_val.data), db_val.size}; + if (ret == 0) return {static_cast(db_val.data), db_val.size}; string err = format("cursor->get: {}", libdb::db_strerror(ret)); - if (ret == DB_NOTFOUND) - throw out_of_range(err); - else - throw runtime_error(err); + if (ret == DB_NOTFOUND) throw out_of_range(err); + else throw runtime_error(err); } void DB::set(const string & key, const string & value) { libdb::DBT db_key = this->to_thing(key); libdb::DBT db_val = this->to_thing(value); int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0); - if (ret != 0) - throw runtime_error(format("cursor->get: {}", libdb::db_strerror(ret))); + if (ret != 0) throw runtime_error(format("cursor->get: {}", libdb::db_strerror(ret))); } bool DB::has(const std::string & key) { diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp index a65b052..7aa89a9 100644 --- a/src/crepe/facade/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -16,9 +16,7 @@ Sound::Sound(const char * src) { this->load(make_unique(src)); } -void Sound::load(unique_ptr res) { - this->sample.load(res->get_canonical().c_str()); -} +void Sound::load(unique_ptr res) { this->sample.load(res->get_canonical().c_str()); } void Sound::play() { SoundContext & ctx = SoundContext::get_instance(); diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 19493f7..fa3d0de 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -11,9 +11,7 @@ using namespace crepe; -void RenderSystem::clear_screen() const { - SDLContext::get_instance().clear_screen(); -} +void RenderSystem::clear_screen() const { SDLContext::get_instance().clear_screen(); } void RenderSystem::present_screen() const { SDLContext::get_instance().present_screen(); } void RenderSystem::update_camera() { diff --git a/src/crepe/util/Log.h b/src/crepe/util/Log.h index e0844ca..d55b11e 100644 --- a/src/crepe/util/Log.h +++ b/src/crepe/util/Log.h @@ -9,16 +9,14 @@ // 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__) + 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_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 @@ -59,8 +57,7 @@ public: * \param args Format arguments */ template - static void logf(const Level & level, std::format_string fmt, - Args &&... args); + static void logf(const Level & level, std::format_string fmt, Args &&... args); /** * \brief Format a message and log it (with default severity \c INFO) diff --git a/src/crepe/util/Log.hpp b/src/crepe/util/Log.hpp index 651f076..c2156cd 100644 --- a/src/crepe/util/Log.hpp +++ b/src/crepe/util/Log.hpp @@ -10,8 +10,7 @@ void Log::logf(std::format_string fmt, Args &&... args) { } template -void Log::logf(const Level & level, std::format_string fmt, - Args &&... args) { +void Log::logf(const Level & level, std::format_string fmt, Args &&... args) { Log::log(level, std::format(fmt, std::forward(args)...)); } diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 711bde6..d5ba51b 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -14,14 +14,10 @@ int main() { // Create a few GameObjects try { GameObject body = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1); - GameObject right_leg - = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); - GameObject left_leg - = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); - GameObject right_foot - = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); - GameObject left_foot - = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); + GameObject right_leg = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1); + GameObject left_leg = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1); + GameObject right_foot = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1); + GameObject left_foot = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1); // Set the parent of each GameObject right_foot.set_parent(right_leg); diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp index 62720eb..accec7d 100644 --- a/src/example/scene_manager.cpp +++ b/src/example/scene_manager.cpp @@ -16,12 +16,9 @@ public: void load_scene() { auto & mgr = this->component_manager; - GameObject object1 - = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); - GameObject object2 - = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); - GameObject object3 - = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); + GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1); + GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1); + GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1); } }; @@ -31,14 +28,10 @@ public: void load_scene() { auto & mgr = this->component_manager; - GameObject object1 - = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); - GameObject object2 - = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); - GameObject object3 - = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); - GameObject object4 - = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); + GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1); + GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1); + GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1); + GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1); } }; diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index edb76e9..1e37c26 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -49,8 +49,7 @@ public: TEST_F(PhysicsTest, gravity) { Config::get_instance().physics.gravity = 1; ComponentManager & mgr = this->component_manager; - vector> transforms - = mgr.get_components_by_id(0); + vector> transforms = mgr.get_components_by_id(0); const Transform & transform = transforms.front().get(); ASSERT_FALSE(transforms.empty()); EXPECT_EQ(transform.position.y, 0); @@ -64,8 +63,7 @@ TEST_F(PhysicsTest, gravity) { TEST_F(PhysicsTest, max_velocity) { ComponentManager & mgr = this->component_manager; - vector> rigidbodies - = mgr.get_components_by_id(0); + vector> rigidbodies = mgr.get_components_by_id(0); Rigidbody & rigidbody = rigidbodies.front().get(); ASSERT_FALSE(rigidbodies.empty()); EXPECT_EQ(rigidbody.data.linear_velocity.y, 0); @@ -88,11 +86,9 @@ TEST_F(PhysicsTest, max_velocity) { TEST_F(PhysicsTest, movement) { Config::get_instance().physics.gravity = 0; ComponentManager & mgr = this->component_manager; - vector> rigidbodies - = mgr.get_components_by_id(0); + vector> rigidbodies = mgr.get_components_by_id(0); Rigidbody & rigidbody = rigidbodies.front().get(); - vector> transforms - = mgr.get_components_by_id(0); + vector> transforms = mgr.get_components_by_id(0); const Transform & transform = transforms.front().get(); ASSERT_FALSE(rigidbodies.empty()); ASSERT_FALSE(transforms.empty()); -- cgit v1.2.3