Skip to main content

FpsWidget Class

Debug widget for real-time FPS metrics and frame pacing configuration. More...

Declaration

class helios::ext::imgui::widgets::FpsWidget { ... }

Base class

classImGuiWidget

Abstract base class for ImGui widgets rendered in debug overlays. More...

Public Constructors Index

FpsWidget (helios::engine::tooling::FpsMetrics *fpsMetrics, helios::engine::tooling::FramePacer *framePacer=nullptr)

Constructs the FpsWidget. More...

Public Member Functions Index

voiddraw () override

Renders the FPS metrics UI using ImGui. More...

Private Member Attributes Index

helios::engine::tooling::FpsMetrics *fpsMetrics_ = nullptr

Pointer to an FpsMetrics instance used for tracking and displaying FPS metrics. More...

helios::engine::tooling::FramePacer *framePacer_ = nullptr

Pointer to a `FramePacer` instance for managing frame pacing and target FPS. More...

floattargetFpsInput_ = 0.0f

Stores the user-configured target frames per second (FPS) for frame pacing. More...

boolshowInSeconds_ = false

Determines whether timing information is displayed in seconds or milliseconds. More...

inthistorySizeInput_ = 60

Input value for configuring the size of the FPS history buffer. More...

Description

Debug widget for real-time FPS metrics and frame pacing configuration.

Displays average FPS, frame time, work time, idle time, and frame history graph. Optionally allows runtime configuration of frame pacing target FPS via buttons and sliders (requires a `FramePacer` instance).

info

This widget is not thread-safe. Use from the main/render thread only.

Definition at line 30 of file FpsWidget.ixx.

Public Constructors

FpsWidget()

helios::ext::imgui::widgets::FpsWidget::FpsWidget (helios::engine::tooling::FpsMetrics * fpsMetrics, helios::engine::tooling::FramePacer * framePacer=nullptr)
inline explicit

Constructs the FpsWidget.

Parameters
fpsMetrics

Pointer to the FpsMetrics instance (must remain valid).

framePacer

Optional pointer to FramePacer for runtime FPS configuration.

Definition at line 102 of file FpsWidget.ixx.

102 explicit FpsWidget(
104 helios::engine::tooling::FramePacer* framePacer = nullptr
105 ) : fpsMetrics_(fpsMetrics), framePacer_(framePacer)
106 {
107 if (fpsMetrics_) {
108 historySizeInput_ = static_cast<int>(fpsMetrics_->getHistorySize());
109 }
110 if (framePacer_) {
111 targetFpsInput_ = framePacer_->getTargetFps();
112 }
113 }

Public Member Functions

draw()

void helios::ext::imgui::widgets::FpsWidget::draw ()
inline virtual

Renders the FPS metrics UI using ImGui.

Definition at line 118 of file FpsWidget.ixx.

118 void draw() override {
119 if (!fpsMetrics_) {
120 return;
121 }
122
123 // Window settings
124 ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_FirstUseEver);
125 ImGui::SetNextWindowSize(ImVec2(320, 250), ImGuiCond_FirstUseEver);
126
127 if (ImGui::Begin("FPS Metrics", nullptr, ImGuiWindowFlags_NoCollapse)) {
128
129 // 1 Main Metrics
130 ImGui::SeparatorText("Timing Info");
131
132 float displayFrameTime = showInSeconds_ ? fpsMetrics_->getFrameTimeSeconds() : fpsMetrics_->getFrameTimeMs();
133 float displayWorkTime = showInSeconds_ ? fpsMetrics_->getWorkTimeSeconds() : fpsMetrics_->getWorkTimeMs();
134 float displayIdleTime = showInSeconds_ ? fpsMetrics_->getIdleTimeSeconds() : fpsMetrics_->getIdleTimeMs();
135 const char* unit = showInSeconds_ ? "s" : "ms";
136 const char* format = showInSeconds_ ? "%.5f %s" : "%.2f %s";
137
138 ImGui::Text("FPS: %.1f", fpsMetrics_->getFps());
139 ImGui::Text("Avg Frame: "); ImGui::SameLine(); ImGui::Text(format, displayFrameTime, unit);
140 ImGui::Text("CPU Work: "); ImGui::SameLine(); ImGui::Text(format, displayWorkTime, unit);
141 ImGui::Text("Idle/Wait: "); ImGui::SameLine(); ImGui::Text(format, displayIdleTime, unit);
142 ImGui::Text("Frame #: %llu", fpsMetrics_->getFrameCount());
143
144 // 2 Settings
145 ImGui::SeparatorText("Settings");
146
147 // Checkbox for unit toggle
148 if (ImGui::Checkbox("Show in Seconds", &showInSeconds_)) {
149 // UI state changes; display updates next frame
150 }
151
152 // Input for history size
153 if (ImGui::InputInt("History Size", &historySizeInput_, 1, 10)) {
154 if (historySizeInput_ < 1) historySizeInput_ = 1;
155 if (historySizeInput_ > 1000) historySizeInput_ = 1000;
156
157 fpsMetrics_->setHistorySize(static_cast<size_t>(historySizeInput_));
158 }
159
160 // Frame pacing configuration (if pacer is available)
161 if (framePacer_) {
162 ImGui::SeparatorText("Frame Pacing Config");
163
164 targetFpsInput_ = framePacer_->getTargetFps();
165
166 // Quick preset buttons
167 if (ImGui::Button("Uncapped (0)")) {
168 framePacer_->setTargetFps(0.0f);
169 targetFpsInput_ = 0.0f;
170 }
171 ImGui::SameLine();
172 if (ImGui::Button("30 FPS")) {
173 framePacer_->setTargetFps(30.0f);
174 targetFpsInput_ = 30.0f;
175 }
176 ImGui::SameLine();
177 if (ImGui::Button("60 FPS")) {
178 framePacer_->setTargetFps(60.0f);
179 targetFpsInput_ = 60.0f;
180 }
181 ImGui::SameLine();
182 if (ImGui::Button("120 FPS")) {
183 framePacer_->setTargetFps(120.0f);
184 targetFpsInput_ = 120.0f;
185 }
186 ImGui::SameLine();
187 if (ImGui::Button("144 FPS")) {
188 framePacer_->setTargetFps(144.0f);
189 targetFpsInput_ = 144.0f;
190 }
191
192 // Slider for precise control
193 float sliderFps = targetFpsInput_;
194 if (ImGui::DragFloat("Target FPS", &sliderFps, 1.0f, 0.0f, 300.0f, "%.0f")) {
195 framePacer_->setTargetFps(sliderFps);
196 targetFpsInput_ = sliderFps;
197 }
198 if (ImGui::IsItemHovered()) {
199 ImGui::SetTooltip("Set to 0 for unlimited (V-Sync might still limit)");
200 }
201 }
202
203 // Frame time history graph
204 const auto& history = fpsMetrics_->getHistory();
205 if (!history.empty()) {
206 ImGui::SeparatorText("History");
207
208 std::vector<float> frameTimes;
209 frameTimes.reserve(history.size());
210
211 for (const auto& s : history) {
212 frameTimes.push_back(s.totalFrameTime * 1000.0f);
213 }
214
215 ImGui::PlotLines("Frame Time (ms)",
216 frameTimes.data(),
217 static_cast<int>(frameTimes.size()),
218 0,
219 nullptr,
220 0.0f,
221 FLT_MAX,
222 ImVec2(0, 80.0f));
223 }
224 }
225 ImGui::End();
226 }

Private Member Attributes

fpsMetrics_

helios::engine::tooling::FpsMetrics* helios::ext::imgui::widgets::FpsWidget::fpsMetrics_ = nullptr

Pointer to an FpsMetrics instance used for tracking and displaying FPS metrics.

This member provides direct access to real-time frame rate statistics, including current FPS, average FPS, and frame timing data, which are displayed in the widget. It is expected to be externally managed and supplied during widget initialization.

info

The pointer must remain valid throughout the lifetime of the FpsWidget instance.

Definition at line 43 of file FpsWidget.ixx.

43 helios::engine::tooling::FpsMetrics* fpsMetrics_ = nullptr;

framePacer_

helios::engine::tooling::FramePacer* helios::ext::imgui::widgets::FpsWidget::framePacer_ = nullptr

Pointer to a `FramePacer` instance for managing frame pacing and target FPS.

Provides frame pacing control to synchronize application updates with a specified frame rate target, if set. When associated with a valid `FramePacer`, it enables runtime configuration of frame timing and update intervals.

info

This pointer must be initialized with a valid `FramePacer` instance or set to `nullptr` if frame pacing is not required. Ensure the lifetime of the referenced `FramePacer` extends beyond the usage of this pointer.

Definition at line 56 of file FpsWidget.ixx.

56 helios::engine::tooling::FramePacer* framePacer_ = nullptr;

historySizeInput_

int helios::ext::imgui::widgets::FpsWidget::historySizeInput_ = 60

Input value for configuring the size of the FPS history buffer.

Determines the number of recent frame timing samples to store and display. This value directly influences the frame history graph rendering in the FPS widget. Typically adjusted by the user through the UI input field.

info

Must be within a valid range, with a lower limit of 1 and an upper limit of 1000 to prevent excessive memory usage or invalid states.

Definition at line 92 of file FpsWidget.ixx.

92 int historySizeInput_ = 60;

showInSeconds_

bool helios::ext::imgui::widgets::FpsWidget::showInSeconds_ = false

Determines whether timing information is displayed in seconds or milliseconds.

If set to `true`, all timing metrics (e.g., frame time, work time, idle time) are shown in seconds. If set to `false`, they are shown in milliseconds.

Used to toggle between different units of measurement for presenting frame timing metrics in the FPS widget UI.

Definition at line 80 of file FpsWidget.ixx.

80 bool showInSeconds_ = false;

targetFpsInput_

float helios::ext::imgui::widgets::FpsWidget::targetFpsInput_ = 0.0f

Stores the user-configured target frames per second (FPS) for frame pacing.

Acts as the intermediate value for the target FPS, used for runtime adjustments via buttons or sliders in the UI. This variable gets updated dynamically based on user input and reflects the desired frame rate. A value of `0.0f` indicates an uncapped frame rate.

info

This variable is synchronized with the target FPS of the associated `FramePacer` instance if provided.

Definition at line 69 of file FpsWidget.ixx.

69 float targetFpsInput_ = 0.0f;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.