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-2021 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{0}; 41 std::chrono::time_point<std::chrono::high_resolution_clock> timestamp; 42 }; 43 44 private: 45 46 vector<entry> myQueue; 47 48 uInt32 myQueueOffset{0}; 49 50 uInt32 myFrameCount{0}; 51 52 uInt32 myGarbageFrameCounter{0}; 53 uInt32 myGarbageFrameLimit{0}; 54 55 float myFps{0.F}; 56 57 private: 58 FpsMeter(const FpsMeter&) = delete; 59 FpsMeter(FpsMeter&&) = delete; 60 FpsMeter& operator=(const FpsMeter&) = delete; 61 FpsMeter& operator=(FpsMeter&&) = delete; 62 }; 63 64 #endif // FPS_METER_HXX 65