From 61148c757a1f742ff09e40e5347e74e638c7371c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 22 Dec 2024 12:32:22 +0100 Subject: update clang-format options --- src/crepe/system/AISystem.cpp | 21 +++++----- src/crepe/system/CollisionSystem.cpp | 81 ++++++++++++++++++++---------------- src/crepe/system/CollisionSystem.h | 40 +++++++++++------- src/crepe/system/InputSystem.cpp | 36 +++++++++------- src/crepe/system/InputSystem.h | 21 ++++++---- src/crepe/system/ParticleSystem.cpp | 17 ++++---- src/crepe/system/RenderSystem.cpp | 6 +-- src/crepe/system/ScriptSystem.cpp | 5 ++- 8 files changed, 132 insertions(+), 95 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp index 0f35010..94445c7 100644 --- a/src/crepe/system/AISystem.cpp +++ b/src/crepe/system/AISystem.cpp @@ -28,7 +28,8 @@ void AISystem::fixed_update() { = mgr.get_components_by_id(ai.game_object_id); if (rigidbodies.empty()) { throw std::runtime_error( - "AI component must be attached to a GameObject with a Rigidbody component"); + "AI component must be attached to a GameObject with a Rigidbody component" + ); } Rigidbody & rigidbody = rigidbodies.front().get(); if (!rigidbody.active) { @@ -110,8 +111,8 @@ bool AISystem::accumulate_force(const AI & ai, vec2 & running_total, vec2 & forc return true; } -vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity vec2 desired_velocity = ai.seek_target - transform.position; desired_velocity.normalize(); @@ -120,12 +121,12 @@ vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity if the entity is within the panic distance vec2 desired_velocity = transform.position - ai.flee_target; if (desired_velocity.length_squared() > ai.square_flee_panic_distance) { - return vec2{0, 0}; + return vec2 {0, 0}; } desired_velocity.normalize(); desired_velocity *= rigidbody.data.max_linear_velocity; @@ -133,8 +134,8 @@ vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity (taking into account the deceleration rate) vec2 to_target = ai.arrive_target - transform.position; float distance = to_target.length(); @@ -150,12 +151,12 @@ vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } - return vec2{0, 0}; + return vec2 {0, 0}; } vec2 AISystem::path_follow(AI & ai, const Rigidbody & rigidbody, const Transform & transform) { if (ai.path.empty()) { - return vec2{0, 0}; + return vec2 {0, 0}; } // Get the target node diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 654d4c6..571ac70 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -50,9 +50,11 @@ void CollisionSystem::fixed_update() { for (BoxCollider & boxcollider : boxcolliders) { if (boxcollider.game_object_id != id) continue; if (!boxcollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{boxcollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {boxcollider}, + .info = {transform, rigidbody, metadata}} + ); } // Check if the circlecollider is active and has the same id as the rigidbody. RefVector circlecolliders @@ -60,9 +62,11 @@ void CollisionSystem::fixed_update() { for (CircleCollider & circlecollider : circlecolliders) { if (circlecollider.game_object_id != id) continue; if (!circlecollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{circlecollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {circlecollider}, + .info = {transform, rigidbody, metadata}} + ); } } @@ -110,8 +114,9 @@ CollisionSystem::gather_collisions(std::vector & colliders) { return collisions_ret; } -bool CollisionSystem::should_collide(const CollisionInternal & self, - const CollisionInternal & other) const { +bool CollisionSystem::should_collide( + const CollisionInternal & self, const CollisionInternal & other +) const { const Rigidbody::Data & self_rigidbody = self.info.rigidbody.data; const Rigidbody::Data & other_rigidbody = other.info.rigidbody.data; @@ -133,9 +138,9 @@ bool CollisionSystem::should_collide(const CollisionInternal & self, return false; } -CollisionSystem::CollisionInternalType -CollisionSystem::get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const { +CollisionSystem::CollisionInternalType CollisionSystem::get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 +) const { if (std::holds_alternative>(collider1)) { if (std::holds_alternative>(collider2)) { return CollisionInternalType::CIRCLE_CIRCLE; @@ -151,8 +156,9 @@ CollisionSystem::get_collider_type(const collider_variant & collider1, } } -bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionInternal & other, - const CollisionInternalType & type) { +bool CollisionSystem::detect_collision( + CollisionInternal & self, CollisionInternal & other, const CollisionInternalType & type +) { vec2 resolution; switch (type) { case CollisionInternalType::BOX_BOX: { @@ -177,10 +183,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from box-circle collision detection resolution = this->get_box_circle_detection(BOX1, CIRCLE2); // If no collision (NaN values), return false @@ -195,10 +202,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from circle-circle collision detection resolution = this->get_circle_circle_detection(CIRCLE1, CIRCLE2); // If no collision (NaN values), return false @@ -239,9 +247,10 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern return true; } -vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const { - vec2 resolution{NAN, NAN}; +vec2 CollisionSystem::get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 +) const { + vec2 resolution {NAN, NAN}; // Get current positions of colliders vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset); vec2 pos2 = AbsolutePosition::get_position(box2.transform, box2.collider.offset); @@ -282,8 +291,9 @@ vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, return resolution; } -vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, - const CircleColliderInternal & circle) const { +vec2 CollisionSystem::get_box_circle_detection( + const BoxColliderInternal & box, const CircleColliderInternal & circle +) const { /// Get current positions of colliders vec2 box_pos = AbsolutePosition::get_position(box.transform, box.collider.offset); vec2 circle_pos = AbsolutePosition::get_position(circle.transform, circle.collider.offset); @@ -324,14 +334,15 @@ vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, float penetration_depth = scaled_circle_radius - distance; // Compute the resolution vector - return vec2{collision_normal * penetration_depth}; + return vec2 {collision_normal * penetration_depth}; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; } vec2 CollisionSystem::get_circle_circle_detection( - const CircleColliderInternal & circle1, const CircleColliderInternal & circle2) const { + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 +) const { // Get current positions of colliders vec2 final_position1 = AbsolutePosition::get_position(circle1.transform, circle1.collider.offset); @@ -371,7 +382,7 @@ vec2 CollisionSystem::get_circle_circle_detection( return resolution; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; ; } @@ -402,17 +413,17 @@ CollisionSystem::resolution_correction(vec2 & resolution, const Rigidbody::Data return resolution_direction; } -CollisionSystem::CollisionInfo -CollisionSystem::get_collision_info(const CollisionInternal & in_self, - const CollisionInternal & in_other) const { +CollisionSystem::CollisionInfo CollisionSystem::get_collision_info( + const CollisionInternal & in_self, const CollisionInternal & in_other +) const { - crepe::CollisionSystem::ColliderInfo self{ + crepe::CollisionSystem::ColliderInfo self { .transform = in_self.info.transform, .rigidbody = in_self.info.rigidbody, .metadata = in_self.info.metadata, }; - crepe::CollisionSystem::ColliderInfo other{ + crepe::CollisionSystem::ColliderInfo other { .transform = in_other.info.transform, .rigidbody = in_other.info.rigidbody, .metadata = in_other.info.metadata, diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 3fb9723..ff2d35f 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -60,8 +60,8 @@ public: private: //! A variant type that can hold either a BoxCollider or a CircleCollider. - using collider_variant = std::variant, - std::reference_wrapper>; + using collider_variant = std::variant< + std::reference_wrapper, std::reference_wrapper>; //! Enum representing the types of collider pairs for collision detection. enum class CollisionInternalType { @@ -114,8 +114,9 @@ private: * \param collider2 Second collider variant (BoxCollider or CircleCollider). * \return The combined type of the two colliders. */ - CollisionInternalType get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const; + CollisionInternalType get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 + ) const; private: /** @@ -128,8 +129,8 @@ private: * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. */ - CollisionInfo get_collision_info(const CollisionInternal & data1, - const CollisionInternal & data2) const; + CollisionInfo + get_collision_info(const CollisionInternal & data1, const CollisionInternal & data2) const; /** * \brief Corrects the collision resolution vector and determines its direction. @@ -221,8 +222,10 @@ private: * \param other_metadata Rigidbody of second object * \return Returns true if there is at least one comparison found. */ - bool should_collide(const CollisionInternal & self, - const CollisionInternal & other) const; //done + bool should_collide( + const CollisionInternal & self, + const CollisionInternal & other + ) const; //done /** * \brief Checks for collision between two colliders. @@ -236,8 +239,10 @@ private: * \param type The type of collider pair. * \return True if a collision is detected, otherwise false. */ - bool detect_collision(CollisionInternal & first_info, CollisionInternal & second_info, - const CollisionInternalType & type); + bool detect_collision( + CollisionInternal & first_info, CollisionInternal & second_info, + const CollisionInternalType & type + ); /** * \brief Detects collisions between two BoxColliders. @@ -250,8 +255,9 @@ private: * \param box2 Information about the second BoxCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const; + vec2 get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 + ) const; /** * \brief Check collision for box on circle collider @@ -264,8 +270,9 @@ private: * \param circle2 Information about the circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_circle_detection(const BoxColliderInternal & box1, - const CircleColliderInternal & circle2) const; + vec2 get_box_circle_detection( + const BoxColliderInternal & box1, const CircleColliderInternal & circle2 + ) const; /** * \brief Check collision for circle on circle collider @@ -278,8 +285,9 @@ private: * \param circle2 Information about the second circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_circle_circle_detection(const CircleColliderInternal & circle1, - const CircleColliderInternal & circle2) const; + vec2 get_circle_circle_detection( + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 + ) const; }; /** diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 8e9f763..b4a0633 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -44,8 +44,9 @@ void InputSystem::fixed_update() { } } -void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camera_origin, - const Camera & current_cam) { +void InputSystem::handle_mouse_event( + const EventData & event, const vec2 & camera_origin, const Camera & current_cam +) { EventManager & event_mgr = this->mediator.event_manager; vec2 adjusted_mouse; adjusted_mouse.x = event.data.mouse_data.mouse_position.x + camera_origin.x; @@ -82,8 +83,9 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer .mouse_pos = adjusted_mouse, .button = event.data.mouse_data.mouse_button, }); - this->handle_click(event.data.mouse_data.mouse_button, adjusted_mouse, - current_cam); + this->handle_click( + event.data.mouse_data.mouse_button, adjusted_mouse, current_cam + ); } break; } @@ -115,7 +117,8 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { case EventType::KEY_DOWN: event_mgr.queue_event( - {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key}); + {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key} + ); break; case EventType::KEY_UP: event_mgr.queue_event({.key = event.data.key_data.key}); @@ -128,11 +131,13 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { break; case EventType::WINDOW_RESIZE: event_mgr.queue_event( - WindowResizeEvent{.dimensions = event.data.window_data.resize_dimension}); + WindowResizeEvent {.dimensions = event.data.window_data.resize_dimension} + ); break; case EventType::WINDOW_MOVE: event_mgr.queue_event( - {.delta_move = event.data.window_data.move_delta}); + {.delta_move = event.data.window_data.move_delta} + ); break; case EventType::WINDOW_MINIMIZE: event_mgr.queue_event({}); @@ -151,8 +156,9 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { } } -void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos, - const Camera & current_cam) { +void InputSystem::handle_move( + const EventData & event_data, const vec2 & mouse_pos, const Camera & current_cam +) { ComponentManager & mgr = this->mediator.component_manager; EventManager & event_mgr = this->mediator.event_manager; const RefVector