Simplify FPS management

This commit is contained in:
Adrien Marquès 2019-11-06 22:43:46 +01:00
parent 888cbb99f2
commit 0997541fc7
2 changed files with 6 additions and 11 deletions

View File

@ -311,7 +311,7 @@ void xApplication::render(){
/** Sets FPS */ /** Sets FPS */
void xApplication::setFps(const uint32_t fps){ void xApplication::setFps(const uint32_t fps){
_fps = fps; _fpstime = 1000.0/fps;
} }
/** schedules the main loop */ /** schedules the main loop */
@ -322,19 +322,15 @@ void xApplication::schedule(){
this->_controller.handleEvent(&event); this->_controller.handleEvent(&event);
// wait to satisfy FPS // wait to satisfy FPS
this->syncFps(_fps); this->syncFps();
// render // render
this->render(); this->render();
} }
/** synchronizes according to @fps /** synchronizes according to FPS
* to be used at the end of the UI loop */ * to be used at the end of the UI loop */
void xApplication::syncFps(const int fps){ void xApplication::syncFps(){
// set fps
if( fps != 0 )
_fpstime = 1000/fps;
if( _lasttick == 0 ) if( _lasttick == 0 )
_lasttick = SDL_GetTicks()-_fpstime; _lasttick = SDL_GetTicks()-_fpstime;

View File

@ -50,7 +50,7 @@
void render(); void render();
// manage main loop and thread loops // manage main loop and thread loops
void setFps(const uint32_t fps); void setFps(const uint32_t fps=0);
void schedule(); void schedule();
xAppState state; xAppState state;
@ -59,10 +59,9 @@
xApplication(const char *t, int w, int h); xApplication(const char *t, int w, int h);
static xApplication* _instance; static xApplication* _instance;
void syncFps(const int fps=0); void syncFps();
// fps management // fps management
uint32_t _fps = 60;
uint32_t _lasttick; uint32_t _lasttick;
uint32_t _fpstime; uint32_t _fpstime;