summaryrefslogtreecommitdiff
path: root/lib/nes/common/fps-counter.hh
blob: f921880728626d5d92e88b9b7b9e2d27169c3a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include "nes/common/types.hh"

namespace nes
{
	/// Counts frames.
	class fps_counter
	{
		static constexpr auto buffer_size = u32{ 20 };

		u32 frame_times_[buffer_size]{}; // The time until the next frame for the last <buffer_size> frames.
		u32 buffer_position_{ 0 }; // Position in the ring buffer.
		u32 buffered_fps_{ 0 }; // Delay updates to FPS to one update per round in the ring buffer.

	public:
		explicit fps_counter() = default;

		auto frame(u32 elapsed_time_us) -> void;
		auto get_fps() const -> u32 { return buffered_fps_; }
	};
} // namespace nes