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/api/Vector2.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/crepe/api/Vector2.cpp') diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp index 09bb59b..aa391fa 100644 --- a/src/crepe/api/Vector2.cpp +++ b/src/crepe/api/Vector2.cpp @@ -1,57 +1,44 @@ #include "Vector2.h" -namespace crepe { +using namespace crepe; -// Constructor with initial values -Vector2::Vector2(float x, float y) : x(x), y(y) {} - -// Subtracts another vector from this vector and returns the result. Vector2 Vector2::operator-(const Vector2 & other) const { return {x - other.x, y - other.y}; } -// Adds another vector to this vector and returns the result. Vector2 Vector2::operator+(const Vector2 & other) const { return {x + other.x, y + other.y}; } -// Multiplies this vector by a scalar and returns the result. Vector2 Vector2::operator*(float scalar) const { return {x * scalar, y * scalar}; } -// Multiplies this vector by another vector element-wise and updates this vector. Vector2 & Vector2::operator*=(const Vector2 & other) { x *= other.x; y *= other.y; return *this; } -// Adds another vector to this vector and updates this vector. Vector2 & Vector2::operator+=(const Vector2 & other) { x += other.x; y += other.y; return *this; } -// Adds a scalar value to both components of this vector and updates this vector. Vector2 & Vector2::operator+=(float other) { x += other; y += other; return *this; } -// Returns the negation of this vector. Vector2 Vector2::operator-() const { return {-x, -y}; } -// Checks if this vector is equal to another vector. bool Vector2::operator==(const Vector2 & other) const { return x == other.x && y == other.y; } -// Checks if this vector is not equal to another vector. bool Vector2::operator!=(const Vector2 & other) const { return !(*this == other); } -} // namespace crepe -- cgit v1.2.3 From 87c74782e486647c46f9ca4d2f857094006e563c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 13 Nov 2024 12:19:56 +0100 Subject: `make format` --- src/crepe/Collider.cpp | 1 - src/crepe/Component.cpp | 1 - src/crepe/ComponentManager.cpp | 9 ++++++--- src/crepe/ComponentManager.h | 7 +++++-- src/crepe/api/Animator.cpp | 3 ++- src/crepe/api/AssetManager.h | 3 ++- src/crepe/api/BehaviorScript.cpp | 5 +++-- src/crepe/api/GameObject.cpp | 9 +++++---- src/crepe/api/GameObject.h | 6 ++++-- src/crepe/api/LoopManager.h | 5 ++--- src/crepe/api/LoopManager.hpp | 10 ++++++---- src/crepe/api/SceneManager.cpp | 10 +++++----- src/crepe/api/Script.cpp | 1 - src/crepe/api/Script.h | 1 - src/crepe/api/Transform.h | 2 +- src/crepe/api/Vector2.cpp | 1 - src/crepe/facade/SDLContext.cpp | 2 +- src/crepe/facade/Sound.cpp | 3 +-- src/crepe/facade/SoundContext.cpp | 1 - src/crepe/facade/SoundContext.h | 8 ++++---- src/crepe/system/CollisionSystem.cpp | 1 - src/crepe/system/ParticleSystem.cpp | 1 - src/crepe/system/ScriptSystem.cpp | 1 - src/crepe/system/System.cpp | 5 +---- src/example/rendering.cpp | 6 ++++-- src/example/script.cpp | 4 ++-- src/test/PhysicsTest.cpp | 11 +++++++---- src/test/ScriptTest.cpp | 9 ++++----- src/test/main.cpp | 6 +++--- 29 files changed, 68 insertions(+), 64 deletions(-) (limited to 'src/crepe/api/Vector2.cpp') diff --git a/src/crepe/Collider.cpp b/src/crepe/Collider.cpp index b408609..113ba61 100644 --- a/src/crepe/Collider.cpp +++ b/src/crepe/Collider.cpp @@ -1,4 +1,3 @@ #include "Collider.h" using namespace crepe; - diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index d11a37e..acfd35c 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -3,4 +3,3 @@ using namespace crepe; Component::Component(game_object_id_t id) : game_object_id(id) {} - diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index f6acc1a..8f8437b 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -25,10 +25,13 @@ 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 = new GameObject(*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 = new GameObject(*this, this->next_id, name, tag, + position, rotation, scale); this->objects.push_front(unique_ptr(object)); this->next_id++; return *object; } - diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index 1d67e69..75606e0 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -1,10 +1,10 @@ #pragma once +#include #include #include #include #include -#include #include "Component.h" #include "api/Vector2.h" @@ -101,7 +101,10 @@ 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 cbf415d..fcc07ef 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -9,7 +9,8 @@ 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/AssetManager.h b/src/crepe/api/AssetManager.h index dbfaef3..86a9902 100644 --- a/src/crepe/api/AssetManager.h +++ b/src/crepe/api/AssetManager.h @@ -56,7 +56,8 @@ public: * cache. */ template - std::shared_ptr cache(const std::string & file_path, bool reload = false); + std::shared_ptr cache(const std::string & file_path, + bool reload = false); }; } // namespace crepe diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index 41c144c..c5fecef 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -3,5 +3,6 @@ using namespace crepe; -BehaviorScript::BehaviorScript(game_object_id_t id, ComponentManager & mgr) : Component(id), component_manager(mgr) {} - +BehaviorScript::BehaviorScript(game_object_id_t id, ComponentManager & mgr) + : Component(id), + component_manager(mgr) {} diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index dd20b7f..e05cea1 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -1,16 +1,18 @@ #include "api/Transform.h" +#include "BehaviorScript.h" #include "GameObject.h" #include "Metadata.h" -#include "BehaviorScript.h" using namespace crepe; using namespace std; -GameObject::GameObject(ComponentManager & component_manager, game_object_id_t id, const std::string & name, +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) { + : id(id), + component_manager(component_manager) { // Add Transform and Metadata components ComponentManager & mgr = this->component_manager; @@ -37,4 +39,3 @@ BehaviorScript & GameObject::add_component() { ComponentManager & mgr = this->component_manager; return mgr.add_component(this->id, mgr); } - diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 7751fd0..e4a2539 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -2,8 +2,8 @@ #include -#include "types.h" #include "Vector2.h" +#include "types.h" namespace crepe { @@ -31,7 +31,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.h b/src/crepe/api/LoopManager.h index ef1c14f..288dca2 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -2,8 +2,8 @@ #include -#include "../system/System.h" #include "../ComponentManager.h" +#include "../system/System.h" namespace crepe { @@ -74,7 +74,7 @@ protected: T & get_system(); private: - ComponentManager component_manager; + ComponentManager component_manager{}; std::unordered_map> systems; private: @@ -85,4 +85,3 @@ private: } // namespace crepe #include "LoopManager.hpp" - diff --git a/src/crepe/api/LoopManager.hpp b/src/crepe/api/LoopManager.hpp index 20e8d1c..8fb9aa3 100644 --- a/src/crepe/api/LoopManager.hpp +++ b/src/crepe/api/LoopManager.hpp @@ -3,8 +3,8 @@ #include #include -#include "../system/System.h" #include "../Exception.h" +#include "../system/System.h" #include "LoopManager.h" @@ -13,8 +13,9 @@ namespace crepe { template T & LoopManager::get_system() { using namespace std; - static_assert(is_base_of::value, "get_system must recieve a derivative class of System"); - + static_assert(is_base_of::value, + "get_system must recieve a derivative class of System"); + const type_info & type = typeid(T); if (!this->systems.contains(type)) throw Exception("LoopManager: %s is not initialized", type.name()); @@ -29,7 +30,8 @@ T & LoopManager::get_system() { template void LoopManager::load_system() { using namespace std; - static_assert(is_base_of::value, "load_system must recieve a derivative class of System"); + static_assert(is_base_of::value, + "load_system must recieve a derivative class of System"); System * system = new T(this->component_manager); this->systems[typeid(T)] = unique_ptr(system); diff --git a/src/crepe/api/SceneManager.cpp b/src/crepe/api/SceneManager.cpp index 814b7d7..4a38787 100644 --- a/src/crepe/api/SceneManager.cpp +++ b/src/crepe/api/SceneManager.cpp @@ -16,11 +16,11 @@ void SceneManager::load_next_scene() { // next scene not set if (this->next_scene.empty()) return; - auto it = find_if(this->scenes.begin(), this->scenes.end(), - [&next_scene = this->next_scene](unique_ptr & scene) { - return scene->name == next_scene; - } - ); + auto it + = find_if(this->scenes.begin(), this->scenes.end(), + [&next_scene = this->next_scene](unique_ptr & scene) { + return scene->name == next_scene; + }); // next scene not found if (it == this->scenes.end()) return; diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 0423315..390cec7 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -1,4 +1,3 @@ #include "Script.h" using namespace crepe; - diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index c5e3cc4..837420f 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -49,4 +49,3 @@ private: } // namespace crepe #include "Script.hpp" - diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index a1ef406..902dafa 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -15,7 +15,7 @@ namespace crepe { class Transform : public Component { public: //! Translation (shift) - Vector2 position = { 0, 0 }; + Vector2 position = {0, 0}; //! Rotation, in degrees double rotation = 0; //! Multiplication factor diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp index aa391fa..7da202a 100644 --- a/src/crepe/api/Vector2.cpp +++ b/src/crepe/api/Vector2.cpp @@ -41,4 +41,3 @@ bool Vector2::operator==(const Vector2 & other) const { bool Vector2::operator!=(const Vector2 & other) const { return !(*this == other); } - diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 46230b4..236bf8c 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -159,7 +159,7 @@ SDLContext::texture_from_path(const std::string & path) { SDL_Surface * tmp = IMG_Load(path.c_str()); if (tmp == nullptr) { - tmp = IMG_Load("../asset/texture/ERROR.png"); + tmp = IMG_Load("../asset/texture/ERROR.png"); } std::unique_ptr> diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp index 3a6e1e1..b8ea71a 100644 --- a/src/crepe/facade/Sound.cpp +++ b/src/crepe/facade/Sound.cpp @@ -1,7 +1,7 @@ #include -#include "../util/log.h" #include "../Asset.h" +#include "../util/log.h" #include "Sound.h" #include "SoundContext.h" @@ -56,4 +56,3 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } - diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp index c89fb03..b5f3db3 100644 --- a/src/crepe/facade/SoundContext.cpp +++ b/src/crepe/facade/SoundContext.cpp @@ -13,4 +13,3 @@ SoundContext::~SoundContext() { dbg_trace(); engine.deinit(); } - diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h index c360fb8..8d9e396 100644 --- a/src/crepe/facade/SoundContext.h +++ b/src/crepe/facade/SoundContext.h @@ -11,10 +11,10 @@ public: SoundContext(); virtual ~SoundContext(); - SoundContext(const SoundContext &) = delete; - SoundContext(SoundContext &&) = delete; - SoundContext & operator=(const SoundContext &) = delete; - SoundContext & operator=(SoundContext &&) = delete; + SoundContext(const SoundContext &) = delete; + SoundContext(SoundContext &&) = delete; + SoundContext & operator=(const SoundContext &) = delete; + SoundContext & operator=(SoundContext &&) = delete; private: SoLoud::Soloud engine; diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 67f535a..c74ca1d 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -3,4 +3,3 @@ using namespace crepe; void CollisionSystem::update() {} - diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index 64fee4e..fe02682 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -58,4 +58,3 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter) { } } } - diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 0a87fcc..644e96e 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -44,4 +44,3 @@ forward_list> ScriptSystem::get_scripts() { return scripts; } - diff --git a/src/crepe/system/System.cpp b/src/crepe/system/System.cpp index 31b1337..201b9ad 100644 --- a/src/crepe/system/System.cpp +++ b/src/crepe/system/System.cpp @@ -4,7 +4,4 @@ using namespace crepe; -System::System(ComponentManager & mgr) : component_manager(mgr) { - dbg_trace(); -} - +System::System(ComponentManager & mgr) : component_manager(mgr) { dbg_trace(); } diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index e02f6a3..493169b 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -34,7 +34,9 @@ int main() { } { Color color(0, 0, 0, 0); - obj1.add_component(make_shared("../asset/texture/second.png"), color, FlipSettings{true, true}); + obj1.add_component( + make_shared("../asset/texture/second.png"), color, + FlipSettings{true, true}); } /* @@ -45,7 +47,7 @@ int main() { } */ - auto & sys = crepe::RenderSystem::get_instance(); + auto & sys = crepe::AssetManager::get_instance(); auto start = std::chrono::steady_clock::now(); while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) { sys.update(); diff --git a/src/example/script.cpp b/src/example/script.cpp index 4ba2b4b..69d1ce1 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -35,8 +35,8 @@ class MyScript : public Script { }; int main() { - ComponentManager component_manager {}; - ScriptSystem system { component_manager }; + ComponentManager component_manager{}; + ScriptSystem system{component_manager}; // Create game object with Transform and BehaviorScript components auto & obj = component_manager.new_object("name"); diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 5399d54..9ac99aa 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -13,7 +13,7 @@ using namespace crepe; class PhysicsTest : public ::testing::Test { public: ComponentManager component_manager; - PhysicsSystem system { component_manager }; + PhysicsSystem system{component_manager}; void SetUp() override { ComponentManager & mgr = this->component_manager; @@ -49,7 +49,8 @@ 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); @@ -87,9 +88,11 @@ 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()); diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp index ea49a35..bab9e52 100644 --- a/src/test/ScriptTest.cpp +++ b/src/test/ScriptTest.cpp @@ -5,11 +5,11 @@ #define protected public #include -#include #include -#include #include +#include #include +#include using namespace std; using namespace crepe; @@ -17,8 +17,8 @@ using namespace testing; class ScriptTest : public Test { public: - ComponentManager component_manager {}; - ScriptSystem system { component_manager }; + ComponentManager component_manager{}; + ScriptSystem system{component_manager}; class MyScript : public Script { // NOTE: default (private) visibility of init and update shouldn't cause @@ -70,4 +70,3 @@ TEST_F(ScriptTest, ListScripts) { } ASSERT_EQ(1, script_count); } - diff --git a/src/test/main.cpp b/src/test/main.cpp index 6830a01..a54d239 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -5,11 +5,11 @@ using namespace crepe; using namespace testing; -int main(int argc, char **argv) { - InitGoogleTest(&argc, argv); +int main(int argc, char ** argv) { + InitGoogleTest(&argc, argv); auto & cfg = Config::get_instance(); cfg.log.level = LogLevel::ERROR; - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } -- 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/crepe/api/Vector2.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