Simplify FPS management
This commit is contained in:
parent
888cbb99f2
commit
0997541fc7
|
@ -311,7 +311,7 @@ void xApplication::render(){
|
|||
|
||||
/** Sets FPS */
|
||||
void xApplication::setFps(const uint32_t fps){
|
||||
_fps = fps;
|
||||
_fpstime = 1000.0/fps;
|
||||
}
|
||||
|
||||
/** schedules the main loop */
|
||||
|
@ -322,19 +322,15 @@ void xApplication::schedule(){
|
|||
this->_controller.handleEvent(&event);
|
||||
|
||||
// wait to satisfy FPS
|
||||
this->syncFps(_fps);
|
||||
this->syncFps();
|
||||
|
||||
// render
|
||||
this->render();
|
||||
}
|
||||
|
||||
/** synchronizes according to @fps
|
||||
/** synchronizes according to FPS
|
||||
* to be used at the end of the UI loop */
|
||||
void xApplication::syncFps(const int fps){
|
||||
// set fps
|
||||
if( fps != 0 )
|
||||
_fpstime = 1000/fps;
|
||||
|
||||
void xApplication::syncFps(){
|
||||
if( _lasttick == 0 )
|
||||
_lasttick = SDL_GetTicks()-_fpstime;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
void render();
|
||||
|
||||
// manage main loop and thread loops
|
||||
void setFps(const uint32_t fps);
|
||||
void setFps(const uint32_t fps=0);
|
||||
void schedule();
|
||||
|
||||
xAppState state;
|
||||
|
@ -59,10 +59,9 @@
|
|||
xApplication(const char *t, int w, int h);
|
||||
static xApplication* _instance;
|
||||
|
||||
void syncFps(const int fps=0);
|
||||
void syncFps();
|
||||
|
||||
// fps management
|
||||
uint32_t _fps = 60;
|
||||
uint32_t _lasttick;
|
||||
uint32_t _fpstime;
|
||||
|
||||
|
|
Loading…
Reference in New Issue