OpenTTD Source 20241224-master-gf74b0cf984
PerformanceAccumulator Class Reference

RAII class for measuring multi-step elements of performance. More...

#include <framerate_type.h>

Public Member Functions

 PerformanceAccumulator (PerformanceElement elem)
 Begin measuring one block of the accumulating value.
 
 ~PerformanceAccumulator ()
 Finish and add one block of the accumulating value.
 

Static Public Member Functions

static void Reset (PerformanceElement elem)
 Store the previous accumulator value and reset for a new cycle of accumulating measurements.
 

Private Attributes

PerformanceElement elem
 
TimingMeasurement start_time
 

Detailed Description

RAII class for measuring multi-step elements of performance.

At the beginning of a frame, call Reset on the element, then construct an object in the scope where each processing cycle happens. The measurements are summed between resets.

Usually StateGameLoop is an appropriate function to place Reset calls in, but for elements with more isolated scopes it can also be appropriate to Reset somewhere else. An example is the CallVehicleTicks function where all the vehicle type elements are reset.

The PerformanceMeasurer::Paused function can also be used with elements otherwise measured with this class.

Definition at line 114 of file framerate_type.h.

Constructor & Destructor Documentation

◆ PerformanceAccumulator()

PerformanceAccumulator::PerformanceAccumulator ( PerformanceElement  elem)

Begin measuring one block of the accumulating value.

Parameters
elemThe element to be measured

Definition at line 309 of file framerate_gui.cpp.

References GetPerformanceTimer(), and PFE_MAX.

◆ ~PerformanceAccumulator()

PerformanceAccumulator::~PerformanceAccumulator ( )

Finish and add one block of the accumulating value.

Definition at line 318 of file framerate_gui.cpp.

References anonymous_namespace{framerate_gui.cpp}::PerformanceData::AddAccumulate(), and GetPerformanceTimer().

Member Function Documentation

◆ Reset()

void PerformanceAccumulator::Reset ( PerformanceElement  elem)
static

Store the previous accumulator value and reset for a new cycle of accumulating measurements.

Note
This function must be called once per frame, otherwise measurements are not collected.
Parameters
elemThe element to begin a new measurement cycle of

Definition at line 328 of file framerate_gui.cpp.

References anonymous_namespace{framerate_gui.cpp}::PerformanceData::BeginAccumulate(), and GetPerformanceTimer().

Referenced by StateGameLoop(), and UpdateWindows().

Field Documentation

◆ elem

PerformanceElement PerformanceAccumulator::elem
private

Definition at line 115 of file framerate_type.h.

◆ start_time

TimingMeasurement PerformanceAccumulator::start_time
private

Definition at line 116 of file framerate_type.h.


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