OpenTTD Source 20250331-master-g3c15e0c889
framerate_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "framerate_type.h"
11#include <chrono>
12#include "gfx_func.h"
13#include "newgrf_sound.h"
14#include "window_gui.h"
15#include "window_func.h"
16#include "string_func.h"
17#include "strings_func.h"
18#include "console_func.h"
19#include "console_type.h"
20#include "company_base.h"
21#include "ai/ai_info.hpp"
22#include "ai/ai_instance.hpp"
23#include "game/game.hpp"
25#include "timer/timer.h"
26#include "timer/timer_window.h"
27
29
30#include <atomic>
31#include <mutex>
32
33#include "table/strings.h"
34
35#include "safeguards.h"
36
37static std::mutex _sound_perf_lock;
38static std::atomic<bool> _sound_perf_pending;
39static std::vector<TimingMeasurement> _sound_perf_measurements;
40
44namespace {
45
47 const int NUM_FRAMERATE_POINTS = 512;
50
53 static const TimingMeasurement INVALID_DURATION = UINT64_MAX;
54
56 std::array<TimingMeasurement, NUM_FRAMERATE_POINTS> durations{};
58 std::array<TimingMeasurement, NUM_FRAMERATE_POINTS> timestamps{};
60 double expected_rate = 0;
62 int next_index = 0;
64 int prev_index = 0;
66 int num_valid = 0;
67
69 TimingMeasurement acc_duration{};
71 TimingMeasurement acc_timestamp{};
72
79 explicit PerformanceData(double expected_rate) : expected_rate(expected_rate) { }
80
82 void Add(TimingMeasurement start_time, TimingMeasurement end_time)
83 {
84 this->durations[this->next_index] = end_time - start_time;
85 this->timestamps[this->next_index] = start_time;
86 this->prev_index = this->next_index;
87 this->next_index += 1;
88 if (this->next_index >= NUM_FRAMERATE_POINTS) this->next_index = 0;
89 this->num_valid = std::min(NUM_FRAMERATE_POINTS, this->num_valid + 1);
90 }
91
94 {
95 this->timestamps[this->next_index] = this->acc_timestamp;
96 this->durations[this->next_index] = this->acc_duration;
97 this->prev_index = this->next_index;
98 this->next_index += 1;
99 if (this->next_index >= NUM_FRAMERATE_POINTS) this->next_index = 0;
100 this->num_valid = std::min(NUM_FRAMERATE_POINTS, this->num_valid + 1);
101
102 this->acc_duration = 0;
103 this->acc_timestamp = start_time;
104 }
105
108 {
109 this->acc_duration += duration;
110 }
111
114 {
115 if (this->durations[this->prev_index] != INVALID_DURATION) {
116 this->timestamps[this->next_index] = start_time;
117 this->durations[this->next_index] = INVALID_DURATION;
118 this->prev_index = this->next_index;
119 this->next_index += 1;
120 if (this->next_index >= NUM_FRAMERATE_POINTS) this->next_index = 0;
121 this->num_valid += 1;
122 }
123 }
124
127 {
128 count = std::min(count, this->num_valid);
129
130 int first_point = this->prev_index - count;
131 if (first_point < 0) first_point += NUM_FRAMERATE_POINTS;
132
133 /* Sum durations, skipping invalid points */
134 double sumtime = 0;
135 for (int i = first_point; i < first_point + count; i++) {
136 auto d = this->durations[i % NUM_FRAMERATE_POINTS];
137 if (d != INVALID_DURATION) {
138 sumtime += d;
139 } else {
140 /* Don't count the invalid durations */
141 count--;
142 }
143 }
144
145 if (count == 0) return 0; // avoid div by zero
146 return sumtime * 1000 / count / TIMESTAMP_PRECISION;
147 }
148
150 double GetRate()
151 {
152 /* Start at last recorded point, end at latest when reaching the earliest recorded point */
153 int point = this->prev_index;
154 int last_point = this->next_index - this->num_valid;
155 if (last_point < 0) last_point += NUM_FRAMERATE_POINTS;
156
157 /* Number of data points collected */
158 int count = 0;
159 /* Time of previous data point */
160 TimingMeasurement last = this->timestamps[point];
161 /* Total duration covered by collected points */
162 TimingMeasurement total = 0;
163
164 /* We have nothing to compare the first point against */
165 point--;
166 if (point < 0) point = NUM_FRAMERATE_POINTS - 1;
167
168 while (point != last_point) {
169 /* Only record valid data points, but pretend the gaps in measurements aren't there */
170 if (this->durations[point] != INVALID_DURATION) {
171 total += last - this->timestamps[point];
172 count++;
173 }
174 last = this->timestamps[point];
175 if (total >= TIMESTAMP_PRECISION) break; // end after 1 second has been collected
176 point--;
177 if (point < 0) point = NUM_FRAMERATE_POINTS - 1;
178 }
179
180 if (total == 0 || count == 0) return 0;
181 return (double)count * TIMESTAMP_PRECISION / total;
182 }
183 };
184
186 static const double GL_RATE = 1000.0 / MILLISECONDS_PER_TICK;
187
194 PerformanceData(GL_RATE), // PFE_GAMELOOP
195 PerformanceData(1), // PFE_ACC_GL_ECONOMY
196 PerformanceData(1), // PFE_ACC_GL_TRAINS
197 PerformanceData(1), // PFE_ACC_GL_ROADVEHS
198 PerformanceData(1), // PFE_ACC_GL_SHIPS
199 PerformanceData(1), // PFE_ACC_GL_AIRCRAFT
200 PerformanceData(1), // PFE_GL_LANDSCAPE
201 PerformanceData(1), // PFE_GL_LINKGRAPH
202 PerformanceData(1000.0 / 30), // PFE_DRAWING
203 PerformanceData(1), // PFE_ACC_DRAWWORLD
204 PerformanceData(60.0), // PFE_VIDEO
205 PerformanceData(1000.0 * 8192 / 44100), // PFE_SOUND
206 PerformanceData(1), // PFE_ALLSCRIPTS
207 PerformanceData(1), // PFE_GAMESCRIPT
208 PerformanceData(1), // PFE_AI0 ...
222 PerformanceData(1), // PFE_AI14
223 };
224
225}
226
227
234{
235 using namespace std::chrono;
236 return (TimingMeasurement)time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count();
237}
238
239
245{
246 assert(elem < PFE_MAX);
247
248 this->elem = elem;
249 this->start_time = GetPerformanceTimer();
250}
251
254{
255 if (this->elem == PFE_ALLSCRIPTS) {
256 /* Hack to not record scripts total when no scripts are active */
257 bool any_active = _pf_data[PFE_GAMESCRIPT].num_valid > 0;
258 for (uint e = PFE_AI0; e < PFE_MAX; e++) any_active |= _pf_data[e].num_valid > 0;
259 if (!any_active) {
261 return;
262 }
263 }
264 if (this->elem == PFE_SOUND) {
265 /* PFE_SOUND measurements are made from the mixer thread.
266 * _pf_data cannot be concurrently accessed from the mixer thread
267 * and the main thread, so store the measurement results in a
268 * mutex-protected queue which is drained by the main thread.
269 * See: ProcessPendingPerformanceMeasurements() */
271 std::lock_guard lk(_sound_perf_lock);
272 if (_sound_perf_measurements.size() >= NUM_FRAMERATE_POINTS * 2) return;
273 _sound_perf_measurements.push_back(this->start_time);
274 _sound_perf_measurements.push_back(end);
275 _sound_perf_pending.store(true, std::memory_order_release);
276 return;
277 }
278 _pf_data[this->elem].Add(this->start_time, GetPerformanceTimer());
279}
280
283{
284 _pf_data[this->elem].expected_rate = rate;
285}
286
289{
290 _pf_data[elem].num_valid = 0;
291 _pf_data[elem].next_index = 0;
292 _pf_data[elem].prev_index = 0;
293}
294
300{
302 _pf_data[elem].AddPause(GetPerformanceTimer());
303}
304
305
311{
312 assert(elem < PFE_MAX);
313
314 this->elem = elem;
315 this->start_time = GetPerformanceTimer();
316}
317
320{
321 _pf_data[this->elem].AddAccumulate(GetPerformanceTimer() - this->start_time);
322}
323
333
334
336
337
338static const PerformanceElement DISPLAY_ORDER_PFE[PFE_MAX] = {
348 PFE_AI0,
349 PFE_AI1,
350 PFE_AI2,
351 PFE_AI3,
352 PFE_AI4,
353 PFE_AI5,
354 PFE_AI6,
355 PFE_AI7,
356 PFE_AI8,
357 PFE_AI9,
358 PFE_AI10,
359 PFE_AI11,
360 PFE_AI12,
361 PFE_AI13,
362 PFE_AI14,
366 PFE_VIDEO,
367 PFE_SOUND,
368};
369
370static const char * GetAIName(int ai_index)
371{
372 if (!Company::IsValidAiID(ai_index)) return "";
373 return Company::Get(ai_index)->ai_info->GetName().c_str();
374}
375
377static constexpr NWidgetPart _framerate_window_widgets[] = {
379 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
380 NWidget(WWT_CAPTION, COLOUR_GREY, WID_FRW_CAPTION),
381 NWidget(WWT_SHADEBOX, COLOUR_GREY),
382 NWidget(WWT_STICKYBOX, COLOUR_GREY),
383 EndContainer(),
384 NWidget(WWT_PANEL, COLOUR_GREY),
386 NWidget(WWT_TEXT, INVALID_COLOUR, WID_FRW_RATE_GAMELOOP), SetToolTip(STR_FRAMERATE_RATE_GAMELOOP_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
387 NWidget(WWT_TEXT, INVALID_COLOUR, WID_FRW_RATE_DRAWING), SetToolTip(STR_FRAMERATE_RATE_BLITTER_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
388 NWidget(WWT_TEXT, INVALID_COLOUR, WID_FRW_RATE_FACTOR), SetToolTip(STR_FRAMERATE_SPEED_FACTOR_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
389 EndContainer(),
390 EndContainer(),
392 NWidget(WWT_PANEL, COLOUR_GREY),
395 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FRW_TIMES_NAMES), SetScrollbar(WID_FRW_SCROLLBAR),
396 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FRW_TIMES_CURRENT), SetScrollbar(WID_FRW_SCROLLBAR),
397 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FRW_TIMES_AVERAGE), SetScrollbar(WID_FRW_SCROLLBAR),
398 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FRW_ALLOCSIZE), SetScrollbar(WID_FRW_SCROLLBAR),
399 EndContainer(),
400 NWidget(WWT_TEXT, INVALID_COLOUR, WID_FRW_INFO_DATA_POINTS), SetFill(1, 0), SetResize(1, 0),
401 EndContainer(),
402 EndContainer(),
404 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_FRW_SCROLLBAR),
405 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
406 EndContainer(),
407 EndContainer(),
408};
409
411 int num_active = 0;
412 int num_displayed = 0;
413
415 StringID strid;
416 uint32_t value;
417
418 inline void SetRate(double value, double target)
419 {
420 const double threshold_good = target * 0.95;
421 const double threshold_bad = target * 2 / 3;
422 this->value = (uint32_t)(value * 100);
424 }
425
426 inline void SetTime(double value, double target)
427 {
428 const double threshold_good = target / 3;
429 const double threshold_bad = target;
430 this->value = (uint32_t)(value * 100);
432 }
433
434 inline uint32_t GetValue() const { return this->value; }
435 inline uint32_t GetDecimals() const { return 2; }
436 };
437
441 std::array<CachedDecimal, PFE_MAX> times_shortterm{};
442 std::array<CachedDecimal, PFE_MAX> times_longterm{};
443
444 static constexpr int MIN_ELEMENTS = 5;
445
446 FramerateWindow(WindowDesc &desc, WindowNumber number) : Window(desc)
447 {
448 this->InitNested(number);
449 this->UpdateData();
450 this->num_displayed = this->num_active;
451
452 /* Window is always initialised to MIN_ELEMENTS height, resize to contain num_displayed */
453 ResizeWindow(this, 0, (std::max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * GetCharacterHeight(FS_NORMAL));
454 }
455
457 IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(100), [this](auto) {
458 this->UpdateData();
459 this->SetDirty();
460 }};
461
462 void UpdateData()
463 {
465 this->rate_gameloop.SetRate(gl_rate, _pf_data[PFE_GAMELOOP].expected_rate);
466 this->speed_gameloop.SetRate(gl_rate / _pf_data[PFE_GAMELOOP].expected_rate, 1.0);
467 if (this->IsShaded()) return; // in small mode, this is everything needed
468
470
471 int new_active = 0;
472 for (PerformanceElement e = PFE_FIRST; e < PFE_MAX; e++) {
475 if (_pf_data[e].num_valid > 0) {
476 new_active++;
477 }
478 }
479
480 if (new_active != this->num_active) {
481 this->num_active = new_active;
482 Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
483 sb->SetCount(this->num_active);
484 sb->SetCapacity(std::min(this->num_displayed, this->num_active));
485 }
486 }
487
488 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
489 {
490 switch (widget) {
491 case WID_FRW_CAPTION:
492 /* When the window is shaded, the caption shows game loop rate and speed factor */
493 if (!this->IsShaded()) return GetString(STR_FRAMERATE_CAPTION);
494
495 return GetString(STR_FRAMERATE_CAPTION_SMALL, this->rate_gameloop.strid, this->rate_gameloop.GetValue(), this->rate_gameloop.GetDecimals(), this->speed_gameloop.GetValue(), this->speed_gameloop.GetDecimals());
496
497 case WID_FRW_RATE_GAMELOOP:
498 return GetString(STR_FRAMERATE_RATE_GAMELOOP, this->rate_gameloop.strid, this->rate_gameloop.GetValue(), this->rate_gameloop.GetDecimals());
499
500 case WID_FRW_RATE_DRAWING:
501 return GetString(STR_FRAMERATE_RATE_BLITTER, this->rate_drawing.strid, this->rate_drawing.GetValue(), this->rate_drawing.GetDecimals());
502
503 case WID_FRW_RATE_FACTOR:
504 return GetString(STR_FRAMERATE_SPEED_FACTOR, this->speed_gameloop.GetValue(), this->speed_gameloop.GetDecimals());
505
506 case WID_FRW_INFO_DATA_POINTS:
508
509 default:
510 return this->Window::GetWidgetString(widget, stringid);
511 }
512 }
513
515 {
516 switch (widget) {
517 case WID_FRW_RATE_GAMELOOP:
519 break;
520 case WID_FRW_RATE_DRAWING:
522 break;
523 case WID_FRW_RATE_FACTOR:
525 break;
526
527 case WID_FRW_TIMES_NAMES: {
528 size.width = 0;
530 resize.width = 0;
532 for (PerformanceElement e : DISPLAY_ORDER_PFE) {
533 if (_pf_data[e].num_valid == 0) continue;
535 if (e < PFE_AI0) {
537 } else {
539 }
540 size.width = std::max(size.width, line_size.width);
541 }
542 break;
543 }
544
545 case WID_FRW_TIMES_CURRENT:
546 case WID_FRW_TIMES_AVERAGE:
547 case WID_FRW_ALLOCSIZE: {
548 size = GetStringBoundingBox(STR_FRAMERATE_CURRENT + (widget - WID_FRW_TIMES_CURRENT));
550 size.width = std::max(size.width, item_size.width);
552 resize.width = 0;
554 break;
555 }
556 }
557 }
558
560 void DrawElementTimesColumn(const Rect &r, StringID heading_str, std::span<const CachedDecimal> values) const
561 {
562 const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
563 int32_t skip = sb->GetPosition();
564 int drawable = this->num_displayed;
565 int y = r.top;
566 DrawString(r.left, r.right, y, heading_str, TC_FROMSTRING, SA_CENTER, true);
568 for (PerformanceElement e : DISPLAY_ORDER_PFE) {
569 if (_pf_data[e].num_valid == 0) continue;
570 if (skip > 0) {
571 skip--;
572 } else {
573 DrawString(r.left, r.right, y, GetString(values[e].strid, values[e].GetValue(), values[e].GetDecimals()), TC_FROMSTRING, SA_RIGHT);
575 drawable--;
576 if (drawable == 0) break;
577 }
578 }
579 }
580
581 void DrawElementAllocationsColumn(const Rect &r) const
582 {
583 const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
584 int32_t skip = sb->GetPosition();
585 int drawable = this->num_displayed;
586 int y = r.top;
587 DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TC_FROMSTRING, SA_CENTER, true);
589 for (PerformanceElement e : DISPLAY_ORDER_PFE) {
590 if (_pf_data[e].num_valid == 0) continue;
591 if (skip > 0) {
592 skip--;
593 } else if (e == PFE_GAMESCRIPT || e >= PFE_AI0) {
594 uint64_t value = e == PFE_GAMESCRIPT ? Game::GetInstance()->GetAllocatedMemory() : Company::Get(e - PFE_AI0)->ai_instance->GetAllocatedMemory();
595 DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_BYTES_GOOD, value), TC_FROMSTRING, SA_RIGHT);
597 drawable--;
598 if (drawable == 0) break;
599 } else if (e == PFE_SOUND) {
602 drawable--;
603 if (drawable == 0) break;
604 } else {
605 /* skip non-script */
607 drawable--;
608 if (drawable == 0) break;
609 }
610 }
611 }
612
613 void DrawWidget(const Rect &r, WidgetID widget) const override
614 {
615 switch (widget) {
616 case WID_FRW_TIMES_NAMES: {
617 /* Render a column of titles for performance element names */
618 const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
619 int32_t skip = sb->GetPosition();
620 int drawable = this->num_displayed;
621 int y = r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; // first line contains headings in the value columns
622 for (PerformanceElement e : DISPLAY_ORDER_PFE) {
623 if (_pf_data[e].num_valid == 0) continue;
624 if (skip > 0) {
625 skip--;
626 } else {
627 if (e < PFE_AI0) {
628 DrawString(r.left, r.right, y, STR_FRAMERATE_GAMELOOP + e, TC_FROMSTRING, SA_LEFT);
629 } else {
630 DrawString(r.left, r.right, y, GetString(STR_FRAMERATE_AI, e - PFE_AI0 + 1, GetAIName(e - PFE_AI0)), TC_FROMSTRING, SA_LEFT);
631 }
633 drawable--;
634 if (drawable == 0) break;
635 }
636 }
637 break;
638 }
639 case WID_FRW_TIMES_CURRENT:
640 /* Render short-term average values */
642 break;
643 case WID_FRW_TIMES_AVERAGE:
644 /* Render averages of all recorded values */
646 break;
647 case WID_FRW_ALLOCSIZE:
648 DrawElementAllocationsColumn(r);
649 break;
650 }
651 }
652
653 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
654 {
655 switch (widget) {
656 case WID_FRW_TIMES_NAMES:
657 case WID_FRW_TIMES_CURRENT:
658 case WID_FRW_TIMES_AVERAGE: {
659 /* Open time graph windows when clicking detail measurement lines */
660 const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
662 if (line != INT32_MAX) {
663 line++;
664 /* Find the visible line that was clicked */
665 for (PerformanceElement e : DISPLAY_ORDER_PFE) {
666 if (_pf_data[e].num_valid > 0) line--;
667 if (line == 0) {
669 break;
670 }
671 }
672 }
673 break;
674 }
675 }
676 }
677
678 void OnResize() override
679 {
680 auto *wid = this->GetWidget<NWidgetResizeBase>(WID_FRW_TIMES_NAMES);
681 this->num_displayed = (wid->current_y - wid->min_y - WidgetDimensions::scaled.vsep_normal) / GetCharacterHeight(FS_NORMAL) - 1; // subtract 1 for headings
682 this->GetScrollbar(WID_FRW_SCROLLBAR)->SetCapacity(this->num_displayed);
683 }
684};
685
686static WindowDesc _framerate_display_desc(
687 WDP_AUTO, "framerate_display", 0, 0,
689 {},
690 _framerate_window_widgets
691);
692
693
695static constexpr NWidgetPart _frametime_graph_window_widgets[] = {
697 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
698 NWidget(WWT_CAPTION, COLOUR_GREY, WID_FGW_CAPTION), SetTextStyle(TC_WHITE),
699 NWidget(WWT_STICKYBOX, COLOUR_GREY),
700 EndContainer(),
701 NWidget(WWT_PANEL, COLOUR_GREY),
703 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_FGW_GRAPH),
704 EndContainer(),
705 EndContainer(),
706};
707
711
714
716 {
717 this->InitNested(number);
718 this->UpdateScale();
719 }
720
721 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
722 {
723 switch (widget) {
724 case WID_FGW_CAPTION:
725 if (this->element < PFE_AI0) {
727 }
728 return GetString(STR_FRAMETIME_CAPTION_AI, this->element - PFE_AI0 + 1, GetAIName(this->element - PFE_AI0));
729
730 default:
731 return this->Window::GetWidgetString(widget, stringid);
732 }
733 }
734
736 {
737 if (widget == WID_FGW_GRAPH) {
740
741 /* Size graph in height to fit at least 10 vertical labels with space between, or at least 100 pixels */
742 graph_size.height = std::max(100u, 10 * (size_ms_label.height + 1));
743 /* Always 2:1 graph area */
744 graph_size.width = 2 * graph_size.height;
745 size = graph_size;
746
747 size.width += size_ms_label.width + 2;
748 size.height += size_s_label.height + 2;
749 }
750 }
751
752 void SelectHorizontalScale(TimingMeasurement range)
753 {
754 /* 60 Hz graphical drawing results in a value of approximately TIMESTAMP_PRECISION,
755 * this lands exactly on the scale = 2 vs scale = 4 boundary.
756 * To avoid excessive switching of the horizontal scale, bias these performance
757 * categories away from this scale boundary. */
758 if (this->element == PFE_DRAWING || this->element == PFE_DRAWWORLD) range += (range / 2);
759
760 /* Determine horizontal scale based on period covered by 60 points
761 * (slightly less than 2 seconds at full game speed) */
762 struct ScaleDef { TimingMeasurement range; int scale; };
763 static const std::initializer_list<ScaleDef> hscales = {
764 { TIMESTAMP_PRECISION * 120, 60 },
765 { TIMESTAMP_PRECISION * 10, 20 },
766 { TIMESTAMP_PRECISION * 5, 10 },
767 { TIMESTAMP_PRECISION * 3, 4 },
768 { TIMESTAMP_PRECISION * 1, 2 },
769 };
770 for (const auto &sc : hscales) {
771 if (range < sc.range) this->horizontal_scale = sc.scale;
772 }
773 }
774
775 void SelectVerticalScale(TimingMeasurement range)
776 {
777 /* Determine vertical scale based on peak value (within the horizontal scale + a bit) */
778 static const std::initializer_list<TimingMeasurement> vscales = {
788 };
789 for (const auto &sc : vscales) {
790 if (range < sc) this->vertical_scale = (int)sc;
791 }
792 }
793
796 {
797 const auto &durations = _pf_data[this->element].durations;
798 const auto &timestamps = _pf_data[this->element].timestamps;
799 int num_valid = _pf_data[this->element].num_valid;
800 int point = _pf_data[this->element].prev_index;
801
802 TimingMeasurement lastts = timestamps[point];
805 int count = 0;
806
807 /* Sensible default for when too few measurements are available */
808 this->horizontal_scale = 4;
809
810 for (int i = 1; i < num_valid; i++) {
811 point--;
812 if (point < 0) point = NUM_FRAMERATE_POINTS - 1;
813
814 TimingMeasurement value = durations[point];
816 /* Skip gaps in data by pretending time is continuous across them */
817 lastts = timestamps[point];
818 continue;
819 }
820 if (value > peak_value) peak_value = value;
821 count++;
822
823 /* Accumulate period of time covered by data */
824 time_sum += lastts - timestamps[point];
825 lastts = timestamps[point];
826
827 /* Enough data to select a range and get decent data density */
828 if (count == 60) this->SelectHorizontalScale(time_sum);
829
830 /* End when enough points have been collected and the horizontal scale has been exceeded */
831 if (count >= 60 && time_sum >= (this->horizontal_scale + 2) * TIMESTAMP_PRECISION / 2) break;
832 }
833
834 this->SelectVerticalScale(peak_value);
835 }
836
838 IntervalTimer<TimerWindow> update_interval = {std::chrono::milliseconds(500), [this](auto) {
839 this->UpdateScale();
840 }};
841
842 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
843 {
844 this->SetDirty();
845 }
846
848 template <typename T>
849 static inline T Scinterlate(T dst_min, T dst_max, T src_min, T src_max, T value)
850 {
853 return (value - src_min) * dst_diff / src_diff + dst_min;
854 }
855
856 void DrawWidget(const Rect &r, WidgetID widget) const override
857 {
858 if (widget == WID_FGW_GRAPH) {
859 const auto &durations = _pf_data[this->element].durations;
860 const auto &timestamps = _pf_data[this->element].timestamps;
861 int point = _pf_data[this->element].prev_index;
862
863 const int x_zero = r.right - (int)this->graph_size.width;
864 const int x_max = r.right;
865 const int y_zero = r.top + (int)this->graph_size.height;
866 const int y_max = r.top;
867 const int c_grid = PC_DARK_GREY;
868 const int c_lines = PC_BLACK;
869 const int c_peak = PC_DARK_RED;
870
871 const TimingMeasurement draw_horz_scale = (TimingMeasurement)this->horizontal_scale * TIMESTAMP_PRECISION / 2;
872 const TimingMeasurement draw_vert_scale = (TimingMeasurement)this->vertical_scale;
873
874 /* Number of \c horizontal_scale units in each horizontal division */
875 const uint horz_div_scl = (this->horizontal_scale <= 20) ? 1 : 10;
876 /* Number of divisions of the horizontal axis */
877 const uint horz_divisions = this->horizontal_scale / horz_div_scl;
878 /* Number of divisions of the vertical axis */
879 const uint vert_divisions = 10;
880
881 /* Draw division lines and labels for the vertical axis */
882 for (uint division = 0; division < vert_divisions; division++) {
883 int y = Scinterlate(y_zero, y_max, 0, (int)vert_divisions, (int)division);
884 GfxDrawLine(x_zero, y, x_max, y, c_grid);
885 if (division % 2 == 0) {
886 if ((TimingMeasurement)this->vertical_scale > TIMESTAMP_PRECISION) {
889 TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
890 } else {
892 GetString(STR_FRAMERATE_GRAPH_MILLISECONDS, this->vertical_scale * division / 10 * 1000 / TIMESTAMP_PRECISION),
893 TC_GREY, SA_RIGHT | SA_FORCE, false, FS_SMALL);
894 }
895 }
896 }
897 /* Draw division lines and labels for the horizontal axis */
898 for (uint division = horz_divisions; division > 0; division--) {
899 int x = Scinterlate(x_zero, x_max, 0, (int)horz_divisions, (int)horz_divisions - (int)division);
900 GfxDrawLine(x, y_max, x, y_zero, c_grid);
901 if (division % 2 == 0) {
902 DrawString(x, x_max, y_zero + 2,
904 TC_GREY, SA_LEFT | SA_FORCE, false, FS_SMALL);
905 }
906 }
907
908 /* Position of last rendered data point */
909 Point lastpoint = {
910 x_max,
911 (int)Scinterlate<int64_t>(y_zero, y_max, 0, this->vertical_scale, durations[point])
912 };
913 /* Timestamp of last rendered data point */
914 TimingMeasurement lastts = timestamps[point];
915
917 Point peak_point = { 0, 0 };
920 int points_drawn = 0;
921
922 for (int i = 1; i < NUM_FRAMERATE_POINTS; i++) {
923 point--;
924 if (point < 0) point = NUM_FRAMERATE_POINTS - 1;
925
926 TimingMeasurement value = durations[point];
928 /* Skip gaps in measurements, pretend the data points on each side are continuous */
929 lastts = timestamps[point];
930 continue;
931 }
932
933 /* Use total time period covered for value along horizontal axis */
934 time_sum += lastts - timestamps[point];
935 lastts = timestamps[point];
936 /* Stop if past the width of the graph */
937 if (time_sum > draw_horz_scale) break;
938
939 /* Draw line from previous point to new point */
940 Point newpoint = {
943 };
944 if (newpoint.x > lastpoint.x) continue; // don't draw backwards
945 GfxDrawLine(lastpoint.x, lastpoint.y, newpoint.x, newpoint.y, c_lines);
947
948 /* Record peak and average value across graphed data */
949 value_sum += value;
950 points_drawn++;
951 if (value > peak_value) {
952 peak_value = value;
954 }
955 }
956
957 /* If the peak value is significantly larger than the average, mark and label it */
960 GfxFillRect(peak_point.x - 1, peak_point.y - 1, peak_point.x + 1, peak_point.y + 1, c_peak);
961 uint64_t value = peak_value * 1000 / TIMESTAMP_PRECISION;
962 int label_y = std::max(y_max, peak_point.y - GetCharacterHeight(FS_SMALL));
963 if (peak_point.x - x_zero > (int)this->graph_size.width / 2) {
965 } else {
967 }
968 }
969 }
970 }
971};
972
973static WindowDesc _frametime_graph_window_desc(
974 WDP_AUTO, "frametime_graph", 140, 90,
976 {},
977 _frametime_graph_window_widgets
978);
979
980
981
984{
985 AllocateWindowDescFront<FramerateWindow>(_framerate_display_desc, 0);
986}
987
990{
991 if (elem < PFE_FIRST || elem >= PFE_MAX) return; // maybe warn?
992 AllocateWindowDescFront<FrametimeGraphWindow>(_frametime_graph_window_desc, elem);
993}
994
997{
998 const int count1 = NUM_FRAMERATE_POINTS / 8;
999 const int count2 = NUM_FRAMERATE_POINTS / 4;
1000 const int count3 = NUM_FRAMERATE_POINTS / 1;
1001
1002 IConsolePrint(TC_SILVER, "Based on num. data points: {} {} {}", count1, count2, count3);
1003
1004 static const std::array<std::string_view, PFE_MAX> MEASUREMENT_NAMES = {
1005 "Game loop",
1006 " GL station ticks",
1007 " GL train ticks",
1008 " GL road vehicle ticks",
1009 " GL ship ticks",
1010 " GL aircraft ticks",
1011 " GL landscape ticks",
1012 " GL link graph delays",
1013 "Drawing",
1014 " Viewport drawing",
1015 "Video output",
1016 "Sound mixing",
1017 "AI/GS scripts total",
1018 "Game script",
1019 };
1020 std::string ai_name_buf;
1021
1022 bool printed_anything = false;
1023
1024 for (const auto &e : { PFE_GAMELOOP, PFE_DRAWING, PFE_VIDEO }) {
1025 auto &pf = _pf_data[e];
1026 if (pf.num_valid == 0) continue;
1027 IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)",
1028 MEASUREMENT_NAMES[e],
1029 pf.GetRate(),
1030 pf.expected_rate);
1031 printed_anything = true;
1032 }
1033
1034 for (PerformanceElement e = PFE_FIRST; e < PFE_MAX; e++) {
1035 auto &pf = _pf_data[e];
1036 if (pf.num_valid == 0) continue;
1037 std::string_view name;
1038 if (e < PFE_AI0) {
1039 name = MEASUREMENT_NAMES[e];
1040 } else {
1041 ai_name_buf = fmt::format("AI {} {}", e - PFE_AI0 + 1, GetAIName(e - PFE_AI0));
1042 name = ai_name_buf;
1043 }
1044 IConsolePrint(TC_LIGHT_BLUE, "{} times: {:.2f}ms {:.2f}ms {:.2f}ms",
1045 name,
1046 pf.GetAverageDurationMilliseconds(count1),
1047 pf.GetAverageDurationMilliseconds(count2),
1048 pf.GetAverageDurationMilliseconds(count3));
1049 printed_anything = true;
1050 }
1051
1052 if (!printed_anything) {
1053 IConsolePrint(CC_ERROR, "No performance measurements have been taken yet.");
1054 }
1055}
1056
1065{
1066 if (_sound_perf_pending.load(std::memory_order_acquire)) {
1067 std::lock_guard lk(_sound_perf_lock);
1068 for (size_t i = 0; i < _sound_perf_measurements.size(); i += 2) {
1069 _pf_data[PFE_SOUND].Add(_sound_perf_measurements[i], _sound_perf_measurements[i + 1]);
1070 }
1071 _sound_perf_measurements.clear();
1072 _sound_perf_pending.store(false, std::memory_order_relaxed);
1073 }
1074}
AIInfo keeps track of all information of an AI, like Author, Description, ...
The AIInstance tracks an AI.
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:96
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
~PerformanceAccumulator()
Finish and add one block of the accumulating value.
static void Reset(PerformanceElement elem)
Store the previous accumulator value and reset for a new cycle of accumulating measurements.
PerformanceAccumulator(PerformanceElement elem)
Begin measuring one block of the accumulating value.
static void SetInactive(PerformanceElement elem)
Mark a performance element as not currently in use.
static void Paused(PerformanceElement elem)
Indicate that a cycle of "pause" where no processing occurs.
void SetExpectedRate(double rate)
Set the rate of expected cycles per second of a performance element.
PerformanceMeasurer(PerformanceElement elem)
Begin a cycle of a measured element.
~PerformanceMeasurer()
Finish a cycle of a measured element and store the measurement taken.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2447
size_type GetPosition() const
Gets the position of the first visible element in the list.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Definition of stuff that is very close to a company, like the company struct itself.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition console.cpp:89
Console functions used outside of the console code.
Globally used console related types.
static const TextColour CC_ERROR
Colour for error lines.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
void ShowFramerateWindow()
Open the general framerate window.
static TimingMeasurement GetPerformanceTimer()
Return a timestamp with TIMESTAMP_PRECISION ticks per second precision.
void ProcessPendingPerformanceMeasurements()
This drains the PFE_SOUND measurement data queue into _pf_data.
void ShowFrametimeGraphWindow(PerformanceElement elem)
Open a graph window for a performance element.
void ConPrintFramerate()
Print performance statistics to game console.
Types for recording game performance data.
PerformanceElement
Elements of game performance that can be measured.
@ PFE_AI6
AI execution for player slot 7.
@ PFE_AI1
AI execution for player slot 2.
@ PFE_GAMELOOP
Speed of gameloop processing.
@ PFE_AI9
AI execution for player slot 10.
@ PFE_GL_SHIPS
Time spent processing ships.
@ PFE_AI3
AI execution for player slot 4.
@ PFE_AI4
AI execution for player slot 5.
@ PFE_AI11
AI execution for player slot 12.
@ PFE_AI8
AI execution for player slot 9.
@ PFE_GAMESCRIPT
Game script execution.
@ PFE_VIDEO
Speed of painting drawn video buffer.
@ PFE_GL_LINKGRAPH
Time spent waiting for link graph background jobs.
@ PFE_AI13
AI execution for player slot 14.
@ PFE_AI7
AI execution for player slot 8.
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
@ PFE_GL_ECONOMY
Time spent processing cargo movement.
@ PFE_AI0
AI execution for player slot 1.
@ PFE_DRAWING
Speed of drawing world and GUI.
@ PFE_AI12
AI execution for player slot 13.
@ PFE_AI2
AI execution for player slot 3.
@ PFE_AI10
AI execution for player slot 11.
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
@ PFE_GL_ROADVEHS
Time spend processing road vehicles.
@ PFE_GL_TRAINS
Time spent processing trains.
@ PFE_MAX
End of enum, must be last.
@ PFE_ALLSCRIPTS
Sum of all GS/AI scripts.
@ PFE_SOUND
Speed of mixing audio samples.
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
@ PFE_AI14
AI execution for player slot 15.
@ PFE_AI5
AI execution for player slot 6.
uint64_t TimingMeasurement
Type used to hold a performance timing measurement.
Types related to the framerate windows widgets.
Base functions for all Games.
The GameInstance tracks games.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:852
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
Functions related to the gfx engine.
@ FS_SMALL
Index of the small font in the font tables.
Definition gfx_type.h:246
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:245
@ SA_LEFT
Left align the text.
Definition gfx_type.h:377
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:379
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:389
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:387
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:296
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition gfx_type.h:319
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition gfx_type.h:359
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:945
const TimingMeasurement TIMESTAMP_PRECISION
Units a second is divided into in performance measurements
static const double GL_RATE
Game loop rate, cycles per second
const int NUM_FRAMERATE_POINTS
Number of data points to keep in buffer for each performance measurement.
PerformanceData _pf_data[PFE_MAX]
Storage for all performance element measurements.
size_t GetSoundPoolAllocatedMemory()
Get size of memory allocated to sound effects.
Functions related to NewGRF provided sounds.
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
static const uint8_t PC_BLACK
Black palette colour.
static const uint8_t PC_DARK_RED
Dark red palette colour.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:58
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:230
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
GUISettings gui
settings related to the GUI
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Dimensions (a width and height) of a rectangle in 2D.
void OnResize() override
Called after the window got resized.
void DrawElementTimesColumn(const Rect &r, StringID heading_str, std::span< const CachedDecimal > values) const
Render a column of formatted average durations.
CachedDecimal rate_drawing
cached drawing frame rate
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::array< CachedDecimal, PFE_MAX > times_longterm
cached long term average times
std::array< CachedDecimal, PFE_MAX > times_shortterm
cached short term average times
IntervalTimer< TimerWindow > update_interval
Update the window on a regular interval.
CachedDecimal speed_gameloop
cached game loop speed factor
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
CachedDecimal rate_gameloop
cached game loop tick rate
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr int MIN_ELEMENTS
smallest number of elements to display
int horizontal_scale
number of half-second units horizontally
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void UpdateScale()
Recalculate the graph scaling factors based on current recorded data.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
IntervalTimer< TimerWindow > update_interval
Update the scaling on a regular interval.
Dimension graph_size
size of the main graph area (excluding axis labels)
PerformanceElement element
what element this window renders graph for
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static T Scinterlate(T dst_min, T dst_max, T src_min, T src_max, T value)
Scale and interpolate a value from a source range into a destination range.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
int vertical_scale
number of TIMESTAMP_PRECISION units vertically
uint16_t refresh_rate
How often we refresh the screen (time between draw-ticks).
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static Titem * Get(auto index)
Returns Titem with given index.
Specification of a rectangle with absolute coordinates of all edges.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
ResizeInfo resize
Resize information.
Definition window_gui.h:315
int scale
Scale of this window – used to determine how to resize.
Definition window_gui.h:305
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:558
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1751
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
int next_index
Next index to write to in durations and timestamps.
std::array< TimingMeasurement, NUM_FRAMERATE_POINTS > durations
Time spent processing each cycle of the performance element, circular buffer.
void AddAccumulate(TimingMeasurement duration)
Accumulate a period onto the current measurement.
double GetAverageDurationMilliseconds(int count)
Get average cycle processing time over a number of data points.
double expected_rate
Expected number of cycles per second when the system is running without slowdowns.
int prev_index
Last index written to in durations and timestamps.
double GetRate()
Get current rate of a performance element, based on approximately the past one second of data.
int num_valid
Number of data points recorded, clamped to NUM_FRAMERATE_POINTS.
void AddPause(TimingMeasurement start_time)
Indicate a pause/expected discontinuity in processing the element.
PerformanceData(double expected_rate)
Initialize a data element with an expected collection rate.
static const TimingMeasurement INVALID_DURATION
Duration value indicating the value is not valid should be considered a gap in measurements.
void BeginAccumulate(TimingMeasurement start_time)
Begin an accumulation of multiple measurements into a single value, from a given start time.
std::array< TimingMeasurement, NUM_FRAMERATE_POINTS > timestamps
Start time of each cycle of the performance element, circular buffer.
void Add(TimingMeasurement start_time, TimingMeasurement end_time)
Collect a complete measurement, given start and ending times for a processing block.
Definition of Interval and OneShot timers.
Definition of the Window system.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:54
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:75
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:58
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:48
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2027
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_FRAMETIME_GRAPH
Frame time graph; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_FRAMERATE_DISPLAY
Framerate display; Window numbers: