Add 'printFPS' config entry to continuously print FPS to console

Useful on platforms that don't have window decorations.
This commit is contained in:
Jonas Kulla 2014-12-24 06:23:28 +01:00
parent b4bca7ea3b
commit 7cbf81c83a
5 changed files with 78 additions and 15 deletions

View File

@ -17,6 +17,14 @@
# debugMode=false # debugMode=false
# Continuously print average FPS to console.
# This setting does not affect the window title
# FPS display toggled via F2
# (default: disabled)
#
# printFPS=false
# Game window is resizable # Game window is resizable
# (default: disabled) # (default: disabled)
# #

View File

@ -142,6 +142,7 @@ namespace po = boost::program_options;
Config::Config() Config::Config()
: rgssVersion(0), : rgssVersion(0),
debugMode(false), debugMode(false),
printFPS(false),
winResizable(false), winResizable(false),
fullscreen(false), fullscreen(false),
fixedAspectRatio(true), fixedAspectRatio(true),
@ -169,6 +170,7 @@ void Config::read(int argc, char *argv[])
#define PO_DESC_ALL \ #define PO_DESC_ALL \
PO_DESC(rgssVersion, int) \ PO_DESC(rgssVersion, int) \
PO_DESC(debugMode, bool) \ PO_DESC(debugMode, bool) \
PO_DESC(printFPS, bool) \
PO_DESC(winResizable, bool) \ PO_DESC(winResizable, bool) \
PO_DESC(fullscreen, bool) \ PO_DESC(fullscreen, bool) \
PO_DESC(fixedAspectRatio, bool) \ PO_DESC(fixedAspectRatio, bool) \

View File

@ -25,11 +25,55 @@
#include <string> #include <string>
#include <vector> #include <vector>
struct TouchOverlay
{
std::string image;
struct Button
{
enum Shape
{
Rectangle,
Circle,
Triangle
};
std::string id;
std::string target;
Shape shape;
int x;
int y;
union
{
struct
{
int width;
int height;
} r;
struct
{
int radius;
} c;
struct
{
int x1, y1;
int x2, y2;
} t;
} u;
};
std::vector<Button> buttons;
};
struct Config struct Config
{ {
int rgssVersion; int rgssVersion;
bool debugMode; bool debugMode;
bool printFPS;
bool winResizable; bool winResizable;
bool fullscreen; bool fullscreen;

View File

@ -87,12 +87,14 @@ void EventThread::process(RGSSThreadData &rtData)
fps.lastFrame = SDL_GetPerformanceCounter(); fps.lastFrame = SDL_GetPerformanceCounter();
fps.displayCounter = 0; fps.displayCounter = 0;
fps.displaying = false;
fps.immInitFlag = false;
fps.immFiniFlag = false;
fps.acc = 0; fps.acc = 0;
fps.accDiv = 0; fps.accDiv = 0;
if (rtData.config.printFPS)
fps.sendUpdates.set();
bool displayingFPS = false;
bool cursorInWindow = false; bool cursorInWindow = false;
bool windowFocused = false; bool windowFocused = false;
@ -210,14 +212,18 @@ void EventThread::process(RGSSThreadData &rtData)
if (event.key.keysym.scancode == SDL_SCANCODE_F2) if (event.key.keysym.scancode == SDL_SCANCODE_F2)
{ {
if (!fps.displaying) if (!displayingFPS)
{ {
fps.immInitFlag = true; fps.immInitFlag.set();
fps.displaying = true; fps.sendUpdates.set();
displayingFPS = true;
} }
else else
{ {
fps.displaying = false; displayingFPS = false;
if (!rtData.config.printFPS)
fps.sendUpdates.clear();
if (fullscreen) if (fullscreen)
{ {
@ -333,7 +339,10 @@ void EventThread::process(RGSSThreadData &rtData)
break; break;
case UPDATE_FPS : case UPDATE_FPS :
if (!fps.displaying) if (rtData.config.printFPS)
Debug() << "FPS:" << event.user.code;
if (!fps.sendUpdates)
break; break;
snprintf(buffer, sizeof(buffer), "%s - %d FPS", snprintf(buffer, sizeof(buffer), "%s - %d FPS",
@ -458,7 +467,7 @@ bool EventThread::getShowCursor() const
void EventThread::notifyFrame() void EventThread::notifyFrame()
{ {
if (!fps.displaying) if (!fps.sendUpdates)
return; return;
uint64_t current = SDL_GetPerformanceCounter(); uint64_t current = SDL_GetPerformanceCounter();
@ -467,8 +476,8 @@ void EventThread::notifyFrame()
if (fps.immInitFlag) if (fps.immInitFlag)
{ {
fps.immInitFlag = false; fps.immInitFlag.clear();
fps.immFiniFlag = true; fps.immFiniFlag.set();
return; return;
} }
@ -484,7 +493,7 @@ void EventThread::notifyFrame()
return; return;
fps.displayCounter = 0; fps.displayCounter = 0;
fps.immFiniFlag = false; fps.immFiniFlag.clear();
int32_t avgFPS = fps.acc / fps.accDiv; int32_t avgFPS = fps.acc / fps.accDiv;
fps.acc = fps.accDiv = 0; fps.acc = fps.accDiv = 0;

View File

@ -98,9 +98,9 @@ private:
{ {
uint64_t lastFrame; uint64_t lastFrame;
uint64_t displayCounter; uint64_t displayCounter;
bool displaying; AtomicFlag sendUpdates;
bool immInitFlag; AtomicFlag immInitFlag;
bool immFiniFlag; AtomicFlag immFiniFlag;
double acc; double acc;
uint32_t accDiv; uint32_t accDiv;
} fps; } fps;