Add 'printFPS' config entry to continuously print FPS to console
Useful on platforms that don't have window decorations.
This commit is contained in:
		
							parent
							
								
									b4bca7ea3b
								
							
						
					
					
						commit
						7cbf81c83a
					
				
					 5 changed files with 78 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -142,6 +142,7 @@ namespace po = boost::program_options;
 | 
			
		|||
Config::Config()
 | 
			
		||||
    : rgssVersion(0),
 | 
			
		||||
      debugMode(false),
 | 
			
		||||
      printFPS(false),
 | 
			
		||||
      winResizable(false),
 | 
			
		||||
      fullscreen(false),
 | 
			
		||||
      fixedAspectRatio(true),
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +170,7 @@ void Config::read(int argc, char *argv[])
 | 
			
		|||
#define PO_DESC_ALL \
 | 
			
		||||
	PO_DESC(rgssVersion, int) \
 | 
			
		||||
	PO_DESC(debugMode, bool) \
 | 
			
		||||
	PO_DESC(printFPS, bool) \
 | 
			
		||||
	PO_DESC(winResizable, bool) \
 | 
			
		||||
	PO_DESC(fullscreen, bool) \
 | 
			
		||||
	PO_DESC(fixedAspectRatio, bool) \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										44
									
								
								src/config.h
									
										
									
									
									
								
							
							
						
						
									
										44
									
								
								src/config.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -25,11 +25,55 @@
 | 
			
		|||
#include <string>
 | 
			
		||||
#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
 | 
			
		||||
{
 | 
			
		||||
	int rgssVersion;
 | 
			
		||||
 | 
			
		||||
	bool debugMode;
 | 
			
		||||
	bool printFPS;
 | 
			
		||||
 | 
			
		||||
	bool winResizable;
 | 
			
		||||
	bool fullscreen;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,12 +87,14 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
			
		|||
 | 
			
		||||
	fps.lastFrame = SDL_GetPerformanceCounter();
 | 
			
		||||
	fps.displayCounter = 0;
 | 
			
		||||
	fps.displaying = false;
 | 
			
		||||
	fps.immInitFlag = false;
 | 
			
		||||
	fps.immFiniFlag = false;
 | 
			
		||||
	fps.acc = 0;
 | 
			
		||||
	fps.accDiv = 0;
 | 
			
		||||
 | 
			
		||||
	if (rtData.config.printFPS)
 | 
			
		||||
		fps.sendUpdates.set();
 | 
			
		||||
 | 
			
		||||
	bool displayingFPS = false;
 | 
			
		||||
 | 
			
		||||
	bool cursorInWindow = false;
 | 
			
		||||
	bool windowFocused = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -210,14 +212,18 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
			
		|||
 | 
			
		||||
			if (event.key.keysym.scancode == SDL_SCANCODE_F2)
 | 
			
		||||
			{
 | 
			
		||||
				if (!fps.displaying)
 | 
			
		||||
				if (!displayingFPS)
 | 
			
		||||
				{
 | 
			
		||||
					fps.immInitFlag = true;
 | 
			
		||||
					fps.displaying = true;
 | 
			
		||||
					fps.immInitFlag.set();
 | 
			
		||||
					fps.sendUpdates.set();
 | 
			
		||||
					displayingFPS = true;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					fps.displaying = false;
 | 
			
		||||
					displayingFPS = false;
 | 
			
		||||
 | 
			
		||||
					if (!rtData.config.printFPS)
 | 
			
		||||
						fps.sendUpdates.clear();
 | 
			
		||||
 | 
			
		||||
					if (fullscreen)
 | 
			
		||||
					{
 | 
			
		||||
| 
						 | 
				
			
			@ -333,7 +339,10 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
			
		|||
				break;
 | 
			
		||||
 | 
			
		||||
			case UPDATE_FPS :
 | 
			
		||||
				if (!fps.displaying)
 | 
			
		||||
				if (rtData.config.printFPS)
 | 
			
		||||
					Debug() << "FPS:" << event.user.code;
 | 
			
		||||
 | 
			
		||||
				if (!fps.sendUpdates)
 | 
			
		||||
					break;
 | 
			
		||||
 | 
			
		||||
				snprintf(buffer, sizeof(buffer), "%s - %d FPS",
 | 
			
		||||
| 
						 | 
				
			
			@ -458,7 +467,7 @@ bool EventThread::getShowCursor() const
 | 
			
		|||
 | 
			
		||||
void EventThread::notifyFrame()
 | 
			
		||||
{
 | 
			
		||||
	if (!fps.displaying)
 | 
			
		||||
	if (!fps.sendUpdates)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	uint64_t current = SDL_GetPerformanceCounter();
 | 
			
		||||
| 
						 | 
				
			
			@ -467,8 +476,8 @@ void EventThread::notifyFrame()
 | 
			
		|||
 | 
			
		||||
	if (fps.immInitFlag)
 | 
			
		||||
	{
 | 
			
		||||
		fps.immInitFlag = false;
 | 
			
		||||
		fps.immFiniFlag = true;
 | 
			
		||||
		fps.immInitFlag.clear();
 | 
			
		||||
		fps.immFiniFlag.set();
 | 
			
		||||
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -484,7 +493,7 @@ void EventThread::notifyFrame()
 | 
			
		|||
		return;
 | 
			
		||||
 | 
			
		||||
	fps.displayCounter = 0;
 | 
			
		||||
	fps.immFiniFlag = false;
 | 
			
		||||
	fps.immFiniFlag.clear();
 | 
			
		||||
 | 
			
		||||
	int32_t avgFPS = fps.acc / fps.accDiv;
 | 
			
		||||
	fps.acc = fps.accDiv = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,9 +98,9 @@ private:
 | 
			
		|||
	{
 | 
			
		||||
		uint64_t lastFrame;
 | 
			
		||||
		uint64_t displayCounter;
 | 
			
		||||
		bool displaying;
 | 
			
		||||
		bool immInitFlag;
 | 
			
		||||
		bool immFiniFlag;
 | 
			
		||||
		AtomicFlag sendUpdates;
 | 
			
		||||
		AtomicFlag immInitFlag;
 | 
			
		||||
		AtomicFlag immFiniFlag;
 | 
			
		||||
		double acc;
 | 
			
		||||
		uint32_t accDiv;
 | 
			
		||||
	} fps;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue