The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
tracked_drawable.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2025 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#pragma once
16
17#include "events.hpp"
18
19#include <boost/circular_buffer.hpp>
20
21#include <chrono>
23#include <tuple>
24
25namespace gui2
26{
27/**
28 * Middleware class that tracks framerate and times.
29 *
30 * It should be used in conjunction with classes that implement top_level_drawable.
31 * Strictly, it will measure the between invocations of update_count, which should
32 * be invoked from the render function.
33 */
35{
36public:
38
40 {
41 std::chrono::milliseconds min_time{};
42 std::chrono::milliseconds avg_time{};
43 std::chrono::milliseconds max_time{};
44
45 unsigned min_fps{};
46 unsigned avg_fps{};
47 unsigned max_fps{};
48 unsigned act_fps{};
49 };
50
51 /** Returns the current frame time and info, or nullopt if no times have been recorded. */
52 auto get_info() const -> utils::optional<frame_info>;
53
54protected:
56
57 /** Records time since last invocation. */
58 void update_count();
59
60private:
61 /** Inherited from events::pump_monitor. */
62 void process() override;
63
64 using clock = std::chrono::steady_clock;
65 using times = std::tuple<clock::duration, clock::duration, clock::duration>;
66
67 /** Get min, average, and max frametimes in steady_clock resolution. */
68 auto get_times() const -> times;
69
70 boost::circular_buffer<clock::duration> frametimes_;
71
72 unsigned render_count_;
74
75 clock::time_point last_lap_;
76 clock::time_point last_render_;
77};
78
79} // namespace gui2
Middleware class that tracks framerate and times.
void process() override
Inherited from events::pump_monitor.
clock::time_point last_render_
std::tuple< clock::duration, clock::duration, clock::duration > times
auto get_times() const -> times
Get min, average, and max frametimes in steady_clock resolution.
boost::circular_buffer< clock::duration > frametimes_
clock::time_point last_lap_
auto get_info() const -> utils::optional< frame_info >
Returns the current frame time and info, or nullopt if no times have been recorded.
void update_count()
Records time since last invocation.
std::chrono::steady_clock clock
Definition span.hpp:53
Generic file dialog.
STL namespace.
std::chrono::milliseconds min_time
std::chrono::milliseconds avg_time
std::chrono::milliseconds max_time