diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 18:24:59 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 18:24:59 +0100 |
| commit | d060e3a50c987d10799ccc739bdbf9d7d7a13c10 (patch) | |
| tree | 4b5585383ada85608b57bcf76e5828817962fddf /lib/nes/common/fps-counter.hh | |
| parent | dbed1c0fa5599b1b96c221b89b10f1e350351645 (diff) | |
implement settings
Diffstat (limited to 'lib/nes/common/fps-counter.hh')
| -rw-r--r-- | lib/nes/common/fps-counter.hh | 23 |
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 |
