Skip to main content

CollisionConfig.ixx File

Configuration for collision detection components. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacebuilder

Fluent builder pattern for constructing GameObjects. More...

namespacegameObject

Factory and prototype classes for GameObject construction. More...

namespacebuilders

Domain-specific builders for configuring different aspects of GameObjects. More...

namespaceconfigs

Fine-grained configuration classes for component setup. More...

Classes Index

classCollisionConfig

Fluent configuration for collision detection setup. More...

Description

Configuration for collision detection components.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file CollisionConfig.ixx
3 * @brief Configuration for collision detection components.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.builder.gameObject.builders.configs.CollisionConfig;
11
12import helios.engine.ecs.GameObject;
13
14import helios.engine.modules.physics.collision.components;
15import helios.engine.modules.physics.collision.types;
16
17import helios.engine.mechanics.damage.components.DamageDealerComponent;
18
20
21 /**
22 * @brief Fluent configuration for collision detection setup.
23 *
24 * Automatically adds CollisionStateComponent and provides methods
25 * for configuring collision layers, masks, and behaviors.
26 */
28
29 /**
30 * @brief Non-owning pointer to the target GameObject.
31 */
33
34 /**
35 * @brief Validates CollisionComponent presence.
36 *
37 * @param isAvailable Whether the component should exist.
38 */
39 void ensureCollisionComponent(const bool isAvailable) const noexcept {
40
42
43 if (isAvailable) {
44 assert(cc && "CollisionComponent not configured");
45 } else {
46 assert(!cc && "CollisionComponent already configured");
47 }
48
49 }
50
51 public:
52
53 /**
54 * @brief Constructs a CollisionConfig and adds CollisionStateComponent.
55 *
56 * @param gameObject Target GameObject to configure.
57 */
59
61
62 }
63
64 /**
65 * @brief Adds AABB collider for bounding box collision.
66 *
67 * @return Reference to this config for chaining.
68 */
71 return *this;
72 }
73
74 /**
75 * @brief Sets the collision layer ID.
76 *
77 * @param layerId The layer this entity belongs to.
78 *
79 * @return Reference to this config for chaining.
80 */
81 CollisionConfig& layerId(const uint32_t layerId) {
82
83 ensureCollisionComponent(false);
84
86
87 return *this;
88 }
89
90 /**
91 * @brief Sets the hit policy for collision detection.
92 *
93 * @details Controls how many collision events this entity receives per frame:
94 * - `OneHit`: Only the first collision is reported (default)
95 * - `All`: All collisions with overlapping entities are reported
96 *
97 * @param hitPolicy The hit policy to apply.
98 *
99 * @return Reference to this config for chaining.
100 *
101 * @see HitPolicy
102 */
104
105 ensureCollisionComponent(true);
106
108 ->setHitPolicy(hitPolicy);
109
110 return *this;
111 }
112
113 /**
114 * @brief Sets whether this entity reports collisions.
115 *
116 * @param isCollisionReporter True to generate collision events.
117 *
118 * @return Reference to this config for chaining.
119 */
120 CollisionConfig& reportCollisions(bool isCollisionReporter) {
121
122 ensureCollisionComponent(true);
123
125 ->setIsCollisionReporter(isCollisionReporter);
126 return *this;
127 }
128
129 /**
130 * @brief Sets the solid collision mask.
131 *
132 * @param solidCollisionMask Bitmask of layers to collide with.
133 *
134 * @return Reference to this config for chaining.
135 */
137 ensureCollisionComponent(true);
138
140 ->setSolidCollisionMask(solidCollisionMask);
141 return *this;
142 }
143
144 /**
145 * @brief Adds a collision behavior for a specific layer.
146 *
147 * @param otherLayerId The layer to respond to.
148 * @param collisionBehavior The behavior when colliding.
149 *
150 * @return Reference to this config for chaining.
151 */
153 const uint32_t otherLayerId,
155 ) {
156 ensureCollisionComponent(true);
157
159 ->addSolidCollisionBehavior(collisionBehavior, otherLayerId);
160
161 return *this;
162 }
163
164 /**
165 * @brief Configures damage dealing on collision with a specific layer.
166 *
167 * Adds or updates a DamageDealerComponent to deal the specified damage
168 * when colliding with entities on the given layer.
169 *
170 * @param damageAmount The amount of damage to deal.
171 * @param otherLayerId The layer to deal damage to.
172 *
173 * @return Reference to this config for chaining.
174 */
176 const float damageAmount,
177 const uint32_t otherLayerId
178 ) {
179 ensureCollisionComponent(true);
180
182 .setDamage(damageAmount, otherLayerId);
183
184 return *this;
185 }
186
187 };
188
189}
190

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.