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

#include "nes/common/types.hh"
#include <chrono>

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(std::chrono::microseconds elapsed_time) -> void;
		auto get_fps() const -> u32 { return buffered_fps_; }
	};
} // namespace nes