From a8a1f8236fff67cbae595600abc7a9dfbf6e231d Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Wed, 20 Mar 2019 01:31:40 +0100 Subject: +cRender():setTargetFPS(uint) to set target Framerate if set >1 render sleeps until target frametime is reached --- src/cRender.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/cRender.h') diff --git a/src/cRender.h b/src/cRender.h index 42c3388..19a0367 100644 --- a/src/cRender.h +++ b/src/cRender.h @@ -5,6 +5,9 @@ #include #include #include +#include //clock() +#include +#include #ifdef __linux__ #include @@ -131,6 +134,14 @@ public: */ sPos getSize(); + /** Time in (real) seconds between last and second to last renders + */ + double getFrametime(); + + /** Sets target Framerate. 0 for unlimited + */ + void setTargetFPS(unsigned int _fps); + protected: /** Empty Constructor for being inheritable @@ -159,6 +170,12 @@ protected: unsigned int sizeX, sizeY; //* Size of screen array + //Timekeeping + unsigned int uTargetFPS; + clock_t lastRenderTime; + double lastFrameTime; + timespec lastRender; + #ifdef _WIN32 HANDLE hstdout; CONSOLE_SCREEN_BUFFER_INFO csbi; @@ -170,17 +187,20 @@ protected: int iLastError; private: + void forceReRender(); + + void setConsoleEcho(bool _enable); + + void printDebugInfo(); + + void waitForFrametime(); #ifdef _WIN32 int SetConsoleWindowSize(int x, int y); //Slightly adapted from: http://www.cplusplus.com/forum/windows/121444/ void gotoxy( int x, int y ); -#endif - - void forceReRender(); - void setConsoleEcho(bool _enable); -#ifdef __linux__ +#elif __linux__ sPos getConsoleWindowSize(); void setConsoleCursor(bool _enable); -- cgit v1.2.3