Ups, add missing file.

This commit is contained in:
Christian Speckner 2018-07-30 23:35:56 +02:00
parent 3a5572d3b9
commit b612d22364
2 changed files with 136 additions and 0 deletions

70
src/common/FpsMeter.cxx Normal file
View File

@ -0,0 +1,70 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2018 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "FpsMeter.hxx"
using namespace std::chrono;
FpsMeter::FpsMeter(uInt32 queueSize)
: myQueue(queueSize)
{
reset();
}
void FpsMeter::reset(uInt32 garbageFrameLimit)
{
myQueue.clear();
myQueueOffset = 0;
myFrameCount = 0;
myFps = 0;
myGarbageFrameCounter = 0;
myGarbageFrameLimit = garbageFrameLimit;
}
void FpsMeter::render(uInt32 frameCount)
{
if (myGarbageFrameCounter < myGarbageFrameLimit) {
myGarbageFrameCounter += frameCount;
return;
}
uInt32 queueSize = myQueue.capacity();
entry first, last = (entry){.frames = frameCount, .timestamp = high_resolution_clock::now()};
if (myQueue.size() < queueSize) {
myQueue.push_back(last);
myFrameCount += frameCount;
first = myQueue.at(myQueueOffset);
} else {
myFrameCount = myFrameCount - myQueue.at(myQueueOffset).frames + frameCount;
myQueue.at(myQueueOffset) = last;
myQueueOffset = (myQueueOffset + 1) % queueSize;
first = myQueue.at(myQueueOffset);
}
float myTimeInterval =
duration_cast<duration<float>>(last.timestamp - first.timestamp).count();
if (myTimeInterval > 0) myFps = (myFrameCount - first.frames) / myTimeInterval;
}
float FpsMeter::fps() const
{
return myFps;
}

66
src/common/FpsMeter.hxx Normal file
View File

@ -0,0 +1,66 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2018 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef FPS_METER_HXX
#define FPS_METER_HXX
#include <chrono>
#include "bspf.hxx"
class FpsMeter
{
public:
FpsMeter(uInt32 queueSize);
void reset(uInt32 garbageFrameLimit = 0);
void render(uInt32 frameCount);
float fps() const;
private:
struct entry {
uInt32 frames;
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
};
private:
vector<entry> myQueue;
uInt32 myQueueOffset;
uInt32 myFrameCount;
uInt32 myGarbageFrameCounter;
uInt32 myGarbageFrameLimit;
float myFps;
private:
FpsMeter(const FpsMeter&) = delete;
FpsMeter(FpsMeter&&) = delete;
FpsMeter& operator=(const FpsMeter&) = delete;
FpsMeter& operator=(FpsMeter&&) = delete;
};
#endif // FPS_METER_HXX