|
R-Type
Distributed multiplayer game engine in C++
|
System handling collision detection between entities. More...
#include <CollisionSystem.hpp>


Public Member Functions | |
| CollisionSystem ()=default | |
| Default constructor. | |
| ~CollisionSystem () override=default | |
| Default destructor. | |
| void | update (Registry ®istry, float deltaTime) override |
| Detects and handles collisions between entities. | |
| ComponentMask | getComponentMask () const override |
| Gets the component mask for this system. | |
Public Member Functions inherited from ecs::ISystem | |
| virtual | ~ISystem ()=default |
| Virtual destructor. | |
Private Member Functions | |
| bool | checkAABB (const Transform::Vector2 &pos1, const Collider::Vector2 &size1, const Collider::Vector2 &offset1, const Transform::Vector2 &pos2, const Collider::Vector2 &size2, const Collider::Vector2 &offset2) const |
| Checks AABB collision between two entities. | |
| void | handlePickup (Address playerAddr, Address collectibleAddr, Registry ®istry, std::vector< Address > &entitiesToDestroy) |
| Handle collision between player and collectible. | |
| bool | canCollide (std::uint32_t layer1, std::uint32_t mask1, std::uint32_t layer2, std::uint32_t mask2) const |
| Checks if two entities can collide based on layers. | |
| void | resolveWallCollision (Address playerAddr, Address wallAddr, Transform &playerTransform, Collider &playerCollider, Transform &wallTransform, Collider &wallCollider, Registry ®istry) |
| Resolves collision between player and wall by instantly killing the player. | |
| void | handleModuleEnemyCollision (Address moduleAddr, Address enemyAddr, Registry ®istry) |
| Handle collision between orbital module and enemy. | |
| void | handleModuleProjectileCollision (Address moduleAddr, Address projectileAddr, Registry ®istry, std::vector< Address > &entitiesToDestroy) |
| Handle collision between orbital module and projectile. | |
| void | handleProjectileCollision (Registry ®istry, std::uint32_t entity1, std::uint32_t entity2, std::vector< Address > &entitiesToDestroy) |
| Handle projectile collision with other entities. | |
System handling collision detection between entities.
Detects AABB collisions and manages layer-based filtering. Requires Transform and Collider components.
Definition at line 26 of file CollisionSystem.hpp.
|
default |
Default constructor.
|
overridedefault |
Default destructor.
|
private |
Checks if two entities can collide based on layers.
Checks if two entities can collide based on layer masks.
Uses bitwise operations to determine if collision layers are compatible. Entity A can collide with Entity B if:
| layer1 | Collision layer of first entity |
| mask1 | Collision mask of first entity |
| layer2 | Collision layer of second entity |
| mask2 | Collision mask of second entity |
Definition at line 320 of file CollisionSystem.cpp.
Referenced by update().
|
private |
Checks AABB collision between two entities.
Performs AABB (Axis-Aligned Bounding Box) collision test.
Tests if two axis-aligned bounding boxes overlap.
| pos1 | Position of first entity |
| size1 | Size of first collider |
| offset1 | Offset of first collider from position |
| pos2 | Position of second entity |
| size2 | Size of second collider |
| offset2 | Offset of second collider from position |
Definition at line 276 of file CollisionSystem.cpp.
References ecs::Collider::Vector2::x, ecs::Transform::Vector2::x, ecs::Collider::Vector2::y, and ecs::Transform::Vector2::y.
Referenced by update().
|
overridevirtual |
Gets the component mask for this system.
Implements ecs::ISystem.
Definition at line 408 of file CollisionSystem.cpp.
Referenced by update().
|
private |
Handle collision between orbital module and enemy.
Applies damage from the module to the enemy on contact.
| moduleAddr | Orbital module entity address |
| enemyAddr | Enemy entity address |
| registry | Reference to the ECS registry |
Definition at line 230 of file CollisionSystem.cpp.
References ecs::Registry::getComponent(), ecs::Health::getCurrentHealth(), ecs::Registry::hasComponent(), LOG_DEBUG, and ecs::Health::setCurrentHealth().
Referenced by update().

|
private |
Handle collision between orbital module and projectile.
Blocks enemy projectiles by destroying them on contact with the module.
| moduleAddr | Orbital module entity address |
| projectileAddr | Projectile entity address |
| registry | Reference to the ECS registry |
| entitiesToDestroy | Vector to collect entities that should be destroyed |
Definition at line 253 of file CollisionSystem.cpp.
References ecs::Registry::getComponent(), ecs::Registry::hasComponent(), ecs::Projectile::isFriendly(), and LOG_DEBUG.
Referenced by update().

|
private |
Handle collision between player and collectible.
Applies collectible effects to the player and marks collectible for destruction.
| playerAddr | Player entity address |
| collectibleAddr | Collectible entity address |
| registry | Reference to the ECS registry |
| entitiesToDestroy | Vector to collect entities that should be destroyed after collision processing |
Definition at line 117 of file CollisionSystem.cpp.
References ecs::Buff::addBuff(), ecs::Collectible::awardsScore(), ecs::DamageBoost, ecs::DoubleShot, ecs::FireRateBoost, ecs::Collectible::getBuffType(), ecs::Registry::getComponent(), ecs::Health::getCurrentHealth(), ecs::Collectible::getDuration(), ecs::Collectible::getHealthRestore(), ecs::Health::getMaxHealth(), ecs::Player::getScore(), ecs::Collectible::getScoreValue(), ecs::Collectible::getValue(), ecs::Collectible::grantsBuff(), ecs::Registry::hasComponent(), ecs::HealthRegen, ecs::HomingShot, LOG_INFO, ecs::MaxHealthIncrease, ecs::MultiShot, ecs::PiercingShot, ecs::Collectible::restoresHealth(), ecs::Registry::setComponent(), ecs::Health::setCurrentHealth(), ecs::Health::setMaxHealth(), ecs::Player::setScore(), ecs::Shield, ecs::SpeedBoost, and ecs::TripleShot.
Referenced by update().

|
private |
Handle projectile collision with other entities.
Handles projectile-entity collisions and applies damage.
Checks if a collision involves a projectile and a damageable entity (enemy/player). Applies damage based on projectile properties and marks projectile for destruction. Respects friendly fire rules: friendly projectiles damage enemies, enemy projectiles damage players.
| registry | Reference to the ECS registry |
| entity1 | First entity |
| entity2 | Second entity |
| entitiesToDestroy | Vector to collect entities (projectiles) that should be destroyed |
This method implements clean damage logic:
Definition at line 335 of file CollisionSystem.cpp.
References ecs::Registry::getComponent(), ecs::Health::getCurrentHealth(), ecs::Projectile::getDamage(), ecs::Health::getMaxHealth(), ecs::Registry::hasComponent(), ecs::Projectile::isFriendly(), LOG_INFO, and ecs::Health::takeDamage().
Referenced by update().

|
private |
Resolves collision between player and wall by instantly killing the player.
Resolves player-wall collision by instantly killing the player.
Walls are instant death obstacles - deals massive damage to kill player on contact.
| playerAddr | Player entity address |
| wallAddr | Wall entity address |
| playerTransform | Player's transform component |
| playerCollider | Player's collider component |
| wallTransform | Wall's transform component |
| wallCollider | Wall's collider component |
| registry | Reference to the ECS registry |
Definition at line 297 of file CollisionSystem.cpp.
References ecs::Registry::getComponent(), ecs::Registry::hasComponent(), LOG_INFO, and ecs::Health::setCurrentHealth().
Referenced by update().

|
overridevirtual |
Detects and handles collisions between entities.
Performs collision detection between all collidable entities.
Performs N² collision detection between all entities with colliders. Uses AABB (Axis-Aligned Bounding Box) collision detection and layer-based filtering to determine valid collisions.
| registry | Reference to the ECS registry |
| deltaTime | Time elapsed since last frame (in seconds) |
Implements ecs::ISystem.
Definition at line 20 of file CollisionSystem.cpp.
References canCollide(), checkAABB(), ecs::Registry::destroyEntity(), ecs::Registry::getComponent(), getComponentMask(), ecs::Registry::getEntitiesWithMask(), handleModuleEnemyCollision(), handleModuleProjectileCollision(), handlePickup(), handleProjectileCollision(), ecs::Registry::hasComponent(), LOG_DEBUG, and resolveWallCollision().
