framecounter.h

main 27 lines · 527 bytes Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1#include <atomic>
2#include <list>
3#include "../stdext/time.h"
4
5class FrameCounter {
6public:
7 void addFrame() // not thread-safe
8 {
9 ticks_t now = stdext::millis();
10 m_framesList.push_back(now);
11 m_frames += 1;
12 while (m_framesList.front() + 1000 < now) {
13 m_framesList.pop_front();
14 m_frames -= 1;
15 }
16 }
17
18 int getFps() // thread safe
19 {
20 return m_frames.load();
21 }
22
23private:
24 std::list<ticks_t> m_framesList;
25 std::atomic_int m_frames;
26};
27
Top