mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +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 <iostream>
|
||||
#include <iomanip>
|
||||
#include "Renderer.h"
|
||||
#include "components/GuiGameList.h"
|
||||
#include "SystemData.h"
|
||||
|
@ -198,12 +199,22 @@ int main(int argc, char* argv[])
|
|||
|
||||
if(DRAWFRAMERATE)
|
||||
{
|
||||
float framerate = 1/((float)deltaTime)*1000;
|
||||
std::stringstream ss;
|
||||
ss << framerate;
|
||||
std::string fps;
|
||||
ss >> fps;
|
||||
Renderer::drawText(fps, 50, 50, 0x00FF00FF, Renderer::getDefaultFont(Renderer::MEDIUM));
|
||||
static int timeElapsed = 0;
|
||||
static int nrOfFrames = 0;
|
||||
static std::string fpsString;
|
||||
|
||||
nrOfFrames++;
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue