Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
/** @file framerate_gui.cpp GUI for displaying framerate/game speed information. */
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "framerate_type.h"
|
||||
#include <chrono>
|
||||
#include "gfx_func.h"
|
||||
@@ -24,6 +26,7 @@
|
||||
#include "game/game_instance.hpp"
|
||||
#include "timer/timer.h"
|
||||
#include "timer/timer_window.h"
|
||||
#include "zoom_func.h"
|
||||
|
||||
#include "widgets/framerate_widget.h"
|
||||
|
||||
@@ -367,10 +370,10 @@ static const PerformanceElement DISPLAY_ORDER_PFE[PFE_MAX - 4] = {
|
||||
PFE_SOUND,
|
||||
};
|
||||
|
||||
static const char * GetAIName(int ai_index)
|
||||
static std::string_view GetAIName(int ai_index)
|
||||
{
|
||||
if (!Company::IsValidAiID(ai_index)) return "";
|
||||
return Company::Get(ai_index)->ai_info->GetName().c_str();
|
||||
if (!Company::IsValidAiID(ai_index)) return {};
|
||||
return Company::Get(ai_index)->ai_info->GetName();
|
||||
}
|
||||
|
||||
/** @hideinitializer */
|
||||
@@ -454,7 +457,7 @@ struct FramerateWindow : Window {
|
||||
}
|
||||
|
||||
/** Update the window on a regular interval. */
|
||||
IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(100), [this](auto) {
|
||||
const IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(100), [this](auto) {
|
||||
this->UpdateData();
|
||||
this->SetDirty();
|
||||
}};
|
||||
@@ -528,7 +531,7 @@ struct FramerateWindow : Window {
|
||||
size.width = 0;
|
||||
size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + MIN_ELEMENTS * GetCharacterHeight(FS_NORMAL);
|
||||
resize.width = 0;
|
||||
resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
for (PerformanceElement e : DISPLAY_ORDER_PFE) {
|
||||
if (_pf_data[e].num_valid == 0) continue;
|
||||
Dimension line_size;
|
||||
@@ -550,7 +553,7 @@ struct FramerateWindow : Window {
|
||||
size.width = std::max(size.width, item_size.width);
|
||||
size.height += GetCharacterHeight(FS_NORMAL) * MIN_ELEMENTS + WidgetDimensions::scaled.vsep_normal;
|
||||
resize.width = 0;
|
||||
resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -699,7 +702,7 @@ static constexpr NWidgetPart _frametime_graph_window_widgets[] = {
|
||||
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
||||
EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY),
|
||||
NWidget(NWID_VERTICAL), SetPadding(6),
|
||||
NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.frametext),
|
||||
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FGW_GRAPH),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
@@ -739,13 +742,13 @@ struct FrametimeGraphWindow : Window {
|
||||
Dimension size_s_label = GetStringBoundingBox(GetString(STR_FRAMERATE_GRAPH_SECONDS, 100));
|
||||
|
||||
/* Size graph in height to fit at least 10 vertical labels with space between, or at least 100 pixels */
|
||||
graph_size.height = std::max(100u, 10 * (size_ms_label.height + 1));
|
||||
graph_size.height = std::max<uint>(ScaleGUITrad(100), 10 * (size_ms_label.height + WidgetDimensions::scaled.vsep_normal));
|
||||
/* Always 2:1 graph area */
|
||||
graph_size.width = 2 * graph_size.height;
|
||||
size = graph_size;
|
||||
|
||||
size.width += size_ms_label.width + 2;
|
||||
size.height += size_s_label.height + 2;
|
||||
size.width += size_ms_label.width + WidgetDimensions::scaled.hsep_normal;
|
||||
size.height += size_s_label.height + WidgetDimensions::scaled.vsep_normal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,7 +838,7 @@ struct FrametimeGraphWindow : Window {
|
||||
}
|
||||
|
||||
/** Update the scaling on a regular interval. */
|
||||
IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(500), [this](auto) {
|
||||
const IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(500), [this](auto) {
|
||||
this->UpdateScale();
|
||||
}};
|
||||
|
||||
@@ -864,9 +867,9 @@ struct FrametimeGraphWindow : Window {
|
||||
const int x_max = r.right;
|
||||
const int y_zero = r.top + (int)this->graph_size.height;
|
||||
const int y_max = r.top;
|
||||
const int c_grid = PC_DARK_GREY;
|
||||
const int c_lines = PC_BLACK;
|
||||
const int c_peak = PC_DARK_RED;
|
||||
const PixelColour c_grid = PC_DARK_GREY;
|
||||
const PixelColour c_lines = PC_BLACK;
|
||||
const PixelColour c_peak = PC_DARK_RED;
|
||||
|
||||
const TimingMeasurement draw_horz_scale = (TimingMeasurement)this->horizontal_scale * TIMESTAMP_PRECISION / 2;
|
||||
const TimingMeasurement draw_vert_scale = (TimingMeasurement)this->vertical_scale;
|
||||
@@ -884,11 +887,11 @@ struct FrametimeGraphWindow : Window {
|
||||
GfxDrawLine(x_zero, y, x_max, y, c_grid);
|
||||
if (division % 2 == 0) {
|
||||
if ((TimingMeasurement)this->vertical_scale > TIMESTAMP_PRECISION) {
|
||||
DrawString(r.left, x_zero - 2, y - GetCharacterHeight(FS_SMALL),
|
||||
DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FS_SMALL),
|
||||
GetString(STR_FRAMERATE_GRAPH_SECONDS, this->vertical_scale * division / 10 / TIMESTAMP_PRECISION),
|
||||
TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
|
||||
} else {
|
||||
DrawString(r.left, x_zero - 2, y - GetCharacterHeight(FS_SMALL),
|
||||
DrawString(r.left, x_zero - WidgetDimensions::scaled.hsep_normal, y - GetCharacterHeight(FS_SMALL),
|
||||
GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, this->vertical_scale * division / 10 * 1000 / TIMESTAMP_PRECISION),
|
||||
TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
|
||||
}
|
||||
@@ -899,7 +902,7 @@ struct FrametimeGraphWindow : Window {
|
||||
int x = Scinterlate(x_zero, x_max, 0, (int)horz_divisions, (int)horz_divisions - (int)division);
|
||||
GfxDrawLine(x, y_max, x, y_zero, c_grid);
|
||||
if (division % 2 == 0) {
|
||||
DrawString(x, x_max, y_zero + 2,
|
||||
DrawString(x, x_max, y_zero + WidgetDimensions::scaled.vsep_normal,
|
||||
GetString(STR_FRAMERATE_GRAPH_SECONDS, division * horz_div_scl / 2),
|
||||
TC_GREY, SA_LEFT | SA_FORCE, false, FS_SMALL);
|
||||
}
|
||||
@@ -956,14 +959,14 @@ struct FrametimeGraphWindow : Window {
|
||||
|
||||
/* If the peak value is significantly larger than the average, mark and label it */
|
||||
if (points_drawn > 0 && peak_value > TIMESTAMP_PRECISION / 100 && 2 * peak_value > 3 * value_sum / points_drawn) {
|
||||
TextColour tc_peak = (TextColour)(TC_IS_PALETTE_COLOUR | c_peak);
|
||||
TextColour tc_peak = c_peak.ToTextColour();
|
||||
GfxFillRect(peak_point.x - 1, peak_point.y - 1, peak_point.x + 1, peak_point.y + 1, c_peak);
|
||||
uint64_t value = peak_value * 1000 / TIMESTAMP_PRECISION;
|
||||
int label_y = std::max(y_max, peak_point.y - GetCharacterHeight(FS_SMALL));
|
||||
if (peak_point.x - x_zero > (int)this->graph_size.width / 2) {
|
||||
DrawString(x_zero, peak_point.x - 2, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_RIGHT | SA_FORCE, false, FS_SMALL);
|
||||
DrawString(x_zero, peak_point.x - WidgetDimensions::scaled.hsep_normal, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_RIGHT | SA_FORCE, false, FS_SMALL);
|
||||
} else {
|
||||
DrawString(peak_point.x + 2, x_max, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_LEFT | SA_FORCE, false, FS_SMALL);
|
||||
DrawString(peak_point.x + WidgetDimensions::scaled.hsep_normal, x_max, label_y, GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, value), tc_peak, SA_LEFT | SA_FORCE, false, FS_SMALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user