Skip to main content

CollisionStateComponent Class

Stores per-frame collision state for a GameObject. More...

Declaration

class helios::engine::modules::physics::collision::components::CollisionStateComponent { ... }

Public Constructors Index

CollisionStateComponent ()=default

Default constructor. More...

CollisionStateComponent (const CollisionStateComponent &other)

Copy constructor (creates empty state). More...

CollisionStateComponent (CollisionStateComponent &&) noexcept=default

Public Operators Index

CollisionStateComponent &operator= (const CollisionStateComponent &)=default
CollisionStateComponent &operator= (CollisionStateComponent &&) noexcept=default

Public Member Functions Index

boolisEnabled () const noexcept

Checks whether this component is enabled. More...

voidenable () noexcept

Enables this component. More...

voiddisable () noexcept

Disables this component. More...

boolsetState (helios::engine::ecs::GameObject gameObject, helios::math::vec3f contact, const bool isSolid, const bool isTrigger, const helios::engine::modules::physics::collision::types::CollisionBehavior collisionBehavior, const bool isCollisionReporter, std::optional< helios::engine::ecs::EntityHandle > other=std::nullopt, const uint32_t collisionLayer=0, const uint32_t otherCollisionLayer=0)

Sets the collision state for this frame. More...

voidreset () noexcept

Resets the collision state for a new frame. More...

voidonAcquire () noexcept

Called when the owning GameObject is acquired from a pool. More...

const types::CollisionContext &collisionContext () const noexcept

Returns the full collision context data. More...

boolhasCollision () const noexcept

Checks whether a collision was detected this frame. More...

std::optional< helios::engine::ecs::EntityHandle >other () const noexcept

Returns the handle of the other entity involved in the collision. More...

boolisCollisionReporter () const noexcept

Checks whether this entity is the collision reporter. More...

boolisSolid () const noexcept

Checks whether this is a solid (physical) collision. More...

boolisTrigger () const noexcept

Checks whether this is a trigger (non-physical) collision. More...

helios::engine::modules::physics::collision::types::CollisionBehaviorcollisionBehavior () const noexcept

Returns the collision behavior for this collision. More...

helios::math::vec3fcontact () const noexcept

Returns the world-space contact point of the collision. More...

uint32_tcollisionLayer () const noexcept

Returns the collision layer ID of this entity. More...

uint32_totherCollisionLayer () const noexcept

Returns the collision layer ID of the other entity. More...

Private Member Attributes Index

helios::math::vec3fcontact_

World-space contact point of the collision. More...

boolisSolid_ = false

Whether this collision is a solid (physical) collision. More...

boolisTrigger_ = false

Whether this collision is a trigger (non-physical) collision. More...

boolisCollisionReporter_ = false

Whether this entity is the collision reporter. More...

std::optional< helios::engine::ecs::EntityHandle >other_

Handle of the other entity involved in the collision. More...

helios::engine::modules::physics::collision::types::CollisionBehaviorcollisionBehavior_ = types::CollisionBehavior::None

The collision behavior to apply. More...

boolhasCollision_ = false

Flag indicating whether a collision was detected this frame. More...

helios::engine::modules::physics::collision::types::CollisionContextcollisionContext_ {}

Full collision context data for event publishing. More...

uint32_tcollisionLayer_ = 0

Collision layer ID of this entity. More...

uint32_totherCollisionLayer_ = 0

Collision layer ID of the other entity. More...

boolisEnabled_ = true

Whether this component is enabled. More...

Description

Stores per-frame collision state for a GameObject.

This component is written by the collision detection system each frame to record whether a collision occurred and provide details about the collision. Game logic can query this component to react to collisions.

The state should be reset at the start of each frame by the collision system or when the owning GameObject is acquired from a pool.

Definition at line 35 of file CollisionStateComponent.ixx.

Public Constructors

CollisionStateComponent()

helios::engine::modules::physics::collision::components::CollisionStateComponent::CollisionStateComponent ()
default

Default constructor.

Definition at line 119 of file CollisionStateComponent.ixx.

Referenced by CollisionStateComponent, CollisionStateComponent, operator= and operator=.

CollisionStateComponent()

helios::engine::modules::physics::collision::components::CollisionStateComponent::CollisionStateComponent (const CollisionStateComponent & other)
inline

Copy constructor (creates empty state).

Parameters
other

The component to copy from (state is not copied).

Definition at line 126 of file CollisionStateComponent.ixx.

References CollisionStateComponent and other.

CollisionStateComponent()

helios::engine::modules::physics::collision::components::CollisionStateComponent::CollisionStateComponent (CollisionStateComponent &&)
noexcept default

Definition at line 129 of file CollisionStateComponent.ixx.

Reference CollisionStateComponent.

Public Operators

operator=()

CollisionStateComponent & helios::engine::modules::physics::collision::components::CollisionStateComponent::operator= (const CollisionStateComponent &)
default

Definition at line 128 of file CollisionStateComponent.ixx.

Reference CollisionStateComponent.

operator=()

CollisionStateComponent & helios::engine::modules::physics::collision::components::CollisionStateComponent::operator= (CollisionStateComponent &&)
noexcept default

Definition at line 130 of file CollisionStateComponent.ixx.

Reference CollisionStateComponent.

Public Member Functions

collisionBehavior()

helios::engine::modules::physics::collision::types::CollisionBehavior helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionBehavior ()
inline nodiscard noexcept

Returns the collision behavior for this collision.

Returns

The CollisionBehavior enum value.

Definition at line 285 of file CollisionStateComponent.ixx.

286 return collisionBehavior_;
287 }

Referenced by setState.

collisionContext()

const types::CollisionContext & helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionContext ()
inline nodiscard noexcept

Returns the full collision context data.

Returns

Reference to the CollisionContext struct containing all collision details.

Definition at line 230 of file CollisionStateComponent.ixx.

230 [[nodiscard]] const types::CollisionContext& collisionContext() const noexcept {
231 return collisionContext_;
232 }

collisionLayer()

uint32_t helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionLayer ()
inline nodiscard noexcept

Returns the collision layer ID of this entity.

Returns

The collision layer ID.

Definition at line 303 of file CollisionStateComponent.ixx.

303 [[nodiscard]] uint32_t collisionLayer() const noexcept {
304 return collisionLayer_;
305 }

Referenced by setState.

contact()

helios::math::vec3f helios::engine::modules::physics::collision::components::CollisionStateComponent::contact ()
inline nodiscard noexcept

Returns the world-space contact point of the collision.

Returns

The contact point as a 3D vector.

Definition at line 294 of file CollisionStateComponent.ixx.

294 [[nodiscard]] helios::math::vec3f contact() const noexcept {
295 return contact_;
296 }

Referenced by setState.

disable()

void helios::engine::modules::physics::collision::components::CollisionStateComponent::disable ()
inline noexcept

Disables this component.

Definition at line 112 of file CollisionStateComponent.ixx.

112 void disable() noexcept {
113 isEnabled_ = false;
114 }

enable()

void helios::engine::modules::physics::collision::components::CollisionStateComponent::enable ()
inline noexcept

Enables this component.

Definition at line 105 of file CollisionStateComponent.ixx.

105 void enable() noexcept {
106 isEnabled_ = true;
107 }

hasCollision()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::hasCollision ()
inline nodiscard noexcept

Checks whether a collision was detected this frame.

Returns

True if a collision occurred, false otherwise.

Definition at line 240 of file CollisionStateComponent.ixx.

240 [[nodiscard]] bool hasCollision() const noexcept {
241 return hasCollision_;
242 }

Referenced by helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::solveCell.

isCollisionReporter()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isCollisionReporter ()
inline nodiscard noexcept

Checks whether this entity is the collision reporter.

Returns

True if this entity reported the collision.

Definition at line 258 of file CollisionStateComponent.ixx.

258 [[nodiscard]] bool isCollisionReporter() const noexcept {
259 return isCollisionReporter_;
260 }

Referenced by setState.

isEnabled()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isEnabled ()
inline nodiscard noexcept

Checks whether this component is enabled.

Returns

True if enabled, false otherwise.

Definition at line 98 of file CollisionStateComponent.ixx.

98 [[nodiscard]] bool isEnabled() const noexcept {
99 return isEnabled_;
100 }

isSolid()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isSolid ()
inline nodiscard noexcept

Checks whether this is a solid (physical) collision.

Returns

True if the collision is solid.

Definition at line 267 of file CollisionStateComponent.ixx.

267 [[nodiscard]] bool isSolid() const noexcept {
268 return isSolid_;
269 }

Referenced by setState.

isTrigger()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isTrigger ()
inline nodiscard noexcept

Checks whether this is a trigger (non-physical) collision.

Returns

True if the collision is a trigger.

Definition at line 276 of file CollisionStateComponent.ixx.

276 [[nodiscard]] bool isTrigger() const noexcept {
277 return isTrigger_;
278 }

Referenced by setState.

onAcquire()

void helios::engine::modules::physics::collision::components::CollisionStateComponent::onAcquire ()
inline noexcept

Called when the owning GameObject is acquired from a pool.

Resets all collision state to prepare for a new lifecycle.

Definition at line 221 of file CollisionStateComponent.ixx.

221 void onAcquire() noexcept {
222 reset();
223 }

Reference reset.

other()

std::optional< helios::engine::ecs::EntityHandle > helios::engine::modules::physics::collision::components::CollisionStateComponent::other ()
inline nodiscard noexcept

Returns the handle of the other entity involved in the collision.

Returns

Optional handle of the other entity, or nullopt if not set.

Definition at line 249 of file CollisionStateComponent.ixx.

249 [[nodiscard]] std::optional<helios::engine::ecs::EntityHandle> other() const noexcept {
250 return other_;
251 }

Referenced by CollisionStateComponent and setState.

otherCollisionLayer()

uint32_t helios::engine::modules::physics::collision::components::CollisionStateComponent::otherCollisionLayer ()
inline nodiscard noexcept

Returns the collision layer ID of the other entity.

Returns

The other entity's collision layer ID.

Definition at line 312 of file CollisionStateComponent.ixx.

312 [[nodiscard]] uint32_t otherCollisionLayer() const noexcept {
313 return otherCollisionLayer_;
314 }

Referenced by setState.

reset()

void helios::engine::modules::physics::collision::components::CollisionStateComponent::reset ()
inline noexcept

Resets the collision state for a new frame.

Clears all collision flags and data. Called at the start of each frame or when the owning GameObject is acquired from a pool.

Definition at line 198 of file CollisionStateComponent.ixx.

198 void reset() noexcept {
199 hasCollision_ = false;
200 isSolid_ = false;
201 isTrigger_ = false;
202
203 collisionBehavior_ = types::CollisionBehavior::None;
204
205 isCollisionReporter_ = false;
206
207 other_ = std::nullopt;
208 contact_ = helios::math::vec3f{0.0f, 0.0f, 0.0f};
209
210 collisionContext_ = types::CollisionContext{};
211
212 collisionLayer_ = 0;
213 otherCollisionLayer_ = 0;
214 }

Reference helios::engine::modules::physics::collision::types::None.

Referenced by onAcquire.

setState()

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::setState (helios::engine::ecs::GameObject gameObject, helios::math::vec3f contact, const bool isSolid, const bool isTrigger, const helios::engine::modules::physics::collision::types::CollisionBehavior collisionBehavior, const bool isCollisionReporter, std::optional< helios::engine::ecs::EntityHandle > other=std::nullopt, const uint32_t collisionLayer=0, const uint32_t otherCollisionLayer=0)
inline

Sets the collision state for this frame.

This method is called by the collision detection system when a collision is detected. Only the first collision per frame is recorded.

Parameters
contact

World-space contact point.

isSolid

Whether this is a solid collision.

isTrigger

Whether this is a trigger collision.

collisionBehavior

The behavior to apply for this collision.

isCollisionReporter

Whether this entity reports the collision.

other

GUID of the other entity (optional).

collisionLayer

Collision layer ID of this entity.

otherCollisionLayer

Collision layer ID of the other entity.

Returns

True if the state was set, false if a collision was already recorded.

Definition at line 149 of file CollisionStateComponent.ixx.

150 helios::engine::ecs::GameObject gameObject,
151 helios::math::vec3f contact,
152 const bool isSolid,
153 const bool isTrigger,
154 const helios::engine::modules::physics::collision::types::CollisionBehavior collisionBehavior,
155 const bool isCollisionReporter,
156 std::optional<helios::engine::ecs::EntityHandle> other = std::nullopt,
157 const uint32_t collisionLayer = 0,
158 const uint32_t otherCollisionLayer = 0) {
159
160 if (hasCollision_) {
161 return false;
162 }
163
164 hasCollision_ = true;
165 isSolid_ = isSolid;
166 isTrigger_ = isTrigger;
167
168 collisionBehavior_ = collisionBehavior;
169
170 isCollisionReporter_ = isCollisionReporter;
171
172 other_ = other;
173 contact_ = contact;
174
175 collisionLayer_ = collisionLayer;
176 otherCollisionLayer_ = otherCollisionLayer;
177
178 collisionContext_ = types::CollisionContext{
179 .source = gameObject.entityHandle(),
180 .contact = contact,
181 .isSolid = isSolid,
182 .isTrigger = isTrigger,
183 .isCollisionReporter = isCollisionReporter,
184 .other = other,
185 .collisionLayerId = collisionLayer,
186 .otherCollisionLayerId = otherCollisionLayer,
187 };
188
189 return true;
190 }

References collisionBehavior, collisionLayer, contact, isCollisionReporter, isSolid, isTrigger, other, otherCollisionLayer and setState.

Referenced by setState.

Private Member Attributes

collisionBehavior_

helios::engine::modules::physics::collision::types::CollisionBehavior helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionBehavior_ = types::CollisionBehavior::None

The collision behavior to apply.

Definition at line 64 of file CollisionStateComponent.ixx.

collisionContext_

helios::engine::modules::physics::collision::types::CollisionContext helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionContext_ {}

Full collision context data for event publishing.

Definition at line 74 of file CollisionStateComponent.ixx.

collisionLayer_

uint32_t helios::engine::modules::physics::collision::components::CollisionStateComponent::collisionLayer_ = 0

Collision layer ID of this entity.

Definition at line 79 of file CollisionStateComponent.ixx.

79 uint32_t collisionLayer_ = 0;

contact_

helios::math::vec3f helios::engine::modules::physics::collision::components::CollisionStateComponent::contact_

World-space contact point of the collision.

Definition at line 39 of file CollisionStateComponent.ixx.

39 helios::math::vec3f contact_;

hasCollision_

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::hasCollision_ = false

Flag indicating whether a collision was detected this frame.

Definition at line 69 of file CollisionStateComponent.ixx.

69 bool hasCollision_ = false;

isCollisionReporter_

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isCollisionReporter_ = false

Whether this entity is the collision reporter.

Definition at line 54 of file CollisionStateComponent.ixx.

54 bool isCollisionReporter_ = false;

isEnabled_

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isEnabled_ = true

Whether this component is enabled.

Definition at line 89 of file CollisionStateComponent.ixx.

89 bool isEnabled_ = true;

isSolid_

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isSolid_ = false

Whether this collision is a solid (physical) collision.

Definition at line 44 of file CollisionStateComponent.ixx.

44 bool isSolid_ = false;

isTrigger_

bool helios::engine::modules::physics::collision::components::CollisionStateComponent::isTrigger_ = false

Whether this collision is a trigger (non-physical) collision.

Definition at line 49 of file CollisionStateComponent.ixx.

49 bool isTrigger_ = false;

other_

std::optional<helios::engine::ecs::EntityHandle> helios::engine::modules::physics::collision::components::CollisionStateComponent::other_

Handle of the other entity involved in the collision.

Definition at line 59 of file CollisionStateComponent.ixx.

59 std::optional<helios::engine::ecs::EntityHandle> other_;

otherCollisionLayer_

uint32_t helios::engine::modules::physics::collision::components::CollisionStateComponent::otherCollisionLayer_ = 0

Collision layer ID of the other entity.

Definition at line 84 of file CollisionStateComponent.ixx.

84 uint32_t otherCollisionLayer_ = 0;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.