-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(collisions): extract broadphase to plugin
- Loading branch information
1 parent
5d133d8
commit db4adfa
Showing
14 changed files
with
400 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
engine/include/cubos/engine/collisions/broad_phase/plugin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// @dir | ||
/// @brief @ref broad-phase-collisions-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup broad-phase-collisions-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/cubos.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup broad-phase-collisions-plugin Broad-phase Collisions | ||
/// @ingroup engine | ||
/// @brief Adds broad-phase collision detection to @b CUBOS. | ||
/// | ||
/// ## 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. | ||
/// @ingroup broad-phase-collisions-plugin | ||
void broadPhaseCollisionsPlugin(Cubos& cubos); | ||
} // namespace cubos::engine |
51 changes: 51 additions & 0 deletions
51
engine/include/cubos/engine/collisions/broad_phase/sweep_and_prune.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::BroadPhaseSweepAndPrune. | ||
/// @ingroup broad-phase-collisions-plugin | ||
|
||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <vector> | ||
|
||
#include <cubos/core/ecs/entity/hash.hpp> | ||
#include <cubos/core/ecs/entity/manager.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Resource which stores sweep and prune data. | ||
/// @ingroup broad-phase-collisions-plugin | ||
struct BroadPhaseSweepAndPrune | ||
{ | ||
/// @brief Marker used for sweep and prune. | ||
struct SweepMarker | ||
{ | ||
core::ecs::Entity entity; ///< Entity referenced by the marker. | ||
bool isMin; ///< Whether the marker is a min or max marker. | ||
}; | ||
|
||
/// @brief List of ordered sweep markers for each axis. Stores the index of the marker in mMarkers. | ||
std::vector<SweepMarker> markersPerAxis[3]; | ||
|
||
/// @brief Maps of overlapping entities for each axis calculated by sweep and prune. | ||
/// | ||
/// For each each map, the key is an entity and the value is a list of entities that | ||
/// overlap with the key. Symmetrical pairs are not stored. | ||
std::unordered_map<core::ecs::Entity, std::vector<core::ecs::Entity>, core::ecs::EntityHash> | ||
sweepOverlapMaps[3]; | ||
|
||
/// @brief Set of active entities during sweep for each axis. | ||
std::unordered_set<core::ecs::Entity, core::ecs::EntityHash> activePerAxis[3]; | ||
|
||
/// @brief Adds an entity to the list of entities tracked by sweep and prune. | ||
/// @param entity Entity to add. | ||
void addEntity(core::ecs::Entity entity); | ||
|
||
/// @brief Removes an entity from the list of entities tracked by sweep and prune. | ||
/// @param entity Entity to remove. | ||
void removeEntity(core::ecs::Entity entity); | ||
|
||
/// @brief Clears the list of entities tracked by sweep and prune. | ||
void clearEntities(); | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.