From cebe343e4cf5d75e5b1dec49ceef00cb753819cb Mon Sep 17 00:00:00 2001 From: Benedikt Galbavy Date: Fri, 2 Feb 2024 15:12:51 +0100 Subject: [PATCH] extended collision handler docs --- Doxyfile | 5 ++++- include/CollisionHandler.h | 16 ++++++++++------ include/Entity.h | 2 ++ include/TransformComponent.h | 1 + src/CollisionHandler.cpp | 22 ++++++++++++++++++++++ src/TransformComponent.cpp | 3 +++ 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Doxyfile b/Doxyfile index c25adcc..cf23eae 100644 --- a/Doxyfile +++ b/Doxyfile @@ -26,6 +26,8 @@ DOT_TRANSPARENT = YES # Source files INPUT = ./include ./src FILE_PATTERNS = *.cpp *.h *.hpp +EXAMPLE_PATH = ./include ./src +EXAMPLE_PATTERNS = *.cpp *.h *.hpp # Output formats GENERATE_XML = YES @@ -57,4 +59,5 @@ DISABLE_INDEX = YES GENERATE_TREEVIEW = YES HTML_COLLABORATION = YES -# idk everything else \ No newline at end of file +# idk everything else +TAB_SIZE = 4 \ No newline at end of file diff --git a/include/CollisionHandler.h b/include/CollisionHandler.h index 8c02980..5acf169 100644 --- a/include/CollisionHandler.h +++ b/include/CollisionHandler.h @@ -1,5 +1,9 @@ #pragma once +//! \file CollisionHandler.h +//! \file CollisionHandler.cpp +//! \file TransformComponent.cpp + #include "ColliderComponent.h" #include "Constants.h" #include "Entity.h" @@ -17,9 +21,11 @@ class ColliderComponent; class Entity; +// [IntersectionBitSet] constexpr uint8_t DIRECTION_C = 4; using IntersectionBitSet = std::bitset; +// [IntersectionBitSet] class CollisionHandler { @@ -54,20 +60,18 @@ public: * If the primary entity has no ColliderComponent, the equivalent of no collision is returned immediately, other entities are skipped * if they don't have a ColliderComponent * \param entity The primary entity to check against. Return values will be relative to this entity - * \param posMod Modifier to apply toposition before checking collisions. Example: (TODO: link player collision) + * \param posMod Modifier to apply toposition before checking collisions. * \param groupLabels Entities need to have at least one listed GroupLabels to get checked against * \param teamLabels Entities need to have one of the specified TeamLabels to get checked against * \param negateTeam If set to true, entities will only be checked against if they **don't** have one of the specified TeamLabels - * \return `bool` true if any collision was found, otherwise false - * \return `Entity*` returns first entity with collision found - * \return `IntersectionBitSet` bitset of intersection, position `Direction` true if any part in direction collides * \see GroupLabel * \see TeamLabel * \see Entity * \see ColliderComponent - * \see IntersectionBitSet - * \see Direction * \see Entity::getTeam() + * \details Example usage for IntersectionBitSet (TransformComponent::update()): + * \snippet{trimleft} TransformComponent.cpp getAnyIntersection example code + * */ template T getAnyIntersection( diff --git a/include/Entity.h b/include/Entity.h index ad0f2b5..ce0d5ad 100644 --- a/include/Entity.h +++ b/include/Entity.h @@ -16,6 +16,7 @@ using ComponentBitSet = std::bitset; using GroupBitSet = std::bitset; using ComponentArray = std::array; +/*! TODO */ enum class GroupLabel { MAPTILES, @@ -57,6 +58,7 @@ public: std::bitset getGroupBitSet(); void setTeam(TeamLabel teamLabel); + /*! TODO */ TeamLabel getTeam(); Manager& getManager() { return manager; }; diff --git a/include/TransformComponent.h b/include/TransformComponent.h index e57d747..43e6cdc 100644 --- a/include/TransformComponent.h +++ b/include/TransformComponent.h @@ -23,6 +23,7 @@ public: TransformComponent(float x, float y, int w, int h, int scale); void init() override; + /*! TODO: document usage of collision handler */ void update() override; void modifySpeed(int8_t modifier); }; diff --git a/src/CollisionHandler.cpp b/src/CollisionHandler.cpp index d481094..126466a 100644 --- a/src/CollisionHandler.cpp +++ b/src/CollisionHandler.cpp @@ -115,6 +115,15 @@ std::vector CollisionHandler::getColliders( return colliders; } +/*! + * + * \details Refer to getAnyIntersection() for more details + * \return A bitset of intersections, describing the directions of intersection. Position `Direction` in bitset true if edge in that direction collides + * \see Direction + * \see IntersectionBitSet + * \snippet CollisionHandler.h IntersectionBitSet + * + */ template<> IntersectionBitSet CollisionHandler::getAnyIntersection( Entity* entity, @@ -131,6 +140,13 @@ IntersectionBitSet CollisionHandler::getAnyIntersection( return intersections; }; +/*! + * + * \details Refer to getAnyIntersection() for more details + * \return The first entity with collision found + * \see Entity + * + */ template<> Entity* CollisionHandler::getAnyIntersection( Entity* entity, @@ -149,6 +165,12 @@ Entity* CollisionHandler::getAnyIntersection( return nullptr; }; +/*! + * + * \details Refer to getAnyIntersection() for more details + * \return True if any collision was found, otherwise false + * + */ template<> bool CollisionHandler::getAnyIntersection( Entity* entity, diff --git a/src/TransformComponent.cpp b/src/TransformComponent.cpp index d586a1c..b7de2e8 100644 --- a/src/TransformComponent.cpp +++ b/src/TransformComponent.cpp @@ -63,6 +63,8 @@ void TransformComponent::update() // TODO: move to separate functions if (this->entity->hasGroup((size_t)GroupLabel::PLAYERS)) { + + // [getAnyIntersection example code] IntersectionBitSet intersections = (CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) | (Game::collisionHandler->getAnyIntersection(entity, Vector2D(positionChange.x, 0), { GroupLabel::MAPTILES, GroupLabel::COLLIDERS })) & @@ -76,6 +78,7 @@ void TransformComponent::update() if (intersections.test((size_t)Direction::UP) || intersections.test((size_t)Direction::DOWN)) positionChange.y = 0; + // [getAnyIntersection example code] } position += positionChange;