Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
actor_2d.cpp
Go to the documentation of this file.
1#include "actor_2d.hpp"
2#include "scene.hpp"
3#include "scene_manager.hpp"
4#include "drawable_2d.hpp"
5
6namespace rendering_engine
7{
9 :
10 mScene(scene),
11 bUpdateOnTick(true)
12{
13 mRenderContext = mScene.GetSceneManager().GetRenderResourceContext();
14}
15
17{
18}
19
21{
22}
23
24void Actor2D::SetPosition(const glm::vec2& position)
25{
27}
28
29void Actor2D::SetRotation(float angleDegrees)
30{
31 mRootComponent.SetRotation(angleDegrees);
32}
33
34void Actor2D::SetScale(const glm::vec2& scale)
35{
37}
38
39const glm::vec2& Actor2D::GetPosition() const
40{
42}
43
45{
47}
48
49const glm::vec2& Actor2D::GetScale() const
50{
51 return mRootComponent.GetScale();
52}
53
55{
56 return mRootComponent;
57}
58
60{
61 return mRootComponent;
62}
63
64void Actor2D::Update(float deltaTime)
65{
66 if (!bUpdateOnTick)
67 return;
68
70}
71
73{
74 return mRenderContext;
75}
76
78{
80 return;
81
82 bPendingDestroy = true;
83
84 // Detach wards while they are still valid objects
85 for (auto* ward : mWards)
86 {
87 if (ward)
88 ward->GetTransform().AttachTo(nullptr);
89 }
90
91 // Now schedule ward destruction
92 for (auto* ward : mWards)
93 {
94 if (ward)
95 ward->Destroy();
96 }
97
98 mScene.DestroyActor(this);
99}
100
102{
103 mWards.clear();
104
105 mRootComponent.AttachTo(nullptr);
106}
107
109{
110 return mScene;
111}
112
113
114
115
116} // namespace rendering_engine
SceneComponent2D mRootComponent
Definition: actor_2d.hpp:207
virtual void Update(float deltaTime)
Updates actor logic and root transform state.
Definition: actor_2d.cpp:64
virtual void Initialize()
Initializes the actor after creation.
Definition: actor_2d.cpp:20
Scene & GetScene()
Returns the owning Scene.
Definition: actor_2d.cpp:108
const glm::vec2 & GetScale() const
Gets the actor 2d scale.
Definition: actor_2d.cpp:49
SceneComponent2D & GetTransform()
Access to the underlying SceneComponent2D (transform).
Definition: actor_2d.cpp:54
void SetScale(const glm::vec2 &scale)
Sets the actor's scale along each axis.
Definition: actor_2d.cpp:34
void Destroy()
Requests deferred destruction of this 2D actor.
Definition: actor_2d.cpp:77
float GetRotation() const
Gets the actor 2d rotation angle (degrees).
Definition: actor_2d.cpp:44
Actor2D(Scene &scene)
Constructs a 2D actor associated with a Scene.
Definition: actor_2d.cpp:8
virtual void Shutdown()
Performs internal cleanup before destruction.
Definition: actor_2d.cpp:101
void SetPosition(const glm::vec2 &position)
Sets the actor's position in world space.
Definition: actor_2d.cpp:24
const glm::vec2 & GetPosition() const
Gets the actor 2d position.
Definition: actor_2d.cpp:39
void SetRotation(float angleDegrees)
Sets the actor's rotation in degrees.
Definition: actor_2d.cpp:29
RenderResourceContext GetRenderContext() const
Returns the render resource context associated with this actor.
Definition: actor_2d.cpp:72
Represents a hierarchical 2D transform component.
const glm::vec2 & GetScale() const
Gets the current scale.
void UpdateWorldMatrix()
Recomputes the world transformation matrix.
const glm::vec2 & GetPosition() const
Gets the current position.
void AttachTo(SceneComponent2D *parent)
Attaches this scene component to a parent scene component.
void SetScale(const glm::vec2 &scale)
Sets the scale in each dimension.
float GetRotation() const
Gets the current rotation angle (in degrees).
void SetRotation(float angleDegrees)
Sets the rotation angle in degrees.
void SetPosition(const glm::vec2 &position)
Sets the local position of this component.
RenderResourceContext GetRenderResourceContext() const
Retrieves the current RenderResourceContext.
Base class representing a renderable scene.
Definition: scene.hpp:44
SceneManager & GetSceneManager()
Gets a reference to the SceneManager that owns this scene.
Definition: scene.cpp:129
void DestroyActor(Actor *actor)
Schedules a 3D actor for deferred destruction.
Definition: scene.cpp:159
Aggregates pointers to global rendering resource managers.