diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-16 21:22:35 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-16 21:22:35 +0100 |
commit | 5bece30f9ad495a0e82097b2c5668e979856fb69 (patch) | |
tree | 82d897004f17dfe06f6453ebc9f244ed0d4d53a7 | |
parent | ea7beae5974838b6e1727c539b0899ad157bc1fb (diff) |
make format
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 3 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 123 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 2 | ||||
-rw-r--r-- | src/crepe/system/ParticleSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/util/AbsoluutPosition.cpp | 3 | ||||
-rw-r--r-- | src/crepe/util/AbsoluutPosition.h | 5 | ||||
-rw-r--r-- | src/example/game.cpp | 2 | ||||
-rw-r--r-- | src/test/CollisionTest.cpp | 5 | ||||
-rw-r--r-- | src/test/Profiling.cpp | 26 |
10 files changed, 90 insertions, 83 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index ee7d149..a1a6f97 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -235,8 +235,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { } size *= cam_aux_data.render_scale * ctx.img_scale * data.scale_offset; - vec2 screen_pos = (ctx.pos - cam_aux_data.cam_pos - + (cam_aux_data.zoomed_viewport) / 2) + vec2 screen_pos = (ctx.pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) * cam_aux_data.render_scale - size / 2 + cam_aux_data.bar_size; diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 294e7b3..9604543 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -15,8 +15,8 @@ #include "api/Rigidbody.h" #include "api/Transform.h" #include "api/Vector2.h" -#include "util/OptionalRef.h" #include "util/AbsoluutPosition.h" +#include "util/OptionalRef.h" #include "Collider.h" #include "CollisionSystem.h" @@ -139,9 +139,11 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal = std::get<std::reference_wrapper<BoxCollider>>(data1.collider); const BoxCollider & collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider); - - vec2 collider_pos1 = AbsoluutPosition::get_position(data1.transform,collider1.offset); - vec2 collider_pos2 = AbsoluutPosition::get_position(data2.transform,collider2.offset); + + vec2 collider_pos1 + = AbsoluutPosition::get_position(data1.transform, collider1.offset); + vec2 collider_pos2 + = AbsoluutPosition::get_position(data2.transform, collider2.offset); resolution = this->get_box_box_resolution(collider1, collider2, collider_pos1, collider_pos2); break; @@ -151,8 +153,10 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal = std::get<std::reference_wrapper<BoxCollider>>(data1.collider); const CircleCollider & collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider); - vec2 collider_pos1 = AbsoluutPosition::get_position(data1.transform,collider1.offset); - vec2 collider_pos2 = AbsoluutPosition::get_position(data2.transform,collider2.offset); + vec2 collider_pos1 + = AbsoluutPosition::get_position(data1.transform, collider1.offset); + vec2 collider_pos2 + = AbsoluutPosition::get_position(data2.transform, collider2.offset); resolution = -this->get_circle_box_resolution(collider2, collider1, collider_pos2, collider_pos1); break; @@ -162,8 +166,10 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal = std::get<std::reference_wrapper<CircleCollider>>(data1.collider); const CircleCollider & collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider); - vec2 collider_pos1 = AbsoluutPosition::get_position(data1.transform,collider1.offset); - vec2 collider_pos2 = AbsoluutPosition::get_position(data2.transform,collider2.offset); + vec2 collider_pos1 + = AbsoluutPosition::get_position(data1.transform, collider1.offset); + vec2 collider_pos2 + = AbsoluutPosition::get_position(data2.transform, collider2.offset); resolution = this->get_circle_circle_resolution(collider1, collider2, collider_pos1, collider_pos2); break; @@ -173,8 +179,10 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal = std::get<std::reference_wrapper<CircleCollider>>(data1.collider); const BoxCollider & collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider); - vec2 collider_pos1 = AbsoluutPosition::get_position(data1.transform,collider1.offset); - vec2 collider_pos2 = AbsoluutPosition::get_position(data2.transform,collider2.offset); + vec2 collider_pos1 + = AbsoluutPosition::get_position(data1.transform, collider1.offset); + vec2 collider_pos2 + = AbsoluutPosition::get_position(data2.transform, collider2.offset); resolution = this->get_circle_box_resolution(collider1, collider2, collider_pos1, collider_pos2); break; @@ -297,58 +305,67 @@ vec2 CollisionSystem::get_circle_box_resolution(const CircleCollider & circle_co void CollisionSystem::determine_collision_handler(CollisionInfo & info) { // Inverted collision info - CollisionInfo inverted = { - .this_collider = info.other_collider, - .this_transform = info.other_transform, - .this_rigidbody = info.other_rigidbody, - .this_metadata = info.other_metadata, - .other_collider = info.this_collider, - .other_transform = info.this_transform, - .other_rigidbody = info.this_rigidbody, - .other_metadata = info.this_metadata, - .resolution = -info.resolution, - .resolution_direction = info.resolution_direction, - }; + CollisionInfo inverted = { + .this_collider = info.other_collider, + .this_transform = info.other_transform, + .this_rigidbody = info.other_rigidbody, + .this_metadata = info.other_metadata, + .other_collider = info.this_collider, + .other_transform = info.this_transform, + .other_rigidbody = info.this_rigidbody, + .other_metadata = info.this_metadata, + .resolution = -info.resolution, + .resolution_direction = info.resolution_direction, + }; // If both objects are static skip handle call collision script - if(info.this_rigidbody.data.body_type == Rigidbody::BodyType::STATIC && info.other_rigidbody.data.body_type == Rigidbody::BodyType::STATIC) return; + if (info.this_rigidbody.data.body_type == Rigidbody::BodyType::STATIC + && info.other_rigidbody.data.body_type == Rigidbody::BodyType::STATIC) + return; // First body is not dynamic - if(info.this_rigidbody.data.body_type != Rigidbody::BodyType::DYNAMIC) - { - bool static_collision = info.this_rigidbody.data.body_type == Rigidbody::BodyType::STATIC && info.other_rigidbody.data.body_type == Rigidbody::BodyType::DYNAMIC; - bool kinematic_collision = info.this_rigidbody.data.body_type == Rigidbody::BodyType::KINEMATIC && info.other_rigidbody.data.body_type == Rigidbody::BodyType::DYNAMIC && info.this_rigidbody.data.kinematic_collision; - - - if(static_collision || kinematic_collision){ + if (info.this_rigidbody.data.body_type != Rigidbody::BodyType::DYNAMIC) { + bool static_collision + = info.this_rigidbody.data.body_type == Rigidbody::BodyType::STATIC + && info.other_rigidbody.data.body_type == Rigidbody::BodyType::DYNAMIC; + bool kinematic_collision + = info.this_rigidbody.data.body_type == Rigidbody::BodyType::KINEMATIC + && info.other_rigidbody.data.body_type == Rigidbody::BodyType::DYNAMIC + && info.this_rigidbody.data.kinematic_collision; + + if (static_collision || kinematic_collision) { // Static collision this->static_collision_handler(inverted); }; // Call scripts - this->call_collision_events(inverted,info); + this->call_collision_events(inverted, info); return; } // Second body is not dynamic - if(info.other_rigidbody.data.body_type != Rigidbody::BodyType::DYNAMIC) - { - bool static_collision = info.other_rigidbody.data.body_type == Rigidbody::BodyType::STATIC; - bool kinematic_collision = info.other_rigidbody.data.body_type == Rigidbody::BodyType::KINEMATIC && info.other_rigidbody.data.kinematic_collision; - if(static_collision || kinematic_collision) this->static_collision_handler(info); - this->call_collision_events(info,inverted); + if (info.other_rigidbody.data.body_type != Rigidbody::BodyType::DYNAMIC) { + bool static_collision + = info.other_rigidbody.data.body_type == Rigidbody::BodyType::STATIC; + bool kinematic_collision + = info.other_rigidbody.data.body_type == Rigidbody::BodyType::KINEMATIC + && info.other_rigidbody.data.kinematic_collision; + if (static_collision || kinematic_collision) this->static_collision_handler(info); + this->call_collision_events(info, inverted); return; } //dynamic this->dynamic_collision_handler(info); - this->call_collision_events(info,inverted); + this->call_collision_events(info, inverted); } -void CollisionSystem::call_collision_events(CollisionInfo & info,CollisionInfo & info_inverted){ +void CollisionSystem::call_collision_events(CollisionInfo & info, + CollisionInfo & info_inverted) { CollisionEvent data(info); CollisionEvent data_inverted(info_inverted); EventManager & emgr = this->mediator.event_manager; emgr.trigger_event<CollisionEvent>(data, info.this_collider.game_object_id); - emgr.trigger_event<CollisionEvent>(data_inverted, info_inverted.this_collider.game_object_id); + emgr.trigger_event<CollisionEvent>(data_inverted, + info_inverted.this_collider.game_object_id); } void CollisionSystem::static_collision_handler(CollisionInfo & info) { @@ -400,9 +417,9 @@ void CollisionSystem::static_collision_handler(CollisionInfo & info) { } } -void CollisionSystem::dynamic_collision_handler(CollisionInfo & info){ - info.this_transform.position += info.resolution/2; - info.other_transform.position += -(info.resolution/2); +void CollisionSystem::dynamic_collision_handler(CollisionInfo & info) { + info.this_transform.position += info.resolution / 2; + info.other_transform.position += -(info.resolution / 2); switch (info.resolution_direction) { case Direction::BOTH: @@ -410,8 +427,7 @@ void CollisionSystem::dynamic_collision_handler(CollisionInfo & info){ info.this_rigidbody.data.linear_velocity = -info.this_rigidbody.data.linear_velocity * info.this_rigidbody.data.elastisity_coefficient; - } - else { + } else { info.this_rigidbody.data.linear_velocity = {0, 0}; } @@ -419,8 +435,7 @@ void CollisionSystem::dynamic_collision_handler(CollisionInfo & info){ info.other_rigidbody.data.linear_velocity = -info.other_rigidbody.data.linear_velocity * info.other_rigidbody.data.elastisity_coefficient; - } - else { + } else { info.other_rigidbody.data.linear_velocity = {0, 0}; } break; @@ -602,8 +617,8 @@ bool CollisionSystem::get_box_box_collision(const BoxCollider & box1, const BoxC const Rigidbody & rigidbody1, const Rigidbody & rigidbody2) const { // Get current positions of colliders - vec2 final_position1 = AbsoluutPosition::get_position(transform1,box1.offset); - vec2 final_position2 = AbsoluutPosition::get_position(transform2,box2.offset); + vec2 final_position1 = AbsoluutPosition::get_position(transform1, box1.offset); + vec2 final_position2 = AbsoluutPosition::get_position(transform2, box2.offset); // Scale dimensions vec2 scaled_box1 = box1.dimensions * transform1.scale; @@ -629,8 +644,8 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1, const Rigidbody & rigidbody1, const Rigidbody & rigidbody2) const { // Get current positions of colliders - vec2 final_position1 = AbsoluutPosition::get_position(transform1,box1.offset); - vec2 final_position2 = AbsoluutPosition::get_position(transform2,circle2.offset); + vec2 final_position1 = AbsoluutPosition::get_position(transform1, box1.offset); + vec2 final_position2 = AbsoluutPosition::get_position(transform2, circle2.offset); // Scale dimensions vec2 scaled_box = box1.dimensions * transform1.scale; @@ -662,8 +677,8 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 const Rigidbody & rigidbody1, const Rigidbody & rigidbody2) const { // Get current positions of colliders - vec2 final_position1 = AbsoluutPosition::get_position(transform1,circle1.offset); - vec2 final_position2 = AbsoluutPosition::get_position(transform2,circle2.offset); + vec2 final_position1 = AbsoluutPosition::get_position(transform1, circle1.offset); + vec2 final_position2 = AbsoluutPosition::get_position(transform2, circle2.offset); // Scale dimensions float scaled_circle1 = circle1.radius * transform1.scale; @@ -679,5 +694,3 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 // Check if the distance between the centers is less than or equal to the sum of the radii return distance_squared < radius_sum * radius_sum; } - - diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index b802426..23752e1 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -188,7 +188,7 @@ private: * * \param info Collision information containing data about both colliders. */ - void call_collision_events(CollisionInfo & info,CollisionInfo & info_inverted); + void call_collision_events(CollisionInfo & info, CollisionInfo & info_inverted); /** * \brief Handles collisions involving static objects. diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index fb6cfd7..56f1dfd 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -48,7 +48,7 @@ void ParticleSystem::update() { void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & transform) { constexpr float DEG_TO_RAD = M_PI / 180.0; - + vec2 initial_position = AbsoluutPosition::get_position(transform, emitter.data.offset); float random_angle = this->generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index fcb52c3..c0717fc 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -106,7 +106,7 @@ void RenderSystem::render_normal(const Sprite & sprite, const Transform & tm) { SDLContext & ctx = this->mediator.sdl_context; ResourceManager & resource_manager = this->mediator.resource_manager; const Texture & res = resource_manager.get<Texture>(sprite.source); - vec2 pos = AbsoluutPosition::get_position(tm,sprite.data.position_offset); + vec2 pos = AbsoluutPosition::get_position(tm, sprite.data.position_offset); ctx.draw(SDLContext::RenderContext{ .sprite = sprite, .texture = res, diff --git a/src/crepe/util/AbsoluutPosition.cpp b/src/crepe/util/AbsoluutPosition.cpp index 8be625e..296cc09 100644 --- a/src/crepe/util/AbsoluutPosition.cpp +++ b/src/crepe/util/AbsoluutPosition.cpp @@ -2,7 +2,7 @@ using namespace crepe; -vec2 AbsoluutPosition::get_position(const Transform & transform,const vec2 & offset) { +vec2 AbsoluutPosition::get_position(const Transform & transform, const vec2 & offset) { // Get the rotation in radians float radians1 = transform.rotation * (M_PI / 180.0); @@ -18,4 +18,3 @@ vec2 AbsoluutPosition::get_position(const Transform & transform,const vec2 & off // Final positions considering scaling and rotation return (transform.position + vec2(rotated_total_offset_x1, rotated_total_offset_y1)); } - diff --git a/src/crepe/util/AbsoluutPosition.h b/src/crepe/util/AbsoluutPosition.h index 4441f90..30a7f93 100644 --- a/src/crepe/util/AbsoluutPosition.h +++ b/src/crepe/util/AbsoluutPosition.h @@ -1,17 +1,14 @@ #pragma once - #include "api/Transform.h" #include "types.h" namespace crepe { - class AbsoluutPosition { public: - static vec2 get_position(const Transform & transform,const vec2 & offset); - + static vec2 get_position(const Transform & transform, const vec2 & offset); }; } // namespace crepe diff --git a/src/example/game.cpp b/src/example/game.cpp index b30166e..01a509f 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -238,7 +238,7 @@ public: .sorting_in_layer = 2, .order_in_layer = 2, .size = {20, 20}, - .position_offset = {0,-10}, + .position_offset = {0, -10}, }); //add circle with cirlcecollider deactiveated diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index 43bf77d..3cb7f33 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -290,9 +290,8 @@ TEST_F(CollisionTest, collision_box_box_static_both) { EXPECT_EQ(ev.info.resolution.y, 10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; - script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { - collision_happend = true; - }; + script_object2_ref->test_fn + = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); tf.position = {50, 30}; diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index 1585061..16736b8 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -219,19 +219,19 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) { .order_in_layer = 1, .size = {.y = 500}, }); - auto & test = gameobject.add_component<ParticleEmitter>(test_sprite,ParticleEmitter::Data{ - .max_particles = 10, - .emission_rate = 100, - .end_lifespan = 100000, - .boundary{ - .width = 1000, - .height = 1000, - .offset = vec2{0, 0}, - .reset_on_exit = false, - }, - - } - ); + auto & test = gameobject.add_component<ParticleEmitter>( + test_sprite, ParticleEmitter::Data{ + .max_particles = 10, + .emission_rate = 100, + .end_lifespan = 100000, + .boundary{ + .width = 1000, + .height = 1000, + .offset = vec2{0, 0}, + .reset_on_exit = false, + }, + + }); } render_sys.update(); this->game_object_count++; |