Rendering Engine
0.2.9
Modular Graphics Rendering Engine | v0.2.9
actor.hpp
Go to the documentation of this file.
1
// This file is part of the Rendering Engine project.
2
// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3
// Copyright (c) 2026 Alexander Obzherin
4
// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6
#pragma once
7
8
#include "
rendering_engine_export.hpp
"
9
#include "
drawable_component.hpp
"
10
#include "
scene_component.hpp
"
11
12
namespace
rendering_engine
13
{
14
15
class
DrawableComponent
;
16
class
Drawable3D
;
17
18
/**
19
* @class Actor
20
* @brief Base class representing a 3D entity within a Scene.
21
*
22
* An Actor encapsulates:
23
* - A root SceneComponent defining its world transform.
24
* - A collection of attached 3D drawable subobjects.
25
* - Per-frame update logic.
26
* - Deferred destruction lifecycle integration with Scene.
27
*
28
* Actors are owned and lifetime-managed by the Scene that spawns them.
29
* They must not be manually deleted.
30
*
31
* Transformations applied to the Actor propagate to all attached
32
* drawable subobjects via hierarchical SceneComponent attachment.
33
*
34
* @note
35
* - Actors operate in the 3D domain and use SceneComponent.
36
* - Destruction is deferred and handled safely by Scene.
37
*
38
* @see Scene, SceneComponent, Drawable3D
39
*/
40
class
RE_API
Actor
41
{
42
friend
class
Scene
;
43
public
:
44
/**
45
* @brief Constructs an Actor associated with a Scene.
46
*
47
* The Scene becomes the owner of this Actor.
48
* The root SceneComponent is initialized with identity transform.
49
*
50
* @param scene Reference to the owning Scene.
51
*/
52
Actor
(
Scene
& scene);
53
54
virtual
~Actor
();
55
56
/**
57
* @brief Initializes the actor after creation.
58
*
59
* Called automatically by Scene::SpawnActor().
60
* Derived classes should override this method to:
61
* - Create drawable subobjects
62
* - Attach components
63
* - Set initial transforms
64
*/
65
virtual
void
Initialize();
66
67
/**
68
* @brief Sets the actor's position in world space.
69
* @param position New position vector (x, y, z).
70
*/
71
void
SetPosition(
const
glm::vec3& position);
72
73
/**
74
* @brief Sets the actor's rotation in degrees.
75
* @param rotation New rotation vector (pitch, yaw, roll), in degrees.
76
*/
77
void
SetRotation(
const
glm::vec3& rotation);
78
79
/**
80
* @brief Sets the actor's scale along each axis.
81
* @param scale New scale vector (x, y, z).
82
*/
83
void
SetScale(
const
glm::vec3& scale);
84
85
/**
86
* @brief Gets the actor's position.
87
*/
88
const
glm::vec3& GetPosition()
const
;
89
90
/**
91
* @brief Gets the actor's rotation (pitch, yaw, roll in degrees).
92
*/
93
const
glm::vec3& GetRotation()
const
;
94
95
/**
96
* @brief Gets the actor's scale.
97
*/
98
const
glm::vec3& GetScale()
const
;
99
100
/**
101
* @brief Access to the underlying SceneComponent (transform).
102
*/
103
SceneComponent
& GetTransform();
104
const
SceneComponent
& GetTransform()
const
;
105
///@}
106
107
/**
108
* @brief Updates actor logic and root transform state.
109
*
110
* Called once per frame by Scene::Update().
111
*
112
* The base implementation updates the root SceneComponent's
113
* world matrix if ticking is enabled.
114
*
115
* Derived classes should call Actor::Update(deltaTime)
116
* before or after custom logic as appropriate.
117
*
118
* @param deltaTime Time elapsed since last frame (seconds).
119
*/
120
virtual
void
Update(
float
deltaTime);
121
/**
122
* @brief Returns the render resource context associated with this actor.
123
*
124
* This context provides access to renderer-level resources
125
* required by attached drawable components.
126
*
127
* @return RenderResourceContext for this actor.
128
*/
129
RenderResourceContext
GetRenderContext()
const
;
130
/**
131
* @brief Requests deferred destruction of this actor.
132
*
133
* Marks the actor as pending destroy and schedules safe removal
134
* via the owning Scene.
135
*
136
* The actor is not deleted immediately. Instead:
137
* - Attached drawable subobjects are detached and scheduled for destruction.
138
* - The actor is added to the Scene's pending destruction queue.
139
*
140
* @note
141
* - Do not manually delete actors.
142
* - After calling Destroy(), IsPendingDestroy() will return true.
143
* - Actual deletion occurs during Scene's flush phase.
144
*/
145
void
Destroy();
146
/**
147
* @brief Indicates whether this actor is scheduled for destruction.
148
*
149
* @return True if Destroy() has been called and the actor is awaiting removal.
150
*/
151
bool
IsPendingDestroy
()
const
{
return
bPendingDestroy; }
152
153
Actor
(
const
Actor
&) =
delete
;
154
Actor
&
operator=
(
const
Actor
&) =
delete
;
155
156
protected
:
157
/**
158
* @brief Performs internal cleanup before destruction.
159
*
160
* Called by Scene during the destruction flush phase.
161
* Derived classes may override this to release resources,
162
* but must not delete the actor manually.
163
*
164
* @note This is part of the deferred destruction pipeline.
165
*/
166
virtual
void
Shutdown();
167
168
/**
169
* @brief Creates and attaches a drawable subobject to this actor.
170
*
171
* This helper function delegates creation to the owning Scene,
172
* registers the drawable for lifetime management, and stores it
173
* as a ward (child drawable) of the actor.
174
*
175
* @tparam T Drawable type (must derive from Drawable3D).
176
* @tparam V Construction parameter type.
177
* @param arg Argument forwarded to Scene::Spawn().
178
*
179
* @return Pointer to the created drawable subobject.
180
*
181
* @note
182
* - The drawable is owned by the Scene.
183
* - The actor keeps a non-owning reference in mWards.
184
* - Destruction is automatically handled when the actor is destroyed.
185
*/
186
template
<
typename
T,
typename
V>
187
T*
CreateSubobject
(V arg);
188
189
protected
:
190
SceneComponent
mRootComponent
;
191
bool
bUpdateOnTick
;
192
193
bool
bPendingDestroy =
false
;
194
195
private
:
196
Scene
& mScene;
197
RenderResourceContext
mRenderContext;
198
std::vector<Drawable3D*> mWards;
199
200
};
201
202
}
// namespace rendering_engine
rendering_engine::Actor
Base class representing a 3D entity within a Scene.
Definition:
actor.hpp:41
rendering_engine::Actor::IsPendingDestroy
bool IsPendingDestroy() const
Indicates whether this actor is scheduled for destruction.
Definition:
actor.hpp:151
rendering_engine::Actor::mRootComponent
SceneComponent mRootComponent
Definition:
actor.hpp:190
rendering_engine::Actor::bUpdateOnTick
bool bUpdateOnTick
Definition:
actor.hpp:191
rendering_engine::Actor::Actor
Actor(const Actor &)=delete
rendering_engine::Actor::CreateSubobject
T * CreateSubobject(V arg)
Creates and attaches a drawable subobject to this actor.
rendering_engine::Actor::operator=
Actor & operator=(const Actor &)=delete
rendering_engine::Drawable3D
3D drawable component for rendering objects in 3D space.
Definition:
drawable_3d.hpp:27
rendering_engine::DrawableComponent
Abstract base for all drawable (renderable) objects in the engine.
Definition:
drawable_component.hpp:48
rendering_engine::SceneComponent
Represents a 3D transformable scene component with position, rotation, and scale.
Definition:
scene_component.hpp:43
rendering_engine::Scene
Base class representing a renderable scene.
Definition:
scene.hpp:44
drawable_component.hpp
rendering_engine
Definition:
actor.hpp:13
rendering_engine_export.hpp
RE_API
#define RE_API
Definition:
rendering_engine_export.hpp:10
scene_component.hpp
rendering_engine::RenderResourceContext
Aggregates pointers to global rendering resource managers.
Definition:
render_resource_context.hpp:26
RenderingEngine
RenderingLibrary
Include
actor.hpp
Generated by
1.9.4