OpenTTD Source  20241108-master-g80f628063a
framerate_gui.cpp File Reference

GUI for displaying framerate/game speed information. More...

#include "framerate_type.h"
#include <chrono>
#include "gfx_func.h"
#include "window_gui.h"
#include "window_func.h"
#include "table/sprites.h"
#include "string_func.h"
#include "strings_func.h"
#include "console_func.h"
#include "console_type.h"
#include "company_base.h"
#include "ai/ai_info.hpp"
#include "ai/ai_instance.hpp"
#include "game/game.hpp"
#include "game/game_instance.hpp"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "widgets/framerate_widget.h"
#include <atomic>
#include <mutex>
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  anonymous_namespace{framerate_gui.cpp}::PerformanceData
 
struct  FramerateWindow
 
struct  FramerateWindow::CachedDecimal
 
struct  FrametimeGraphWindow
 

Namespaces

 anonymous_namespace{framerate_gui.cpp}
 Private declarations for performance measurement implementation.
 

Functions

static TimingMeasurement GetPerformanceTimer ()
 Return a timestamp with TIMESTAMP_PRECISION ticks per second precision. More...
 
void ShowFrametimeGraphWindow (PerformanceElement elem)
 Open a graph window for a performance element.
 
static const char * GetAIName (int ai_index)
 
void ShowFramerateWindow ()
 Open the general framerate window.
 
void ConPrintFramerate ()
 Print performance statistics to game console.
 
void ProcessPendingPerformanceMeasurements ()
 This drains the PFE_SOUND measurement data queue into _pf_data. More...
 

Variables

static std::mutex _sound_perf_lock
 
static std::atomic< bool > _sound_perf_pending
 
static std::vector< TimingMeasurement_sound_perf_measurements
 
const int anonymous_namespace{framerate_gui.cpp}::NUM_FRAMERATE_POINTS = 512
 Number of data points to keep in buffer for each performance measurement.
 
const TimingMeasurement anonymous_namespace{framerate_gui.cpp}::TIMESTAMP_PRECISION = 1000000
 Units a second is divided into in performance measurements
 
static const double anonymous_namespace{framerate_gui.cpp}::GL_RATE = 1000.0 / MILLISECONDS_PER_TICK
 Game loop rate, cycles per second
 
PerformanceData anonymous_namespace{framerate_gui.cpp}::_pf_data [PFE_MAX]
 Storage for all performance element measurements. More...
 
static const PerformanceElement DISPLAY_ORDER_PFE [PFE_MAX]
 
static constexpr NWidgetPart _framerate_window_widgets []
 
static WindowDesc _framerate_display_desc (WDP_AUTO, "framerate_display", 0, 0, WC_FRAMERATE_DISPLAY, WC_NONE, 0, _framerate_window_widgets)
 
static constexpr NWidgetPart _frametime_graph_window_widgets []
 
static WindowDesc _frametime_graph_window_desc (WDP_AUTO, "frametime_graph", 140, 90, WC_FRAMETIME_GRAPH, WC_NONE, 0, _frametime_graph_window_widgets)
 

Detailed Description

GUI for displaying framerate/game speed information.

Definition in file framerate_gui.cpp.

Function Documentation

◆ GetPerformanceTimer()

static TimingMeasurement GetPerformanceTimer ( )
static

Return a timestamp with TIMESTAMP_PRECISION ticks per second precision.

The basis of the timestamp is implementation defined, but the value should be steady, so differences can be taken to reliably measure intervals.

Definition at line 231 of file framerate_gui.cpp.

Referenced by PerformanceMeasurer::Paused(), PerformanceAccumulator::PerformanceAccumulator(), PerformanceMeasurer::PerformanceMeasurer(), PerformanceAccumulator::Reset(), PerformanceAccumulator::~PerformanceAccumulator(), and PerformanceMeasurer::~PerformanceMeasurer().

◆ ProcessPendingPerformanceMeasurements()

void ProcessPendingPerformanceMeasurements ( )

This drains the PFE_SOUND measurement data queue into _pf_data.

PFE_SOUND measurements are made by the mixer thread and so cannot be stored into _pf_data directly, because this would not be thread safe and would violate the invariants of the FPS and frame graph windows.

See also
PerformanceMeasurement::~PerformanceMeasurement()

Definition at line 1111 of file framerate_gui.cpp.

Referenced by UpdateWindows().