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

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

#include <actor.hpp>

Public Member Functions

 Actor (Scene &scene)
 Constructs an Actor associated with a Scene. More...
 
virtual ~Actor ()
 
virtual void Initialize ()
 Initializes the actor after creation. More...
 
void SetPosition (const glm::vec3 &position)
 Sets the actor's position in world space. More...
 
void SetRotation (const glm::vec3 &rotation)
 Sets the actor's rotation in degrees. More...
 
void SetScale (const glm::vec3 &scale)
 Sets the actor's scale along each axis. More...
 
const glm::vec3 & GetPosition () const
 Gets the actor's position. More...
 
const glm::vec3 & GetRotation () const
 Gets the actor's rotation (pitch, yaw, roll in degrees). More...
 
const glm::vec3 & GetScale () const
 Gets the actor's scale. More...
 
SceneComponentGetTransform ()
 Access to the underlying SceneComponent (transform). More...
 
const SceneComponentGetTransform () 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 actor. More...
 
bool IsPendingDestroy () const
 Indicates whether this actor is scheduled for destruction. More...
 
 Actor (const Actor &)=delete
 
Actoroperator= (const Actor &)=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 drawable subobject to this actor. More...
 
template<>
StaticMeshCreateSubobject (StaticMeshParams params)
 

Protected Attributes

SceneComponent mRootComponent
 
bool bUpdateOnTick
 
bool bPendingDestroy = false
 

Friends

class Scene
 

Detailed Description

Base class representing a 3D entity within a Scene.

An Actor encapsulates:

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

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

Transformations applied to the Actor propagate to all attached drawable subobjects via hierarchical SceneComponent attachment.

Note
  • Actors operate in the 3D domain and use SceneComponent.
  • Destruction is deferred and handled safely by Scene.
See also
Scene, SceneComponent, Drawable3D

Definition at line 40 of file actor.hpp.

Constructor & Destructor Documentation

◆ Actor() [1/2]

rendering_engine::Actor::Actor ( Scene scene)

Constructs an Actor associated with a Scene.

The Scene becomes the owner of this Actor. The root SceneComponent is initialized with identity transform.

Parameters
sceneReference to the owning Scene.

Definition at line 9 of file actor.cpp.

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

◆ ~Actor()

rendering_engine::Actor::~Actor ( )
virtual

Definition at line 17 of file actor.cpp.

18{
19}

◆ Actor() [2/2]

rendering_engine::Actor::Actor ( const Actor )
delete

Member Function Documentation

◆ CreateSubobject() [1/2]

template<>
StaticMesh * rendering_engine::Actor::CreateSubobject ( StaticMeshParams  params)
protected

Definition at line 17 of file create_actor_subobject.hpp.

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

◆ CreateSubobject() [2/2]

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

Creates and attaches a 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 Drawable3D).
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::Actor::Destroy ( )

Requests deferred destruction of this 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 pending destruction queue.
Note

Definition at line 79 of file actor.cpp.

80{
82 return;
83
84 bPendingDestroy = true;
85
86 // Detach wards while they are still valid objects
87 for (auto* ward : mWards)
88 {
89 if (ward)
90 ward->GetTransform().AttachTo(nullptr);
91 }
92
93 // Now schedule ward destruction
94 for (auto* ward : mWards)
95 {
96 if (ward)
97 ward->Destroy();
98 }
99
100 mScene.DestroyActor(this);
101}
void DestroyActor(Actor *actor)
Schedules a 3D actor for deferred destruction.
Definition: scene.cpp:159

◆ GetPosition()

const glm::vec3 & rendering_engine::Actor::GetPosition ( ) const

Gets the actor's position.

Definition at line 41 of file actor.cpp.

42{
44}
SceneComponent mRootComponent
Definition: actor.hpp:190
const glm::vec3 & GetPosition() const
Gets the current position.

◆ GetRenderContext()

RenderResourceContext rendering_engine::Actor::GetRenderContext ( ) const

Returns the render resource context associated with this actor.

This context provides access to renderer-level resources required by attached drawable components.

Returns
RenderResourceContext for this actor.

Definition at line 74 of file actor.cpp.

75{
76 return mRenderContext;
77}

◆ GetRotation()

const glm::vec3 & rendering_engine::Actor::GetRotation ( ) const

Gets the actor's rotation (pitch, yaw, roll in degrees).

Definition at line 46 of file actor.cpp.

47{
49}
const glm::vec3 & GetRotation() const
Gets the current rotation as Euler angles (in radians).

◆ GetScale()

const glm::vec3 & rendering_engine::Actor::GetScale ( ) const

Gets the actor's scale.

Definition at line 51 of file actor.cpp.

52{
53 return mRootComponent.GetScale();
54}
const glm::vec3 & GetScale() const
Gets the current scale.

◆ GetTransform() [1/2]

SceneComponent & rendering_engine::Actor::GetTransform ( )

Access to the underlying SceneComponent (transform).

Definition at line 56 of file actor.cpp.

57{
58 return mRootComponent;
59}

◆ GetTransform() [2/2]

const SceneComponent & rendering_engine::Actor::GetTransform ( ) const

Definition at line 61 of file actor.cpp.

62{
63 return mRootComponent;
64}

◆ Initialize()

void rendering_engine::Actor::Initialize ( )
virtual

Initializes the actor after creation.

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

  • Create drawable subobjects
  • Attach components
  • Set initial transforms

Definition at line 21 of file actor.cpp.

22{
23}

◆ IsPendingDestroy()

bool rendering_engine::Actor::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 151 of file actor.hpp.

151{ return bPendingDestroy; }

◆ operator=()

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

◆ SetPosition()

void rendering_engine::Actor::SetPosition ( const glm::vec3 &  position)

Sets the actor's position in world space.

Parameters
positionNew position vector (x, y, z).

Definition at line 25 of file actor.cpp.

26{
28}
void SetPosition(const glm::vec3 &position)
Sets the position of the component in world space.

◆ SetRotation()

void rendering_engine::Actor::SetRotation ( const glm::vec3 &  rotation)

Sets the actor's rotation in degrees.

Parameters
rotationNew rotation vector (pitch, yaw, roll), in degrees.

Definition at line 30 of file actor.cpp.

31{
33
34}
void SetRotation(const glm::quat &rotation)
Sets the rotation using a quaternion.

◆ SetScale()

void rendering_engine::Actor::SetScale ( const glm::vec3 &  scale)

Sets the actor's scale along each axis.

Parameters
scaleNew scale vector (x, y, z).

Definition at line 36 of file actor.cpp.

37{
39}
void SetScale(const glm::vec3 &scale)
Sets the scale for each dimension.

◆ Shutdown()

void rendering_engine::Actor::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
This is part of the deferred destruction pipeline.

Definition at line 103 of file actor.cpp.

104{
105 mWards.clear();
106
107 mRootComponent.AttachTo(nullptr);
108}
void AttachTo(SceneComponent *parent)
Attaches this scene component to a parent scene component.

◆ Update()

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

Updates actor logic and root transform state.

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

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

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

Parameters
deltaTimeTime elapsed since last frame (seconds).

Definition at line 66 of file actor.cpp.

67{
68 if (!bUpdateOnTick)
69 return;
70
72}

Friends And Related Function Documentation

◆ Scene

friend class Scene
friend

Definition at line 42 of file actor.hpp.

Member Data Documentation

◆ bPendingDestroy

bool rendering_engine::Actor::bPendingDestroy = false
protected

Definition at line 193 of file actor.hpp.

◆ bUpdateOnTick

bool rendering_engine::Actor::bUpdateOnTick
protected

Definition at line 191 of file actor.hpp.

◆ mRootComponent

SceneComponent rendering_engine::Actor::mRootComponent
protected

Definition at line 190 of file actor.hpp.


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