From cbd4b97d348c46f4f43fe59683a5e3d1bdbc500f Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sun, 1 Dec 2024 23:03:07 +0100 Subject: improved readablity of check_collision function and reset LoopManager --- src/crepe/api/LoopManager.cpp | 4 ++-- src/crepe/system/CollisionSystem.cpp | 38 +++++++++++++++++++++++------------- src/crepe/system/CollisionSystem.h | 8 +++----- 3 files changed, 29 insertions(+), 21 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index d3a7f44..35919cc 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -47,11 +47,11 @@ void LoopManager::loop() { while (game_running) { timer.update(); - //while (timer.get_lag() >= timer.get_fixed_delta_time()) { + while (timer.get_lag() >= timer.get_fixed_delta_time()) { this->process_input(); this->fixed_update(); timer.advance_fixed_update(); - //} + } this->update(); this->render(); diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index c7fbff9..e0c6d03 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -230,7 +230,17 @@ std::vectorfirst, + .rigidbody = inner_components->second, + }, + { + .collider = colliders[j], + .transform = outer_components->first, + .rigidbody = outer_components->second, + }, + type)) return; collisions_ret.emplace_back( CollisionInternal{colliders[i], inner_components->first.get(), inner_components->second.get()}, CollisionInternal{colliders[j], outer_components->first.get(), outer_components->second.get()} @@ -282,27 +292,27 @@ CollisionSystem::CollisionInternalType CollisionSystem::check_collider_type(cons } } -bool CollisionSystem::check_collision(const collider_variant& collider1,std::pair, std::reference_wrapper> components1,const collider_variant& collider2,std::pair, std::reference_wrapper> components2, CollisionInternalType type){ +bool CollisionSystem::check_collision(const CollisionInternal& first_info,const CollisionInternal& second_info, CollisionInternalType type){ switch (type) { case CollisionInternalType::BOX_BOX: { - const BoxCollider & box_collider1 = std::get>(collider1); - const BoxCollider & box_collider2 = std::get>(collider2); - return check_box_box_collision(box_collider1,box_collider2,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); + const BoxCollider & box_collider1 = std::get>(first_info.collider); + const BoxCollider & box_collider2 = std::get>(second_info.collider); + return check_box_box_collision(box_collider1,box_collider2,first_info.transform,second_info.transform,second_info.rigidbody,second_info.rigidbody); } case CollisionInternalType::BOX_CIRCLE: { - const BoxCollider & box_collider = std::get>(collider1); - const CircleCollider & circle_collider = std::get>(collider2); - return check_box_circle_collision(box_collider,circle_collider,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); + const BoxCollider & box_collider = std::get>(first_info.collider); + const CircleCollider & circle_collider = std::get>(second_info.collider); + return check_box_circle_collision(box_collider,circle_collider,first_info.transform,second_info.transform,second_info.rigidbody,second_info.rigidbody); } case CollisionInternalType::CIRCLE_CIRCLE: { - const CircleCollider & circle_collider1 = std::get>(collider1); - const CircleCollider & circle_collider2 = std::get>(collider2); - return check_circle_circle_collision(circle_collider1,circle_collider2,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); + const CircleCollider & circle_collider1 = std::get>(first_info.collider); + const CircleCollider & circle_collider2 = std::get>(second_info.collider); + return check_circle_circle_collision(circle_collider1,circle_collider2,first_info.transform,second_info.transform,second_info.rigidbody,second_info.rigidbody); } case CollisionInternalType::CIRCLE_BOX: { - const CircleCollider & circle_collider = std::get>(collider1); - const BoxCollider & box_collider = std::get>(collider2); - return check_box_circle_collision(box_collider,circle_collider,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); + const CircleCollider & circle_collider = std::get>(first_info.collider); + const BoxCollider & box_collider = std::get>(second_info.collider); + return check_box_circle_collision(box_collider,circle_collider,first_info.transform,second_info.transform,second_info.rigidbody,second_info.rigidbody); } } return false; diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 39ee83d..ea8c1e1 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -177,14 +177,12 @@ private: * * Calls the appropriate collision detection function based on the collider types. * - * \param collider1 The first collider. - * \param components1 Transform and Rigidbody of the first object. - * \param collider2 The second collider. - * \param components2 Transform and Rigidbody of the second object. + * \param first_info Collision data for the first collider. + * \param second_info Collision data for the second collider. * \param type The type of collider pair. * \return True if a collision is detected, otherwise false. */ - bool check_collision(const collider_variant& collider1,std::pair, std::reference_wrapper> components1,const collider_variant& collider2,std::pair, std::reference_wrapper> components2,CollisionSystem::CollisionInternalType type); + bool check_collision(const CollisionInternal& first_info,const CollisionInternal& second_info, CollisionInternalType type); /** * \brief Retrieves the active Transform and Rigidbody components for a given game object. -- cgit v1.2.3