diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-15 20:49:37 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-15 20:49:37 +0100 |
commit | fdd5c471dffd4a204a91e8d1d70567fa56ea29a5 (patch) | |
tree | ece2c3e32261fe9b0f7ccd3aa3bd4e98f74e3b28 | |
parent | e8cd950b8ebd152d76d588d4fedc7f4c239b0835 (diff) |
`make format`
-rw-r--r-- | src/crepe/Component.h | 1 | ||||
-rw-r--r-- | src/crepe/ComponentManager.cpp | 4 | ||||
-rw-r--r-- | src/crepe/ComponentManager.h | 7 | ||||
-rw-r--r-- | src/crepe/api/Animator.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Camera.cpp | 4 | ||||
-rw-r--r-- | src/crepe/api/GameObject.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 4 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 4 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.hpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Script.hpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Vector2.cpp | 20 | ||||
-rw-r--r-- | src/crepe/facade/DB.cpp | 15 | ||||
-rw-r--r-- | src/crepe/facade/Sound.cpp | 4 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 4 | ||||
-rw-r--r-- | src/crepe/util/Log.h | 15 | ||||
-rw-r--r-- | src/crepe/util/Log.hpp | 3 | ||||
-rw-r--r-- | src/example/ecs.cpp | 12 | ||||
-rw-r--r-- | src/example/scene_manager.cpp | 21 | ||||
-rw-r--r-- | src/test/PhysicsTest.cpp | 12 |
19 files changed, 61 insertions, 89 deletions
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<std::reference_wrapper<T>> 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<reference_wrapper<Metadata>> this_metadata = mgr.get_components_by_id<Metadata>(this->id); + vector<reference_wrapper<Metadata>> this_metadata + = mgr.get_components_by_id<Metadata>(this->id); this_metadata.at(0).get().parent = parent.id; // Add own id to children list of parent's Metadata component - vector<reference_wrapper<Metadata>> parent_metadata = mgr.get_components_by_id<Metadata>(parent.id); + vector<reference_wrapper<Metadata>> parent_metadata + = mgr.get_components_by_id<Metadata>(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<ScriptSystem>(); } -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 <cassert> -#include <memory> #include <format> +#include <memory> #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<reference_wrapper<T>> all_components = this->get_components<T>(); 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<char *>(db_val.data), db_val.size}; + if (ret == 0) return {static_cast<char *>(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<Asset>(src)); } -void Sound::load(unique_ptr<Asset> res) { - this->sample.load(res->get_canonical().c_str()); -} +void Sound::load(unique_ptr<Asset> 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 <class... Args> - static void logf(const Level & level, std::format_string<Args...> fmt, - Args &&... args); + static void logf(const Level & level, std::format_string<Args...> 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<Args...> fmt, Args &&... args) { } template <class... Args> -void Log::logf(const Level & level, std::format_string<Args...> fmt, - Args &&... args) { +void Log::logf(const Level & level, std::format_string<Args...> fmt, Args &&... args) { Log::log(level, std::format(fmt, std::forward<Args>(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<reference_wrapper<Transform>> transforms - = mgr.get_components_by_id<Transform>(0); + vector<reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(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<reference_wrapper<Rigidbody>> rigidbodies - = mgr.get_components_by_id<Rigidbody>(0); + vector<reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_id<Rigidbody>(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<reference_wrapper<Rigidbody>> rigidbodies - = mgr.get_components_by_id<Rigidbody>(0); + vector<reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_id<Rigidbody>(0); Rigidbody & rigidbody = rigidbodies.front().get(); - vector<reference_wrapper<Transform>> transforms - = mgr.get_components_by_id<Transform>(0); + vector<reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(0); const Transform & transform = transforms.front().get(); ASSERT_FALSE(rigidbodies.empty()); ASSERT_FALSE(transforms.empty()); |