| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #ifndef FPS_METER_HXX |
| 19 | #define FPS_METER_HXX |
| 20 | |
| 21 | #include <chrono> |
| 22 | |
| 23 | #include "bspf.hxx" |
| 24 | |
| 25 | class FpsMeter |
| 26 | { |
| 27 | public: |
| 28 | |
| 29 | explicit FpsMeter(uInt32 queueSize); |
| 30 | |
| 31 | void reset(uInt32 garbageFrameLimit = 0); |
| 32 | |
| 33 | void render(uInt32 frameCount); |
| 34 | |
| 35 | float fps() const; |
| 36 | |
| 37 | private: |
| 38 | |
| 39 | struct entry { |
| 40 | uInt32 frames; |
| 41 | std::chrono::time_point<std::chrono::high_resolution_clock> timestamp; |
| 42 | }; |
| 43 | |
| 44 | private: |
| 45 | |
| 46 | vector<entry> myQueue; |
| 47 | |
| 48 | uInt32 myQueueOffset; |
| 49 | |
| 50 | uInt32 myFrameCount; |
| 51 | |
| 52 | uInt32 myGarbageFrameCounter; |
| 53 | uInt32 myGarbageFrameLimit; |
| 54 | |
| 55 | float myFps; |
| 56 | |
| 57 | private: |
| 58 | |
| 59 | FpsMeter(const FpsMeter&) = delete; |
| 60 | FpsMeter(FpsMeter&&) = delete; |
| 61 | FpsMeter& operator=(const FpsMeter&) = delete; |
| 62 | FpsMeter& operator=(FpsMeter&&) = delete; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | #endif // FPS_METER_HXX |
| 67 | |