mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
extended collision handler docs
This commit is contained in:
parent
680f66270f
commit
cebe343e4c
5
Doxyfile
5
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
|
||||
# idk everything else
|
||||
TAB_SIZE = 4
|
||||
@ -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<DIRECTION_C>;
|
||||
// [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<typename T>
|
||||
T getAnyIntersection(
|
||||
|
||||
@ -16,6 +16,7 @@ using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
||||
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
||||
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
||||
|
||||
/*! TODO */
|
||||
enum class GroupLabel
|
||||
{
|
||||
MAPTILES,
|
||||
@ -57,6 +58,7 @@ public:
|
||||
std::bitset<MAX_GROUPS> getGroupBitSet();
|
||||
|
||||
void setTeam(TeamLabel teamLabel);
|
||||
/*! TODO */
|
||||
TeamLabel getTeam();
|
||||
|
||||
Manager& getManager() { return manager; };
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -115,6 +115,15 @@ std::vector<ColliderComponent*> 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<IntersectionBitSet>(
|
||||
Entity* entity,
|
||||
@ -131,6 +140,13 @@ IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
||||
return intersections;
|
||||
};
|
||||
|
||||
/*!
|
||||
*
|
||||
* \details Refer to getAnyIntersection() for more details
|
||||
* \return The first entity with collision found
|
||||
* \see Entity
|
||||
*
|
||||
*/
|
||||
template<>
|
||||
Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||
Entity* entity,
|
||||
@ -149,6 +165,12 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
/*!
|
||||
*
|
||||
* \details Refer to getAnyIntersection() for more details
|
||||
* \return True if any collision was found, otherwise false
|
||||
*
|
||||
*/
|
||||
template<>
|
||||
bool CollisionHandler::getAnyIntersection<bool>(
|
||||
Entity* entity,
|
||||
|
||||
@ -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<IntersectionBitSet>(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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user