mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Better frame rate / time display
Calculate and update every 500ms which makes it much more readable
This commit is contained in:
parent
cfee178f2f
commit
c8bf0cf652
23
src/main.cpp
23
src/main.cpp
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "components/GuiGameList.h"
|
#include "components/GuiGameList.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
|
@ -198,12 +199,22 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
if(DRAWFRAMERATE)
|
if(DRAWFRAMERATE)
|
||||||
{
|
{
|
||||||
float framerate = 1/((float)deltaTime)*1000;
|
static int timeElapsed = 0;
|
||||||
std::stringstream ss;
|
static int nrOfFrames = 0;
|
||||||
ss << framerate;
|
static std::string fpsString;
|
||||||
std::string fps;
|
|
||||||
ss >> fps;
|
nrOfFrames++;
|
||||||
Renderer::drawText(fps, 50, 50, 0x00FF00FF, Renderer::getDefaultFont(Renderer::MEDIUM));
|
timeElapsed += deltaTime;
|
||||||
|
//wait until half a second has passed to recalculate fps
|
||||||
|
if (timeElapsed >= 500) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::fixed << std::setprecision(1) << (1000.0f * (float)nrOfFrames / (float)timeElapsed) << "fps, ";
|
||||||
|
ss << std::fixed << std::setprecision(2) << ((float)timeElapsed / (float)nrOfFrames) << "ms";
|
||||||
|
fpsString = ss.str();
|
||||||
|
nrOfFrames = 0;
|
||||||
|
timeElapsed = 0;
|
||||||
|
}
|
||||||
|
Renderer::drawText(fpsString, 50, 50, 0x00FF00FF, Renderer::getDefaultFont(Renderer::MEDIUM));
|
||||||
}
|
}
|
||||||
|
|
||||||
//sleep if we're past our threshold
|
//sleep if we're past our threshold
|
||||||
|
|
Loading…
Reference in a new issue