diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/Collider.h | 8 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 34 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 3 |
3 files changed, 19 insertions, 26 deletions
diff --git a/src/crepe/Collider.h b/src/crepe/Collider.h index 78e48cf..0157324 100644 --- a/src/crepe/Collider.h +++ b/src/crepe/Collider.h @@ -10,14 +10,6 @@ class Collider : public Component { public: Collider(game_object_id_t id, Vector2 offset); -protected: - // Friend class allowing access to copy constructor - friend class CollisionSystem; - - // Copy Constructor (Restricted to CollisionSystem) - Collider(const Collider &other) - : Component(other.game_object_id), offset(other.offset) {} - public: //! Offset of the collider relative to rigidbody position Vector2 offset; diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index b23e779..9ca8b3a 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -42,12 +42,12 @@ void CollisionSystem::collision_handler(CollidedInfoStor& data1,CollidedInfoStor Vector2 move_back; // Check collision type and get values for handler - if (std::holds_alternative<BoxCollider>(data1.collider)) { - if (std::holds_alternative<BoxCollider>(data2.collider)) { + if (std::holds_alternative<std::reference_wrapper<BoxCollider>>(data1.collider)) { + if (std::holds_alternative<std::reference_wrapper<BoxCollider>>(data2.collider)) { // Get colliders from variant to be used to determine collision handler info - const BoxCollider& box_collider1 = std::get<BoxCollider>(data1.collider); - const BoxCollider& box_collider2 = std::get<BoxCollider>(data2.collider); + const BoxCollider& box_collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider).get(); + const BoxCollider& box_collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider).get(); collider1 = &box_collider1; collider2 = &box_collider2; @@ -62,24 +62,24 @@ void CollisionSystem::collision_handler(CollidedInfoStor& data1,CollidedInfoStor } else { // TODO: calcualte Box - Circle collision info - const BoxCollider& box_collider = std::get<BoxCollider>(data1.collider); - const CircleCollider& circle_collider = std::get<CircleCollider>(data2.collider); + const BoxCollider& box_collider = std::get<std::reference_wrapper<BoxCollider>>(data1.collider).get(); + const CircleCollider& circle_collider = std::get<std::reference_wrapper<CircleCollider>>(data2.collider).get(); collider1 = &box_collider; collider2 = &circle_collider; } } else { - if (std::holds_alternative<CircleCollider>(data2.collider)) { + if (std::holds_alternative<std::reference_wrapper<CircleCollider>>(data2.collider)) { // TODO: calcualte Circle - Circle collision info - const CircleCollider& circle_collider1 = std::get<CircleCollider>(data1.collider); - const CircleCollider& circle_collider2 = std::get<CircleCollider>(data2.collider); + const CircleCollider& circle_collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider).get(); + const CircleCollider& circle_collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider).get(); collider1 = &circle_collider1; collider2 = &circle_collider2; } else { // TODO: calcualte Circle - Box collision info - const CircleCollider& circle_collider = std::get<CircleCollider>(data1.collider); - const BoxCollider& box_collider = std::get<BoxCollider>(data2.collider); + const CircleCollider& circle_collider = std::get<std::reference_wrapper<CircleCollider>>(data1.collider); + const BoxCollider& box_collider = std::get<std::reference_wrapper<BoxCollider>>(data2.collider); collider1 = &circle_collider; collider2 = &box_collider; } @@ -222,8 +222,8 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide // Check collision if (check_box_box_collision(boxcolliders[i], boxcolliders[j], transform1, transform2, rigidbody1, rigidbody2)) { collisions_ret.emplace_back(std::make_pair( - CollidedInfoStor{boxcolliders[i], transform1, rigidbody1}, - CollidedInfoStor{boxcolliders[j], transform2, rigidbody2} + CollidedInfoStor{boxcolliders[i].get(), transform1, rigidbody1}, + CollidedInfoStor{boxcolliders[j].get(), transform2, rigidbody2} )); } } @@ -245,8 +245,8 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide if (check_box_circle_collision(boxcolliders[i], circlecolliders[j], transform1, transform2, rigidbody1, rigidbody2)) { collisions_ret.emplace_back(std::make_pair( - CollidedInfoStor{boxcolliders[i], transform1, rigidbody1}, - CollidedInfoStor{circlecolliders[j], transform2, rigidbody2} + CollidedInfoStor{boxcolliders[i].get(), transform1, rigidbody1}, + CollidedInfoStor{circlecolliders[j].get(), transform2, rigidbody2} )); } } @@ -276,8 +276,8 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide // Check collision if (check_circle_circle_collision(circlecolliders[i], circlecolliders[j], transform1, transform2, rigidbody1, rigidbody2)) { collisions_ret.emplace_back(std::make_pair( - CollidedInfoStor{circlecolliders[i], transform1, rigidbody1}, - CollidedInfoStor{circlecolliders[j], transform2, rigidbody2} + CollidedInfoStor{circlecolliders[i].get(), transform1, rigidbody1}, + CollidedInfoStor{circlecolliders[j].get(), transform2, rigidbody2} )); } } diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index d94f6bc..69d1d23 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -22,7 +22,8 @@ public: private: //! A variant type that can hold either a BoxCollider or a CircleCollider. - using collider_stor = std::variant<BoxCollider, CircleCollider>; + // using collider_stor = std::variant<BoxCollider, CircleCollider>; + using collider_stor = std::variant<std::reference_wrapper<BoxCollider>, std::reference_wrapper<CircleCollider>>; /** * \brief A structure to store the collision data of a single collider. |