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

Displays real-time frame statistics as a 2D overlay. More...

#include <stats_overlay.hpp>

Inherits rendering_engine::Actor2D.

Public Member Functions

 StatsOverlay (Scene &scene)
 Constructs a StatsOverlay actor. More...
 
void Initialize () override
 Creates and positions overlay visual elements. More...
 
void Update (float deltaTime) override
 Updates displayed statistics each frame. More...
 
- Public Member Functions inherited from rendering_engine::Actor2D
 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
 

Additional Inherited Members

- Protected Member Functions inherited from rendering_engine::Actor2D
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 inherited from rendering_engine::Actor2D
SceneComponent2D mRootComponent
 
bool bUpdateOnTick
 
bool bPendingDestroy = false
 

Detailed Description

Displays real-time frame statistics as a 2D overlay.

StatsOverlay renders a simple performance panel containing:

  • FPS
  • Frame duration (ms)
  • Update time (ms)
  • Draw time (ms)

The overlay is drawn in screen space using Rectangle2D and TextBlock2D subobjects. Values are updated every frame using FrameMetrics obtained from the active application.

Intended for debugging and performance diagnostics.

Definition at line 31 of file stats_overlay.hpp.

Constructor & Destructor Documentation

◆ StatsOverlay()

rendering_engine::StatsOverlay::StatsOverlay ( Scene scene)

Constructs a StatsOverlay actor.

Reads configuration options and prepares internal state.

Parameters
sceneReference to the owning scene.

Definition at line 16 of file stats_overlay.cpp.

17 :
18 Actor2D(scene),
19 mFPSLabel(nullptr),
20 mFPSValue(nullptr),
21 mFrameLabel(nullptr),
22 mFrameValue(nullptr),
23 mUpdateLabel(nullptr),
24 mUpdateValue(nullptr),
25 mDrawLabel(nullptr),
26 mDrawValue(nullptr)
27{
28 bUseSmoothedFPS = Utility::ReadConfigFile().useSmoothedFPS;
29}
Actor2D(Scene &scene)
Constructs a 2D actor associated with a Scene.
Definition: actor_2d.cpp:8
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
Definition: utility.cpp:34
bool useSmoothedFPS
Enable FPS smoothing and frame pacing behavior.
Definition: utility.hpp:43

Member Function Documentation

◆ Initialize()

void rendering_engine::StatsOverlay::Initialize ( )
overridevirtual

Creates and positions overlay visual elements.

Spawns background rectangle and label/value text blocks, attaches them to the root component, and arranges them in a two-column layout.

Reimplemented from rendering_engine::Actor2D.

Definition at line 31 of file stats_overlay.cpp.

32{
34
35 bUpdateOnTick = true;
36
38 tbProp.fontName = "RobotoMono-Medium";
39
40 const float vertDelta = 25.0f;
41 const float width = 140.0f;
42 const float pad = 5.0f;
43 const float height = vertDelta * 4;
44
45 Rectangle2D::Properties rectangleProp;
46 rectangleProp.color = mBgColor;
47 rectangleProp.size = { width, height };
48 mBackGround = CreateSubobject<Rectangle2D>(rectangleProp);
49 mBackGround->GetTransform().AttachTo(&mRootComponent);
50
51 const float middleX = width / 2.0f;
52 const float middleY = height / 2.0f;
53 const float column_0 = -middleX + pad;
54 const float column_1 = column_0 + middleX + pad;
55
56 const float row_0 = -middleY + tbProp.fontSize + pad;
57 const float row_1 = row_0 + vertDelta;
58 const float row_2 = row_1 + vertDelta;
59 const float row_3 = row_2 + vertDelta;
60
61 mFPSLabel = CreateSubobject<TextBlock2D>(tbProp);
63 mFPSLabel->SetText("FPS:");
64 mFPSLabel->SetPosition(glm::vec2(column_0, row_0));
65
66 mFPSValue = CreateSubobject<TextBlock2D>(tbProp);
68 mFPSValue->SetPosition(glm::vec2(column_1, row_0));
69
70 mFrameLabel = CreateSubobject<TextBlock2D>(tbProp);
71 mFrameLabel->GetTransform().AttachTo(&mRootComponent);
72 mFrameLabel->SetText("Frame:");
73 mFrameLabel->SetPosition(glm::vec2(column_0, row_1));
74
75 mFrameValue = CreateSubobject<TextBlock2D>(tbProp);
76 mFrameValue->GetTransform().AttachTo(&mRootComponent);
77 mFrameValue->SetPosition(glm::vec2(column_1, row_1));
78
79 mUpdateLabel = CreateSubobject<TextBlock2D>(tbProp);
80 mUpdateLabel->GetTransform().AttachTo(&mRootComponent);
81 mUpdateLabel->SetText("Update:");
82 mUpdateLabel->SetPosition(glm::vec2(column_0, row_2));
83
84 mUpdateValue = CreateSubobject<TextBlock2D>(tbProp);
85 mUpdateValue->GetTransform().AttachTo(&mRootComponent);
86 mUpdateValue->SetPosition(glm::vec2(column_1, row_2));
87
88 mDrawLabel = CreateSubobject<TextBlock2D>(tbProp);
89 mDrawLabel->GetTransform().AttachTo(&mRootComponent);
90 mDrawLabel->SetText("Draw:");
91 mDrawLabel->SetPosition(glm::vec2(column_0, row_3));
92
93 mDrawValue = CreateSubobject<TextBlock2D>(tbProp);
94 mDrawValue->GetTransform().AttachTo(&mRootComponent);
95 mDrawValue->SetPosition(glm::vec2(column_1, row_3));
96}
SceneComponent2D mRootComponent
Definition: actor_2d.hpp:207
virtual void Initialize()
Initializes the actor after creation.
Definition: actor_2d.cpp:20
SceneComponent2D & GetTransform()
Access to the underlying SceneComponent2D (transform).
Definition: drawable_2d.cpp:55
void SetPosition(const glm::vec2 &position)
Sets the quad position in 2D space.
Definition: drawable_2d.cpp:25
void AttachTo(SceneComponent2D *parent)
Attaches this scene component to a parent scene component.
virtual void SetText(std::string text)
Sets the displayed text.
Configuration parameters for a text block.

◆ Update()

void rendering_engine::StatsOverlay::Update ( float  deltaTime)
overridevirtual

Updates displayed statistics each frame.

Retrieves FrameMetrics from the active application and updates value text blocks accordingly.

Parameters
deltaTimeTime elapsed since previous frame (ms).

Reimplemented from rendering_engine::Actor2D.

Definition at line 98 of file stats_overlay.cpp.

99{
100 Actor2D::Update(deltaTime);
101
102 mTimeAccumulator += deltaTime;
103 if (mTimeAccumulator < mUpdateInterval)
104 return;
105
106 mTimeAccumulator = 0.0f;
107
108 const auto frameMetrics = GetScene().GetSceneManager().GetApplication()->GetFrameMetrics();
109
110 float fps = 0.0f;
111 if (bUseSmoothedFPS)
112 {
113 fps = frameMetrics.fpsSmoothed;
114 }
115 else
116 {
117 fps = frameMetrics.fpsRaw;
118 }
119
120 char bufferFPS[16];
121 std::snprintf(bufferFPS, sizeof(bufferFPS), "%.2f", fps);
122 mFPSValue->SetText(bufferFPS);
123
124 char bufferFrame[16];
125 std::snprintf(bufferFrame, sizeof(bufferFrame), "%.2f", frameMetrics.frameDurationMs);
126 mFrameValue->SetText(bufferFrame);
127
128 char bufferUpdate[16];
129 std::snprintf(bufferUpdate, sizeof(bufferUpdate), "%.2f", frameMetrics.updateTimeMs);
130 mUpdateValue->SetText(bufferUpdate);
131
132 char bufferDraw[16];
133 std::snprintf(bufferDraw, sizeof(bufferDraw), "%.2f", frameMetrics.drawTimeMs);
134 mDrawValue->SetText(bufferDraw);
135}
virtual void Update(float deltaTime)
Updates actor logic and root transform state.
Definition: actor_2d.cpp:64
Scene & GetScene()
Returns the owning Scene.
Definition: actor_2d.cpp:108
virtual FrameMetrics GetFrameMetrics() const =0
Returns performance metrics of the last processed frame.
IApplication * GetApplication()
Returns the application associated with this SceneManager.
SceneManager & GetSceneManager()
Gets a reference to the SceneManager that owns this scene.
Definition: scene.cpp:129

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