mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 10:13:42 +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
|
# Source files
|
||||||
INPUT = ./include ./src
|
INPUT = ./include ./src
|
||||||
FILE_PATTERNS = *.cpp *.h *.hpp
|
FILE_PATTERNS = *.cpp *.h *.hpp
|
||||||
|
EXAMPLE_PATH = ./include ./src
|
||||||
|
EXAMPLE_PATTERNS = *.cpp *.h *.hpp
|
||||||
|
|
||||||
# Output formats
|
# Output formats
|
||||||
GENERATE_XML = YES
|
GENERATE_XML = YES
|
||||||
@ -57,4 +59,5 @@ DISABLE_INDEX = YES
|
|||||||
GENERATE_TREEVIEW = YES
|
GENERATE_TREEVIEW = YES
|
||||||
HTML_COLLABORATION = YES
|
HTML_COLLABORATION = YES
|
||||||
|
|
||||||
# idk everything else
|
# idk everything else
|
||||||
|
TAB_SIZE = 4
|
||||||
@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
//! \file CollisionHandler.h
|
||||||
|
//! \file CollisionHandler.cpp
|
||||||
|
//! \file TransformComponent.cpp
|
||||||
|
|
||||||
#include "ColliderComponent.h"
|
#include "ColliderComponent.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
@ -17,9 +21,11 @@
|
|||||||
class ColliderComponent;
|
class ColliderComponent;
|
||||||
class Entity;
|
class Entity;
|
||||||
|
|
||||||
|
// [IntersectionBitSet]
|
||||||
constexpr uint8_t DIRECTION_C = 4;
|
constexpr uint8_t DIRECTION_C = 4;
|
||||||
|
|
||||||
using IntersectionBitSet = std::bitset<DIRECTION_C>;
|
using IntersectionBitSet = std::bitset<DIRECTION_C>;
|
||||||
|
// [IntersectionBitSet]
|
||||||
|
|
||||||
class CollisionHandler
|
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 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
|
* if they don't have a ColliderComponent
|
||||||
* \param entity The primary entity to check against. Return values will be relative to this entity
|
* \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 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 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
|
* \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 GroupLabel
|
||||||
* \see TeamLabel
|
* \see TeamLabel
|
||||||
* \see Entity
|
* \see Entity
|
||||||
* \see ColliderComponent
|
* \see ColliderComponent
|
||||||
* \see IntersectionBitSet
|
|
||||||
* \see Direction
|
|
||||||
* \see Entity::getTeam()
|
* \see Entity::getTeam()
|
||||||
|
* \details Example usage for IntersectionBitSet (TransformComponent::update()):
|
||||||
|
* \snippet{trimleft} TransformComponent.cpp getAnyIntersection example code
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T getAnyIntersection(
|
T getAnyIntersection(
|
||||||
|
|||||||
@ -16,6 +16,7 @@ using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
|||||||
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
||||||
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
||||||
|
|
||||||
|
/*! TODO */
|
||||||
enum class GroupLabel
|
enum class GroupLabel
|
||||||
{
|
{
|
||||||
MAPTILES,
|
MAPTILES,
|
||||||
@ -57,6 +58,7 @@ public:
|
|||||||
std::bitset<MAX_GROUPS> getGroupBitSet();
|
std::bitset<MAX_GROUPS> getGroupBitSet();
|
||||||
|
|
||||||
void setTeam(TeamLabel teamLabel);
|
void setTeam(TeamLabel teamLabel);
|
||||||
|
/*! TODO */
|
||||||
TeamLabel getTeam();
|
TeamLabel getTeam();
|
||||||
|
|
||||||
Manager& getManager() { return manager; };
|
Manager& getManager() { return manager; };
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public:
|
|||||||
TransformComponent(float x, float y, int w, int h, int scale);
|
TransformComponent(float x, float y, int w, int h, int scale);
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
/*! TODO: document usage of collision handler */
|
||||||
void update() override;
|
void update() override;
|
||||||
void modifySpeed(int8_t modifier);
|
void modifySpeed(int8_t modifier);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -115,6 +115,15 @@ std::vector<ColliderComponent*> CollisionHandler::getColliders(
|
|||||||
return colliders;
|
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<>
|
template<>
|
||||||
IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
@ -131,6 +140,13 @@ IntersectionBitSet CollisionHandler::getAnyIntersection<IntersectionBitSet>(
|
|||||||
return intersections;
|
return intersections;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \details Refer to getAnyIntersection() for more details
|
||||||
|
* \return The first entity with collision found
|
||||||
|
* \see Entity
|
||||||
|
*
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
@ -149,6 +165,12 @@ Entity* CollisionHandler::getAnyIntersection<Entity*>(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \details Refer to getAnyIntersection() for more details
|
||||||
|
* \return True if any collision was found, otherwise false
|
||||||
|
*
|
||||||
|
*/
|
||||||
template<>
|
template<>
|
||||||
bool CollisionHandler::getAnyIntersection<bool>(
|
bool CollisionHandler::getAnyIntersection<bool>(
|
||||||
Entity* entity,
|
Entity* entity,
|
||||||
|
|||||||
@ -63,6 +63,8 @@ void TransformComponent::update()
|
|||||||
// TODO: move to separate functions
|
// TODO: move to separate functions
|
||||||
|
|
||||||
if (this->entity->hasGroup((size_t)GroupLabel::PLAYERS)) {
|
if (this->entity->hasGroup((size_t)GroupLabel::PLAYERS)) {
|
||||||
|
|
||||||
|
// [getAnyIntersection example code]
|
||||||
IntersectionBitSet intersections =
|
IntersectionBitSet intersections =
|
||||||
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) |
|
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) |
|
||||||
(Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(positionChange.x, 0), { GroupLabel::MAPTILES, GroupLabel::COLLIDERS })) &
|
(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))
|
if (intersections.test((size_t)Direction::UP) || intersections.test((size_t)Direction::DOWN))
|
||||||
positionChange.y = 0;
|
positionChange.y = 0;
|
||||||
|
// [getAnyIntersection example code]
|
||||||
}
|
}
|
||||||
|
|
||||||
position += positionChange;
|
position += positionChange;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user