Skip to main content

DamageDealerComponent Class

Component that stores damage values per collision layer. More...

Declaration

class helios::engine::mechanics::damage::components::DamageDealerComponent { ... }

Public Constructors Index

DamageDealerComponent ()=default
DamageDealerComponent (const DamageDealerComponent &other)

Copy constructor. More...

DamageDealerComponent (DamageDealerComponent &&) noexcept=default

Public Operators Index

DamageDealerComponent &operator= (const DamageDealerComponent &)=default
DamageDealerComponent &operator= (DamageDealerComponent &&) 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...

DamageDealerComponent &setDamage (const float damage, const uint32_t otherLayerId) noexcept

Sets the damage dealt to entities on a specific layer. More...

floatdamage (const uint32_t otherLayerId) const noexcept

Returns the damage dealt to entities on a specific layer. More...

Private Member Attributes Index

std::array< float, helios::engine::modules::physics::collision::types::MAX_COLLISION_LAYERS >damageRegistry_ {}

Damage values indexed by collision layer. More...

boolisEnabled_ = true

Whether this component is enabled. More...

Description

Component that stores damage values per collision layer.

Allows an entity to deal different amounts of damage depending on which collision layer the target belongs to. Uses a fixed-size array indexed by layer ID for O(1) damage lookup.

Definition at line 30 of file DamageDealerComponent.ixx.

Public Constructors

DamageDealerComponent()

helios::engine::mechanics::damage::components::DamageDealerComponent::DamageDealerComponent ()
default

DamageDealerComponent()

helios::engine::mechanics::damage::components::DamageDealerComponent::DamageDealerComponent (const DamageDealerComponent & other)
inline

Copy constructor.

Parameters
other

The component to copy from.

Definition at line 76 of file DamageDealerComponent.ixx.

76 DamageDealerComponent(const DamageDealerComponent& other) : damageRegistry_(other.damageRegistry_) {}

Reference DamageDealerComponent.

DamageDealerComponent()

helios::engine::mechanics::damage::components::DamageDealerComponent::DamageDealerComponent (DamageDealerComponent &&)
noexcept default

Definition at line 79 of file DamageDealerComponent.ixx.

Reference DamageDealerComponent.

Public Operators

operator=()

DamageDealerComponent & helios::engine::mechanics::damage::components::DamageDealerComponent::operator= (const DamageDealerComponent &)
default

Definition at line 78 of file DamageDealerComponent.ixx.

Reference DamageDealerComponent.

operator=()

DamageDealerComponent & helios::engine::mechanics::damage::components::DamageDealerComponent::operator= (DamageDealerComponent &&)
noexcept default

Definition at line 80 of file DamageDealerComponent.ixx.

Reference DamageDealerComponent.

Public Member Functions

damage()

float helios::engine::mechanics::damage::components::DamageDealerComponent::damage (const uint32_t otherLayerId)
inline nodiscard noexcept

Returns the damage dealt to entities on a specific layer.

Parameters
otherLayerId

The target collision layer ID (must be a power of 2).

Returns

The damage value for the specified layer.

Definition at line 111 of file DamageDealerComponent.ixx.

111 [[nodiscard]] float damage(const uint32_t otherLayerId) const noexcept {
112
113 assert(otherLayerId != 0 && "Unexpected layer id, must not be 0");
114
115 const auto idx = std::countr_zero(otherLayerId);
116 assert(idx < damageRegistry_.size() && "Unexpected layer id, index larger than size");
117
118 return damageRegistry_[idx];
119 }

Referenced by setDamage.

disable()

void helios::engine::mechanics::damage::components::DamageDealerComponent::disable ()
inline noexcept

Disables this component.

Definition at line 65 of file DamageDealerComponent.ixx.

65 void disable() noexcept {
66 isEnabled_ = false;
67 }

enable()

void helios::engine::mechanics::damage::components::DamageDealerComponent::enable ()
inline noexcept

Enables this component.

Definition at line 58 of file DamageDealerComponent.ixx.

58 void enable() noexcept {
59 isEnabled_ = true;
60 }

isEnabled()

bool helios::engine::mechanics::damage::components::DamageDealerComponent::isEnabled ()
inline nodiscard noexcept

Checks whether this component is enabled.

Returns

True if enabled, false otherwise.

Definition at line 51 of file DamageDealerComponent.ixx.

51 [[nodiscard]] bool isEnabled() const noexcept {
52 return isEnabled_;
53 }

setDamage()

DamageDealerComponent & helios::engine::mechanics::damage::components::DamageDealerComponent::setDamage (const float damage, const uint32_t otherLayerId)
inline noexcept

Sets the damage dealt to entities on a specific layer.

Parameters
damage

The damage value to deal.

otherLayerId

The target collision layer ID (must be a power of 2).

Returns

Reference to this component for method chaining.

Definition at line 90 of file DamageDealerComponent.ixx.

91 const float damage,
92 const uint32_t otherLayerId
93 ) noexcept {
94 assert(otherLayerId != 0 && "Unexpected layer id, must not be 0");
95
96 const auto idx = std::countr_zero(otherLayerId);
97
98 assert(idx < damageRegistry_.size() && "Unexpected otherLayerId, index larger than size");
99
100 damageRegistry_[idx] = damage;
101 return *this;
102 }

References damage, DamageDealerComponent and setDamage.

Referenced by setDamage.

Private Member Attributes

damageRegistry_

std::array<float, helios::engine::modules::physics::collision::types::MAX_COLLISION_LAYERS> helios::engine::mechanics::damage::components::DamageDealerComponent::damageRegistry_ {}

Damage values indexed by collision layer.

Definition at line 37 of file DamageDealerComponent.ixx.

37 std::array<float, helios::engine::modules::physics::collision::types::MAX_COLLISION_LAYERS> damageRegistry_{};

isEnabled_

bool helios::engine::mechanics::damage::components::DamageDealerComponent::isEnabled_ = true

Whether this component is enabled.

Definition at line 42 of file DamageDealerComponent.ixx.

42 bool isEnabled_ = true;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.