Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::Actor2D Class Reference

Base class representing a 2D entity within a Scene. More...

#include <actor_2d.hpp>

Inherited by rendering_engine::StatsOverlay.

Public Member Functions

 Actor2D (Scene &scene)
 Constructs a 2D actor associated with a Scene. More...
 
virtual ~Actor2D ()
 
virtual void Initialize ()
 Initializes the actor after creation. More...
 
void SetPosition (const glm::vec2 &position)
 Sets the actor's position in world space. More...
 
void SetRotation (float angleDegrees)
 Sets the actor's rotation in degrees. More...
 
void SetScale (const glm::vec2 &scale)
 Sets the actor's scale along each axis. More...
 
const glm::vec2 & GetPosition () const
 Gets the actor 2d position. More...
 
float GetRotation () const
 Gets the actor 2d rotation angle (degrees). More...
 
const glm::vec2 & GetScale () const
 Gets the actor 2d scale. More...
 
SceneComponent2DGetTransform ()
 Access to the underlying SceneComponent2D (transform). More...
 
const SceneComponent2DGetTransform () const
 
virtual void Update (float deltaTime)
 Updates actor logic and root transform state. More...
 
RenderResourceContext GetRenderContext () const
 Returns the render resource context associated with this actor. More...
 
void Destroy ()
 Requests deferred destruction of this 2D actor. More...
 
bool IsPendingDestroy () const
 Indicates whether this actor is scheduled for destruction. More...
 
 Actor2D (const Actor2D &)=delete
 
Actor2Doperator= (const Actor2D &)=delete
 

Protected Member Functions

virtual void Shutdown ()
 Performs internal cleanup before destruction. More...
 
template<typename T , typename V >
T * CreateSubobject (V arg)
 Creates and attaches a 2D drawable subobject to this actor. More...
 
SceneGetScene ()
 Returns the owning Scene. More...
 
template<>
Rectangle2DCreateSubobject (Rectangle2D::Properties prop)
 
template<>
TextBlock2DCreateSubobject (TextBlock2D::Properties prop)
 

Protected Attributes

SceneComponent2D mRootComponent
 
bool bUpdateOnTick
 
bool bPendingDestroy = false
 

Friends

class Scene
 

Detailed Description

Base class representing a 2D entity within a Scene.

Actor2D encapsulates:

  • A root SceneComponent2D defining its 2D transform.
  • A collection of attached 2D drawable subobjects.
  • Per-frame update logic.
  • Deferred destruction lifecycle integration with Scene.

Actor2D operates strictly in the 2D domain:

  • Position is defined in (x, y).
  • Rotation is a single angle (degrees) around the Z-axis.
  • Scale is defined in (x, y).

Transformations applied to the Actor2D propagate to all attached drawable subobjects via hierarchical SceneComponent2D attachment.

Actors are owned and lifetime-managed by the Scene that spawns them. They must not be manually deleted.

Note
  • Actor2D is conceptually separated from Actor (3D).
  • Destruction is deferred and handled safely by Scene.
See also
Scene, SceneComponent2D, Drawable2D, Actor

Definition at line 45 of file actor_2d.hpp.

Constructor & Destructor Documentation

◆ Actor2D() [1/2]

rendering_engine::Actor2D::Actor2D ( Scene scene)

Constructs a 2D actor associated with a Scene.

The Scene becomes the owner of this actor. The root SceneComponent2D is initialized with identity transform.

Parameters
sceneReference to the owning Scene.

Definition at line 8 of file actor_2d.cpp.

9 :
10 mScene(scene),
11 bUpdateOnTick(true)
12{
13 mRenderContext = mScene.GetSceneManager().GetRenderResourceContext();
14}
RenderResourceContext GetRenderResourceContext() const
Retrieves the current RenderResourceContext.
SceneManager & GetSceneManager()
Gets a reference to the SceneManager that owns this scene.
Definition: scene.cpp:129

◆ ~Actor2D()

rendering_engine::Actor2D::~Actor2D ( )
virtual

Definition at line 16 of file actor_2d.cpp.

17{
18}

◆ Actor2D() [2/2]

rendering_engine::Actor2D::Actor2D ( const Actor2D )
delete

Member Function Documentation

◆ CreateSubobject() [1/3]

template<>
Rectangle2D * rendering_engine::Actor2D::CreateSubobject ( Rectangle2D::Properties  prop)
protected

Definition at line 17 of file create_actor_2d_subobject.hpp.

18{
19 auto rectangle2D = mScene.Spawn<Rectangle2D>(prop);
20 mWards.push_back(rectangle2D);
21 rectangle2D->UpdateOnTick(bUpdateOnTick);
22
23 return rectangle2D;
24}
T * Spawn(V arg)
Spawns and registers a drawable of type T.

◆ CreateSubobject() [2/3]

template<>
TextBlock2D * rendering_engine::Actor2D::CreateSubobject ( TextBlock2D::Properties  prop)
protected

Definition at line 27 of file create_actor_2d_subobject.hpp.

28{
29 auto textBlock2D = mScene.Spawn<TextBlock2D>(prop);
30 mWards.push_back(textBlock2D);
31 textBlock2D->UpdateOnTick(bUpdateOnTick);
32
33 return textBlock2D;
34}

◆ CreateSubobject() [3/3]

template<typename T , typename V >
T * rendering_engine::Actor2D::CreateSubobject ( arg)
protected

Creates and attaches a 2D drawable subobject to this actor.

This helper function delegates creation to the owning Scene, registers the drawable for lifetime management, and stores it as a ward (child drawable) of the actor.

Template Parameters
TDrawable type (must derive from Drawable2D).
VConstruction parameter type.
Parameters
argArgument forwarded to Scene::Spawn().
Returns
Pointer to the created drawable subobject.
Note
  • The drawable is owned by the Scene.
  • The actor keeps a non-owning reference in mWards.
  • Destruction is automatically handled when the actor is destroyed.

◆ Destroy()

void rendering_engine::Actor2D::Destroy ( )

Requests deferred destruction of this 2D actor.

Marks the actor as pending destroy and schedules safe removal via the owning Scene.

The actor is not deleted immediately. Instead:

  • Attached drawable subobjects are detached and scheduled for destruction.
  • The actor is added to the Scene's 2D pending destruction queue.
Note

Definition at line 77 of file actor_2d.cpp.

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}
void DestroyActor(Actor *actor)
Schedules a 3D actor for deferred destruction.
Definition: scene.cpp:159

◆ GetPosition()

const glm::vec2 & rendering_engine::Actor2D::GetPosition ( ) const

Gets the actor 2d position.

Definition at line 39 of file actor_2d.cpp.

40{
42}
SceneComponent2D mRootComponent
Definition: actor_2d.hpp:207
const glm::vec2 & GetPosition() const
Gets the current position.

◆ GetRenderContext()

RenderResourceContext rendering_engine::Actor2D::GetRenderContext ( ) const

Returns the render resource context associated with this actor.

Provides access to renderer-level resources required by attached 2D drawable components.

Returns
RenderResourceContext for this actor.

Definition at line 72 of file actor_2d.cpp.

73{
74 return mRenderContext;
75}

◆ GetRotation()

float rendering_engine::Actor2D::GetRotation ( ) const

Gets the actor 2d rotation angle (degrees).

Definition at line 44 of file actor_2d.cpp.

45{
47}
float GetRotation() const
Gets the current rotation angle (in degrees).

◆ GetScale()

const glm::vec2 & rendering_engine::Actor2D::GetScale ( ) const

Gets the actor 2d scale.

Definition at line 49 of file actor_2d.cpp.

50{
51 return mRootComponent.GetScale();
52}
const glm::vec2 & GetScale() const
Gets the current scale.

◆ GetScene()

Scene & rendering_engine::Actor2D::GetScene ( )
protected

Returns the owning Scene.

Provides access to the scene that contains this actor.

Returns
Reference to the parent Scene.

Definition at line 108 of file actor_2d.cpp.

109{
110 return mScene;
111}

◆ GetTransform() [1/2]

SceneComponent2D & rendering_engine::Actor2D::GetTransform ( )

Access to the underlying SceneComponent2D (transform).

Allows direct manipulation of local or hierarchical transforms.

Returns
Reference to the root 2D transform component.

Definition at line 54 of file actor_2d.cpp.

55{
56 return mRootComponent;
57}

◆ GetTransform() [2/2]

const SceneComponent2D & rendering_engine::Actor2D::GetTransform ( ) const

Definition at line 59 of file actor_2d.cpp.

60{
61 return mRootComponent;
62}

◆ Initialize()

void rendering_engine::Actor2D::Initialize ( )
virtual

Initializes the actor after creation.

Called automatically by Scene::SpawnActor2D(). Derived classes should override this method to:

  • Create drawable subobjects
  • Attach components
  • Set initial transforms

Reimplemented in rendering_engine::StatsOverlay.

Definition at line 20 of file actor_2d.cpp.

21{
22}

◆ IsPendingDestroy()

bool rendering_engine::Actor2D::IsPendingDestroy ( ) const
inline

Indicates whether this actor is scheduled for destruction.

Returns
True if Destroy() has been called and the actor is awaiting removal.

Definition at line 160 of file actor_2d.hpp.

160{ return bPendingDestroy; }

◆ operator=()

Actor2D & rendering_engine::Actor2D::operator= ( const Actor2D )
delete

◆ SetPosition()

void rendering_engine::Actor2D::SetPosition ( const glm::vec2 &  position)

Sets the actor's position in world space.

Parameters
positionNew position vector (x, y).

Definition at line 24 of file actor_2d.cpp.

25{
27}
void SetPosition(const glm::vec2 &position)
Sets the local position of this component.

◆ SetRotation()

void rendering_engine::Actor2D::SetRotation ( float  angleDegrees)

Sets the actor's rotation in degrees.

Parameters
angleDegreesRotation angle in degrees (counterclockwise).

Rotation is applied around the Z-axis.

Definition at line 29 of file actor_2d.cpp.

30{
31 mRootComponent.SetRotation(angleDegrees);
32}
void SetRotation(float angleDegrees)
Sets the rotation angle in degrees.

◆ SetScale()

void rendering_engine::Actor2D::SetScale ( const glm::vec2 &  scale)

Sets the actor's scale along each axis.

Parameters
scaleNew scale vector (x, y).

Definition at line 34 of file actor_2d.cpp.

35{
37}
void SetScale(const glm::vec2 &scale)
Sets the scale in each dimension.

◆ Shutdown()

void rendering_engine::Actor2D::Shutdown ( )
protectedvirtual

Performs internal cleanup before destruction.

Called by Scene during the destruction flush phase. Derived classes may override this to release resources, but must not delete the actor manually.

Note
Part of the deferred destruction pipeline.

Definition at line 101 of file actor_2d.cpp.

102{
103 mWards.clear();
104
105 mRootComponent.AttachTo(nullptr);
106}
void AttachTo(SceneComponent2D *parent)
Attaches this scene component to a parent scene component.

◆ Update()

void rendering_engine::Actor2D::Update ( float  deltaTime)
virtual

Updates actor logic and root transform state.

Called once per frame by Scene::Update().

The base implementation updates the root SceneComponent2D's world matrix if ticking is enabled.

Derived classes should call Actor2D::Update(deltaTime) before or after custom logic as appropriate.

Parameters
deltaTimeTime elapsed since last frame (seconds).

Reimplemented in rendering_engine::StatsOverlay.

Definition at line 64 of file actor_2d.cpp.

65{
66 if (!bUpdateOnTick)
67 return;
68
70}
void UpdateWorldMatrix()
Recomputes the world transformation matrix.

Friends And Related Function Documentation

◆ Scene

friend class Scene
friend

Definition at line 47 of file actor_2d.hpp.

Member Data Documentation

◆ bPendingDestroy

bool rendering_engine::Actor2D::bPendingDestroy = false
protected

Definition at line 210 of file actor_2d.hpp.

◆ bUpdateOnTick

bool rendering_engine::Actor2D::bUpdateOnTick
protected

Definition at line 208 of file actor_2d.hpp.

◆ mRootComponent

SceneComponent2D rendering_engine::Actor2D::mRootComponent
protected

Definition at line 207 of file actor_2d.hpp.


The documentation for this class was generated from the following files: