Skip to main content

SpawnedByProfileComponent.ixx File

Component that tracks which spawn profile created a GameObject. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacespawn

Entity spawning and lifecycle management. More...

namespacecomponents

Components for spawn-related entity tracking. More...

Classes Index

classSpawnedByProfileComponent

Component that stores the spawn profile ID that created this GameObject. More...

Description

Component that tracks which spawn profile created a GameObject.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnedByProfileComponent.ixx
3 * @brief Component that tracks which spawn profile created a GameObject.
4 */
5module;
6
7export module helios.engine.mechanics.spawn.components.SpawnedByProfileComponent;
8
9
10import helios.engine.core.data.SpawnProfileId;
11import helios.core.types;
12
14
15 /**
16 * @brief Component that stores the spawn profile ID that created this GameObject.
17 *
18 * @details SpawnedByProfileComponent is attached to pooled GameObjects to track
19 * which spawn profile they belong to. This enables the despawn system to route
20 * release requests to the correct pool manager.
21 *
22 * The component is cloneable, allowing prefab-based pooling where the profile ID
23 * is set after cloning during the acquire phase.
24 *
25 * Example usage:
26 * ```cpp
27 * // During prefab setup
28 * auto prefab = gameWorld.addGameObject();
29 * prefab.add<SpawnedByProfileComponent>();
30 *
31 * // During spawn (in SpawnManager)
32 * auto* comp = entity.get<SpawnedByProfileComponent>();
33 * comp->setSpawnProfileId(profileId);
34 *
35 * // During despawn
36 * auto profileId = entity.get<SpawnedByProfileComponent>()->spawnProfileId();
37 * poolManager.release(profileId, entity.entityHandle());
38 * ```
39 *
40 * @see SpawnProfileId
41 * @see GameObjectPoolManager
42 */
44
45 /**
46 * @brief The spawn profile ID that created this entity.
47 *
48 * Default-initialized to 0, which represents an invalid/unassigned profile.
49 */
51
52 /**
53 * @brief Whether this component is enabled.
54 */
55 bool isEnabled_ = true;
56
57 public:
58
59 /**
60 * @brief Checks whether this component is enabled.
61 *
62 * @return True if enabled, false otherwise.
63 */
64 [[nodiscard]] bool isEnabled() const noexcept {
65 return isEnabled_;
66 }
67
68 /**
69 * @brief Enables this component.
70 */
71 void enable() noexcept {
72 isEnabled_ = true;
73 }
74
75 /**
76 * @brief Disables this component.
77 */
78 void disable() noexcept {
79 isEnabled_ = false;
80 }
81
82 /**
83 * @brief Default constructor.
84 */
86
87 /**
88 * @brief Copy constructor for cloning.
89 *
90 * @param other The component to copy from.
91 */
93 : spawnProfileId_(other.spawnProfileId_) {}
94
97 SpawnedByProfileComponent& operator=(SpawnedByProfileComponent&&) noexcept = default;
98
99 /**
100 * @brief Returns the spawn profile ID.
101 *
102 * @return The SpawnProfileId assigned to this entity.
103 */
104 [[nodiscard]] helios::engine::core::data::SpawnProfileId spawnProfileId() const noexcept {
105 return spawnProfileId_;
106 }
107
108 /**
109 * @brief Sets the spawn profile ID.
110 *
111 * @details Called by the spawn manager after acquiring an entity from the pool
112 * to associate it with the correct profile for later despawning.
113 *
114 * @param spawnProfileId The profile ID to assign.
115 */
117 spawnProfileId_ = spawnProfileId;
118 }
119
120 };
121
122}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.