Skip to main content

RenderableComponent.ixx File

Component for associating a renderable object with an entity. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespacemodules

Domain-specific components and systems. More...

namespacerendering

Rendering components for game entities. More...

namespacerenderable

Renderable entity components and systems. More...

namespacecomponents

Classes Index

classRenderableComponent

Component that holds a shared pointer to a Renderable resource. More...

Description

Component for associating a renderable object with an entity.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RenderableComponent.ixx
3 * @brief Component for associating a renderable object with an entity.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.modules.rendering.renderable.components.RenderableComponent;
11
12
13import helios.engine.ecs.GameObject;
14
15import helios.rendering.Renderable;
16import helios.math.types;
17
18import helios.engine.modules.rendering.model.components.ModelAabbComponent;
19
21
22 /**
23 * @brief Component that holds a shared pointer to a Renderable resource.
24 *
25 * @details
26 * This component links a GameObject to a visual representation (Renderable).
27 * When attached, it automatically extracts the AABB from the renderable's mesh
28 * and populates a ModelAabbComponent on the same GameObject.
29 */
31
32 /**
33 * @brief Shared pointer to the renderable resource.
34 */
35 std::shared_ptr<helios::rendering::Renderable> renderable_;
36
37 /**
38 * @brief The initial AABB of the model associated with the renderable.
39 */
41
42 /**
43 * @brief Whether this component is enabled.
44 */
45 bool isEnabled_ = true;
46
47 public:
48
49 /**
50 * @brief Checks whether this component is enabled.
51 *
52 * @return True if enabled, false otherwise.
53 */
54 [[nodiscard]] bool isEnabled() const noexcept {
55 return isEnabled_;
56 }
57
58 /**
59 * @brief Enables this component.
60 */
61 void enable() noexcept {
62 isEnabled_ = true;
63 }
64
65 /**
66 * @brief Disables this component.
67 */
68 void disable() noexcept {
69 isEnabled_ = false;
70 }
71
72 /**
73 * @brief Constructs a RenderableComponent.
74 *
75 * @param renderable Shared pointer to the Renderable. Must not be nullptr.
76 */
77 explicit RenderableComponent(std::shared_ptr<helios::rendering::Renderable> renderable) :
78 renderable_(std::move(renderable)) {
79
80 assert(renderable_ != nullptr && "renderable must not be nullptr");
81 aabb_ = renderable_->localAABB();
82
83 }
84
85 /**
86 * @brief Copy constructor.
87 *
88 * @details Copies the shared pointer to the Renderable. Both components
89 * will reference the same Renderable resource (shared ownership).
90 *
91 * @param other The component to copy from.
92 */
94 renderable_(other.renderable_), aabb_(other.aabb_) {}
95
96 /**
97 * @brief Copy assignment operator.
98 */
100
101 /**
102 * @brief Move constructor.
103 */
105
106 /**
107 * @brief Move assignment operator.
108 */
109 RenderableComponent& operator=(RenderableComponent&&) noexcept = default;
110
111
112
113 /**
114 * @brief Retrieves a shared pointer to the stored Renderable.
115 *
116 * @return Shared pointer to the Renderable.
117 */
118 [[nodiscard]] std::shared_ptr<helios::rendering::Renderable> shareRenderable() const noexcept {
119 return renderable_;
120 }
121
122 /**
123 * @brief Retrieves a const ref to the stored Renderable.
124 *
125 * @return Const ref to the Renderable (never null after construction).
126 */
127 [[nodiscard]] const helios::rendering::Renderable& renderable() const noexcept {
128 return *renderable_;
129 }
130
131
132
133 };
134
135
136}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.