diff options
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 4 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 38 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 8 |
3 files changed, 29 insertions, 21 deletions
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::vector<std::pair<CollisionSystem::CollisionInternal,CollisionSystem::Collis auto outer_components = get_active_transform_and_rigidbody(outer_collider_ref.get().game_object_id); if (!outer_components) return; CollisionInternalType type = check_collider_type(colliders[i],colliders[j]); - if(!check_collision(colliders[i],*inner_components,colliders[j],*outer_components,type)) return; + if(!check_collision({ + .collider = colliders[i], + .transform = inner_components->first, + .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<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_variant& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> 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<std::reference_wrapper<BoxCollider>>(collider1); - const BoxCollider & box_collider2 = std::get<std::reference_wrapper<BoxCollider>>(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<std::reference_wrapper<BoxCollider>>(first_info.collider); + const BoxCollider & box_collider2 = std::get<std::reference_wrapper<BoxCollider>>(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<std::reference_wrapper<BoxCollider>>(collider1); - const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(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<std::reference_wrapper<BoxCollider>>(first_info.collider); + const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(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<std::reference_wrapper<CircleCollider>>(collider1); - const CircleCollider & circle_collider2 = std::get<std::reference_wrapper<CircleCollider>>(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<std::reference_wrapper<CircleCollider>>(first_info.collider); + const CircleCollider & circle_collider2 = std::get<std::reference_wrapper<CircleCollider>>(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<std::reference_wrapper<CircleCollider>>(collider1); - const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(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<std::reference_wrapper<CircleCollider>>(first_info.collider); + const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(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<Transform>, std::reference_wrapper<Rigidbody>> components1,const collider_variant& collider2,std::pair<std::reference_wrapper<Transform>, std::reference_wrapper<Rigidbody>> 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. |