Skip to main content

SceneNodeComponent.ixx File

Component for linking GameObjects to the scene graph. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespacemodules

Domain-specific components and systems. More...

namespacescene

Scene graph integration for game entities. More...

namespacecomponents

Scene graph integration components. More...

Classes Index

classSceneNodeComponent

Component that links a GameObject to a SceneNode in the scene graph. More...

Description

Component for linking GameObjects to the scene graph.

File Listing

The file content with the documentation metadata removed is:

1/**
2* @file SceneNodeComponent.ixx
3 * @brief Component for linking GameObjects to the scene graph.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9
10
11export module helios.engine.modules.scene.components.SceneNodeComponent;
12
13import helios.scene.SceneNode;
14import helios.math.types;
15import helios.core.units.Unit;
16
17
18import helios.engine.ecs.GameObject;
19
20import helios.engine.modules.rendering.renderable.components.RenderableComponent;
21
22
24
25 /**
26 * @brief Component that links a GameObject to a SceneNode in the scene graph.
27 *
28 * @details
29 * This component bridges the game logic layer (GameObject) with the rendering layer (SceneNode).
30 * It captures the initial AABB from the SceneNode's mesh (if available) and exposes
31 * the underlying SceneNode for other components to use.
32 *
33 * @note The SceneNode must remain valid for the lifetime of this component.
34 */
36
37 protected:
38
39 /**
40 * @brief Non-owning pointer to the associated SceneNode.
41 */
43
44 /**
45 * @brief Whether this component is enabled.
46 */
47 bool isEnabled_ = true;
48
49 public:
50
51 /**
52 * @brief Checks whether this component is enabled.
53 *
54 * @return True if enabled, false otherwise.
55 */
56 [[nodiscard]] bool isEnabled() const noexcept {
57 return isEnabled_;
58 }
59
60 /**
61 * @brief Enables this component.
62 */
63 void enable() noexcept {
64 isEnabled_ = true;
65 }
66
67 /**
68 * @brief Disables this component.
69 */
70 void disable() noexcept {
71 isEnabled_ = false;
72 }
73
74 /**
75 * @brief Called when the owning GameObject is activated.
76 *
77 * @details Activates the SceneNode, making it visible in the scene graph.
78 */
79 void onActivate() noexcept {
80 sceneNode_->setActive(true);
81 }
82
83 /**
84 * @brief Called when the owning GameObject is deactivated.
85 *
86 * @details Deactivates the SceneNode, hiding it from the scene graph.
87 */
88 void onDeactivate() noexcept {
89 sceneNode_->setActive(false);
90 }
91
92
93
94 /**
95 * @brief Constructs a SceneNodeComponent linked to a SceneNode.
96 *
97 * @param sceneNode Pointer to the SceneNode to control. Must not be nullptr.
98 */
101
102 assert(sceneNode_ != nullptr && "sceneNode must not be nullptr");
103 }
104
105 /**
106 * @brief Copy constructor.
107 *
108 * @details Copies the SceneNode pointer. The actual SceneNode cloning
109 * is handled by onClone() during entity cloning.
110 */
111 SceneNodeComponent(const SceneNodeComponent& other) = default;
112
113 /**
114 * @brief Copy assignment operator.
115 */
117
118 /**
119 * @brief Move constructor.
120 */
122
123 /**
124 * @brief Move assignment operator.
125 */
126 SceneNodeComponent& operator=(SceneNodeComponent&&) noexcept = default;
127
128 /**
129 * @brief Called after copy construction during entity cloning.
130 *
131 * @details Creates a new SceneNode for this entity by cloning the source's
132 * renderable and adding it to the same parent node. This ensures each
133 * cloned entity has its own SceneNode in the scene graph.
134 *
135 * @param other The source component to clone from.
136 */
137 void onClone(const SceneNodeComponent& other) {
138
139
140 auto* parent = other.sceneNode_->parent();
141
142 assert(parent != nullptr && "unexpected nullptr for SceneNode's parent");
143
144 auto sceneNode = std::make_unique<helios::scene::SceneNode>(other.sceneNode_->shareRenderable());
145
146 sceneNode_ = parent->addNode(std::move(sceneNode));
147 }
148
149
150 /**
151 * @brief Returns the underlying SceneNode.
152 *
153 * @return Non-owning pointer to the associated SceneNode.
154 */
155 [[nodiscard]] helios::scene::SceneNode* sceneNode() const noexcept {
156 return sceneNode_;
157 }
158 };
159
160
161}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.