OpenTTD Source  20240917-master-g9ab0a47812
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. More...
 
 ~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. More...
 

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 308 of file framerate_gui.cpp.

References GetPerformanceTimer(), and PFE_MAX.

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 327 of file framerate_gui.cpp.

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

Referenced by StateGameLoop(), and UpdateWindows().


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