summaryrefslogtreecommitdiff
path: root/lib/nes/common/fps-counter.hh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nes/common/fps-counter.hh')
-rw-r--r--lib/nes/common/fps-counter.hh23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/nes/common/fps-counter.hh b/lib/nes/common/fps-counter.hh
new file mode 100644
index 0000000..96db98c
--- /dev/null
+++ b/lib/nes/common/fps-counter.hh
@@ -0,0 +1,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 \ No newline at end of file