Skip to content

Commit

Permalink
fix(collisions): apply review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luishfonseca committed Oct 7, 2023
1 parent 77647c6 commit 481ad37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
27 changes: 12 additions & 15 deletions engine/src/cubos/engine/collisions/broad_phase/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using cubos::core::ecs::Write;
using namespace cubos::engine;

/// @brief Tracks all new colliders.
void trackNewColliders(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrune> sweepAndPrune)
static void trackNewCollidersSystem(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrune> sweepAndPrune)
{
for (auto [entity, collider] : query)
{
Expand All @@ -28,7 +28,7 @@ void trackNewColliders(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrun
}

/// @brief Updates the AABBs of all colliders.
void updateAABBs(Query<Read<LocalToWorld>, Write<Collider>> query)
static void updateAABBsSystem(Query<Read<LocalToWorld>, Write<Collider>> query)
{
for (auto [entity, localToWorld, collider] : query)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ void updateAABBs(Query<Read<LocalToWorld>, Write<Collider>> query)
}

/// @brief Updates the sweep markers of all colliders.
void updateMarkers(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrune> sweepAndPrune)
static void updateMarkersSystem(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrune> sweepAndPrune)
{
// TODO: This is parallelizable.
for (glm::length_t axis = 0; axis < 3; axis++)
Expand All @@ -84,7 +84,7 @@ void updateMarkers(Query<Read<Collider>> query, Write<BroadPhaseSweepAndPrune> s
}

/// @brief Performs a sweep of all colliders.
void sweep(Write<BroadPhaseSweepAndPrune> sweepAndPrune)
static void sweepSystem(Write<BroadPhaseSweepAndPrune> sweepAndPrune)
{
// TODO: This is parallelizable.
for (glm::length_t axis = 0; axis < 3; axis++)
Expand Down Expand Up @@ -131,9 +131,8 @@ BroadPhaseCandidates::CollisionType getCollisionType(bool box, bool capsule)
///
/// @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<BoxCollisionShape>, OptRead<CapsuleCollisionShape>, Read<Collider>> query,
Read<BroadPhaseSweepAndPrune> sweepAndPrune, Write<BroadPhaseCandidates> candidates)
static void findPairsSystem(Query<OptRead<BoxCollisionShape>, OptRead<CapsuleCollisionShape>, Read<Collider>> query,
Read<BroadPhaseSweepAndPrune> sweepAndPrune, Write<BroadPhaseCandidates> candidates)
{
candidates->clearCandidates();

Expand Down Expand Up @@ -180,20 +179,18 @@ void findPairs(Query<OptRead<BoxCollisionShape>, OptRead<CapsuleCollisionShape>,

void cubos::engine::broadPhaseCollisionsPlugin(Cubos& cubos)
{
// FIXME: Is it ok not to add resources from the general plugin?

cubos.addResource<BroadPhaseCandidates>();
cubos.addResource<BroadPhaseSweepAndPrune>();

cubos.system(trackNewColliders).tagged("cubos.collisions.aabb.setup");
cubos.system(trackNewCollidersSystem).tagged("cubos.collisions.aabb.setup");

cubos.system(updateAABBs)
cubos.system(updateAABBsSystem)
.tagged("cubos.collisions.aabb.update")
.after("cubos.collisions.setup")
.after("cubos.collisions.aabb.setup")
.after("cubos.transform.update");

cubos.system(updateMarkers).tagged("cubos.collisions.broad.markers").after("cubos.collisions.aabb.update");
cubos.system(sweep).tagged("cubos.collisions.broad.sweep").after("cubos.collisions.broad.markers");
cubos.system(findPairs).tagged("cubos.collisions.broad").after("cubos.collisions.broad.sweep");
}
cubos.system(updateMarkersSystem).tagged("cubos.collisions.broad.markers").after("cubos.collisions.aabb.update");
cubos.system(sweepSystem).tagged("cubos.collisions.broad.sweep").after("cubos.collisions.broad.markers");
cubos.system(findPairsSystem).tagged("cubos.collisions.broad").after("cubos.collisions.broad.sweep");
}
1 change: 0 additions & 1 deletion engine/src/cubos/engine/collisions/broad_phase/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace cubos::engine
/// ## Resources
/// - @ref BroadPhaseCandidates - stores broad phase collision data.
/// - @ref BroadPhaseSweepAndPrune - stores sweep and prune markers.
///

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class.
Expand Down
8 changes: 4 additions & 4 deletions engine/src/cubos/engine/collisions/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using cubos::core::ecs::Write;
using namespace cubos::engine;

/// @brief Setups new box colliders.
void setupNewBoxes(Query<Read<BoxCollisionShape>, Write<Collider>> query)
static void setupNewBoxesSystem(Query<Read<BoxCollisionShape>, Write<Collider>> query)
{
for (auto [entity, shape, collider] : query)
{
Expand All @@ -33,7 +33,7 @@ void setupNewBoxes(Query<Read<BoxCollisionShape>, Write<Collider>> query)
}

/// @brief Setups new capsule colliders.
void setupNewCapsules(Query<Read<CapsuleCollisionShape>, Write<Collider>> query)
static void setupNewCapsulesSystem(Query<Read<CapsuleCollisionShape>, Write<Collider>> query)
{
for (auto [entity, shape, collider] : query)
{
Expand Down Expand Up @@ -61,6 +61,6 @@ void cubos::engine::collisionsPlugin(Cubos& cubos)
cubos.addComponent<BoxCollisionShape>();
cubos.addComponent<CapsuleCollisionShape>();

cubos.system(setupNewBoxes).tagged("cubos.collisions.setup");
cubos.system(setupNewCapsules).tagged("cubos.collisions.setup");
cubos.system(setupNewBoxesSystem).tagged("cubos.collisions.setup");
cubos.system(setupNewCapsulesSystem).tagged("cubos.collisions.setup");
}

0 comments on commit 481ad37

Please sign in to comment.