Skip to content

Commit

Permalink
refactor(collisions): farewell simplex
Browse files Browse the repository at this point in the history
  • Loading branch information
luishfonseca committed Oct 3, 2023
1 parent c50da74 commit 11abc3e
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 256 deletions.
37 changes: 0 additions & 37 deletions core/include/cubos/core/geom/plane.hpp

This file was deleted.

82 changes: 0 additions & 82 deletions core/include/cubos/core/geom/simplex.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ namespace cubos::engine
{
BoxBox = 0,
BoxCapsule,
BoxPlane,
BoxSimplex,
CapsuleCapsule,
CapsulePlane,
CapsuleSimplex,
PlanePlane,
PlaneSimplex,
SimplexSimplex,

Count ///< Number of collision types.
};
Expand Down
28 changes: 0 additions & 28 deletions engine/include/cubos/engine/collisions/colliders/plane.hpp

This file was deleted.

33 changes: 0 additions & 33 deletions engine/include/cubos/engine/collisions/colliders/simplex.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions engine/include/cubos/engine/collisions/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace cubos::engine
/// ## Components
/// - @ref BoxCollider - holds the box collider data.
/// - @ref CapsuleCollider - holds the capsule collider data.
/// - @ref PlaneCollider - holds the plane collider data.
/// - @ref SimplexCollider - holds the simplex collider data.
///
/// ## Events
/// - @ref CollisionEvent - (TODO) emitted when a collision occurs.
Expand Down
57 changes: 6 additions & 51 deletions engine/src/cubos/engine/collisions/broad_phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ void updateCapsuleAABBs(Query<Read<LocalToWorld>, Read<CapsuleCollider>, Write<C
(void)collisions;
}

void updateSimplexAABBs(Query<Read<LocalToWorld>, Read<SimplexCollider>, Write<ColliderAABB>> query,
Write<BroadPhaseCollisions> collisions)
{
(void)query;
(void)collisions;
}

void updateMarkers(Query<Read<ColliderAABB>> query, Write<BroadPhaseCollisions> collisions)
{
// TODO: This is parallelizable.
Expand Down Expand Up @@ -98,59 +91,22 @@ void sweep(Write<BroadPhaseCollisions> collisions)
}
}

CollisionType getCollisionType(bool box, bool capsule, bool plane, bool simplex)
CollisionType getCollisionType(bool box, bool capsule)
{
if (box && capsule)
{
return CollisionType::BoxCapsule;
}

if (box && plane)
{
return CollisionType::BoxPlane;
}

if (box && simplex)
{
return CollisionType::BoxSimplex;
}

if (box)
{
return CollisionType::BoxBox;
}

if (capsule && plane)
{
return CollisionType::CapsulePlane;
}

if (capsule && simplex)
{
return CollisionType::CapsuleSimplex;
}

if (capsule)
{
return CollisionType::CapsuleCapsule;
}

if (plane && simplex)
{
return CollisionType::PlaneSimplex;
}

if (plane)
{
return CollisionType::PlanePlane;
}

return CollisionType::SimplexSimplex;
return CollisionType::CapsuleCapsule;
}

void findPairs(Query<OptRead<BoxCollider>, OptRead<CapsuleCollider>, OptRead<PlaneCollider>, OptRead<SimplexCollider>,
Read<ColliderAABB>>
query,
void findPairs(Query<OptRead<BoxCollider>, OptRead<CapsuleCollider>, Read<ColliderAABB>> query,
Write<BroadPhaseCollisions> collisions)
{
collisions->clearCandidates();
Expand All @@ -159,14 +115,13 @@ void findPairs(Query<OptRead<BoxCollider>, OptRead<CapsuleCollider>, OptRead<Pla
{
for (auto& [entity, overlaps] : collisions->sweepOverlapMaps[axis])
{
auto [box, capsule, plane, simplex, aabb] = query[entity].value();
auto [box, capsule, aabb] = query[entity].value();
for (auto& other : overlaps)
{
auto [otherBox, otherCapsule, otherPlane, otherSimplex, otherAabb] = query[other].value();
auto [otherBox, otherCapsule, otherAabb] = query[other].value();

// TODO: Should this be inside the if statement?
auto type = getCollisionType(box || otherBox, capsule || otherCapsule, plane || otherPlane,
simplex || otherSimplex);
auto type = getCollisionType(box || otherBox, capsule || otherCapsule);

switch (axis)
{
Expand Down
12 changes: 1 addition & 11 deletions engine/src/cubos/engine/collisions/broad_phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <cubos/engine/collisions/broad_phase_collisions.hpp>
#include <cubos/engine/collisions/colliders/box.hpp>
#include <cubos/engine/collisions/colliders/capsule.hpp>
#include <cubos/engine/collisions/colliders/plane.hpp>
#include <cubos/engine/collisions/colliders/simplex.hpp>
#include <cubos/engine/transform/plugin.hpp>

using cubos::core::ecs::Commands;
Expand All @@ -24,8 +22,6 @@ using cubos::engine::BroadPhaseCollisions;
using cubos::engine::CapsuleCollider;
using cubos::engine::ColliderAABB;
using cubos::engine::LocalToWorld;
using cubos::engine::PlaneCollider;
using cubos::engine::SimplexCollider;

/// @brief Adds collision tracking to all new entities with colliders.
template <typename C>
Expand All @@ -51,10 +47,6 @@ void updateBoxAABBs(Query<Read<LocalToWorld>, Read<BoxCollider>, Write<ColliderA
void updateCapsuleAABBs(Query<Read<LocalToWorld>, Read<CapsuleCollider>, Write<ColliderAABB>> query,
Write<BroadPhaseCollisions> collisions);

/// @brief Updates the AABBs of all simplex colliders.
void updateSimplexAABBs(Query<Read<LocalToWorld>, Read<SimplexCollider>, Write<ColliderAABB>> query,
Write<BroadPhaseCollisions> collisions);

/// @brief Updates the sweep markers of all colliders.
void updateMarkers(Query<Read<ColliderAABB>> query, Write<BroadPhaseCollisions> collisions);

Expand All @@ -66,7 +58,5 @@ void sweep(Write<BroadPhaseCollisions> collisions);
/// @details
/// TODO: This query is disgusting. We need a way to find if a component is present without reading it.
/// Maybe something like Commands but for reads?
void findPairs(Query<OptRead<BoxCollider>, OptRead<CapsuleCollider>, OptRead<PlaneCollider>, OptRead<SimplexCollider>,
Read<ColliderAABB>>
query,
void findPairs(Query<OptRead<BoxCollider>, OptRead<CapsuleCollider>, Read<ColliderAABB>> query,
Write<BroadPhaseCollisions> collisions);
5 changes: 0 additions & 5 deletions engine/src/cubos/engine/collisions/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ void cubos::engine::collisionsPlugin(Cubos& cubos)

cubos.addComponent<ColliderAABB>();
cubos.addComponent<BoxCollider>();
cubos.addComponent<SimplexCollider>();
cubos.addComponent<CapsuleCollider>();
cubos.addComponent<PlaneCollider>();

cubos.system(trackNewEntities<BoxCollider>).tagged("cubos.collisions.aabb.missing");
cubos.system(trackNewEntities<SimplexCollider>).tagged("cubos.collisions.aabb.missing");
cubos.system(trackNewEntities<CapsuleCollider>).tagged("cubos.collisions.aabb.missing");
cubos.system(trackNewEntities<PlaneCollider>).tagged("cubos.collisions.aabb.missing");
cubos.tag("cubos.collisions.aabb.missing").before("cubos.collisions.aabb");

cubos.system(updateBoxAABBs).tagged("cubos.collisions.aabb");
cubos.system(updateCapsuleAABBs).tagged("cubos.collisions.aabb");
cubos.system(updateSimplexAABBs).tagged("cubos.collisions.aabb");
cubos.tag("cubos.collisions.aabb").after("cubos.transform.update");

cubos.system(updateMarkers).tagged("cubos.collisions.broad.markers").after("cubos.collisions.aabb");
Expand Down

0 comments on commit 11abc3e

Please sign in to comment.