mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 09:48:51 +01:00
change input processing, rendering is now forced at the right times
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
parent
8aef81685d
commit
dd0d19bd38
@ -55,10 +55,7 @@
|
|||||||
#include <SDL/SDL_thread.h>
|
#include <SDL/SDL_thread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define REMOVE_TEST_FUNKEY
|
|
||||||
#define FUNKEY_ALL_POLLEVENT_DELAY 30 //ms
|
|
||||||
//#define PERIOD_FORCE_REFRESH 1000 //ms
|
//#define PERIOD_FORCE_REFRESH 1000 //ms
|
||||||
|
|
||||||
#define FPS 60 // TODO: set in conf file
|
#define FPS 60 // TODO: set in conf file
|
||||||
|
|
||||||
//#define DEBUG_FPS
|
//#define DEBUG_FPS
|
||||||
@ -86,6 +83,7 @@ RetroFE::RetroFE( Configuration &c )
|
|||||||
, keyDelayTime_(.3f)
|
, keyDelayTime_(.3f)
|
||||||
{
|
{
|
||||||
menuMode_ = false;
|
menuMode_ = false;
|
||||||
|
mustRender_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +128,6 @@ void RetroFE::render( )
|
|||||||
}
|
}
|
||||||
#endif //DEBUG_FPS
|
#endif //DEBUG_FPS
|
||||||
|
|
||||||
//SDL_RenderPresent( SDL::getRenderer( ) );
|
|
||||||
//SDL_Flip(SDL::getWindow( ));
|
//SDL_Flip(SDL::getWindow( ));
|
||||||
SDL::renderAndFlipWindow();
|
SDL::renderAndFlipWindow();
|
||||||
|
|
||||||
@ -506,24 +503,17 @@ void RetroFE::run( )
|
|||||||
|
|
||||||
float lastTime = 0;
|
float lastTime = 0;
|
||||||
float deltaTime = 0;
|
float deltaTime = 0;
|
||||||
bool must_render = false;
|
|
||||||
|
|
||||||
// Exit splash mode when an active key is pressed
|
// Exit splash mode when an active key is pressed
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
if ( splashMode && SDL_PollEvent( &e ) )
|
if ( splashMode )
|
||||||
{
|
{
|
||||||
|
while ( SDL_PollEvent( &e ) );
|
||||||
|
|
||||||
if ( input_.update( e ) && input_.keystate(UserInput::KeyCodeSelect) )
|
if ( input_.update( e ) && input_.keystate(UserInput::KeyCodeSelect) )
|
||||||
{
|
{
|
||||||
exitSplashMode = true;
|
exitSplashMode = true;
|
||||||
while ( SDL_PollEvent( &e ) )
|
while ( SDL_PollEvent( &e ) )
|
||||||
{
|
|
||||||
#ifndef REMOVE_TEST_FUNKEY
|
|
||||||
if ( e.type == SDL_JOYDEVICEADDED || e.type == SDL_JOYDEVICEREMOVED )
|
|
||||||
{
|
|
||||||
input_.update( e );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
input_.resetStates( );
|
input_.resetStates( );
|
||||||
attract_.reset( );
|
attract_.reset( );
|
||||||
}
|
}
|
||||||
@ -1021,12 +1011,12 @@ void RetroFE::run( )
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/// Launch menu
|
/// Launch menu
|
||||||
menuMode_ = true;
|
menuMode_ = true;
|
||||||
printf("Menu launched here\n");
|
printf("Menu launched here\n");
|
||||||
MenuMode::launch();
|
MenuMode::launch();
|
||||||
menuMode_ = false;
|
menuMode_ = false;
|
||||||
must_render = true;
|
forceRender(true);
|
||||||
|
|
||||||
/// Clear events
|
/// Clear events
|
||||||
SDL_Event ev;
|
SDL_Event ev;
|
||||||
@ -1094,13 +1084,13 @@ void RetroFE::run( )
|
|||||||
|
|
||||||
// ------- Check if previous update of page needed to be rendered -------
|
// ------- Check if previous update of page needed to be rendered -------
|
||||||
if(!currentPage_->isIdle( ) || splashMode){
|
if(!currentPage_->isIdle( ) || splashMode){
|
||||||
must_render = true;
|
forceRender(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force refresh variables
|
// Force refresh variables
|
||||||
#ifdef PERIOD_FORCE_REFRESH
|
#ifdef PERIOD_FORCE_REFRESH
|
||||||
if(SDL_GetTicks() - ticks_last_refresh > PERIOD_FORCE_REFRESH){
|
if(SDL_GetTicks() - ticks_last_refresh > PERIOD_FORCE_REFRESH){
|
||||||
must_render = true;
|
forceRender(true);
|
||||||
//printf("force render\n");
|
//printf("force render\n");
|
||||||
}
|
}
|
||||||
#endif //PERIOD_FORCE_REFRESH
|
#endif //PERIOD_FORCE_REFRESH
|
||||||
@ -1112,7 +1102,7 @@ void RetroFE::run( )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------- Real render here -------
|
// ------- Real render here -------
|
||||||
if(must_render){
|
if(mustRender_){
|
||||||
render( );
|
render( );
|
||||||
#ifdef PERIOD_FORCE_REFRESH
|
#ifdef PERIOD_FORCE_REFRESH
|
||||||
ticks_last_refresh = SDL_GetTicks();
|
ticks_last_refresh = SDL_GetTicks();
|
||||||
@ -1145,12 +1135,19 @@ bool RetroFE::back(bool &exit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Force render retroFE
|
||||||
|
void RetroFE::forceRender( bool render )
|
||||||
|
{
|
||||||
|
mustRender_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Process the user input
|
// Process the user input
|
||||||
RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page )
|
RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page )
|
||||||
{
|
{
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
RETROFE_STATE state = RETROFE_IDLE;
|
RETROFE_STATE state = RETROFE_IDLE;
|
||||||
|
#if 0
|
||||||
// Poll all events until we find an active one
|
// Poll all events until we find an active one
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while ( SDL_PollEvent( &e ) )
|
while ( SDL_PollEvent( &e ) )
|
||||||
@ -1160,6 +1157,11 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page )
|
|||||||
printf("How dare you interrupt me!\n");
|
printf("How dare you interrupt me!\n");
|
||||||
attract_.reset( );
|
attract_.reset( );
|
||||||
state = RETROFE_QUIT_REQUEST;
|
state = RETROFE_QUIT_REQUEST;
|
||||||
|
|
||||||
|
/* Finish polling events */
|
||||||
|
//SDL_Event e_trash;
|
||||||
|
//while ( SDL_PollEvent( &e_trash ) );
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1170,10 +1172,32 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page )
|
|||||||
}*/
|
}*/
|
||||||
if ( e.type == SDL_KEYDOWN )
|
if ( e.type == SDL_KEYDOWN )
|
||||||
{
|
{
|
||||||
//printf("e.key.keysym.sym = %d\n", e.key.keysym.sym);
|
//printf("e.key.keysym.sym = %d\n", e.key.keysym.sym);
|
||||||
|
|
||||||
|
/* Finish polling events */
|
||||||
|
//SDL_Event e_trash;
|
||||||
|
//while ( SDL_PollEvent( &e_trash ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Poll all events until we find an active one
|
||||||
|
SDL_Event e;
|
||||||
|
while ( SDL_PollEvent( &e ) );
|
||||||
|
|
||||||
|
if ( e.type == SDL_QUIT )
|
||||||
|
{
|
||||||
|
printf("How dare you interrupt me!\n");
|
||||||
|
attract_.reset( );
|
||||||
|
state = RETROFE_QUIT_REQUEST;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_.update(e);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Handle next/previous game inputs
|
// Handle next/previous game inputs
|
||||||
if ( page->isHorizontalScroll( ) )
|
if ( page->isHorizontalScroll( ) )
|
||||||
@ -1235,6 +1259,7 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page )
|
|||||||
{
|
{
|
||||||
keyLastTime_ = 0;
|
keyLastTime_ = 0;
|
||||||
keyDelayTime_= 0.3f;
|
keyDelayTime_= 0.3f;
|
||||||
|
forceRender(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( (currentTime_ - keyLastTime_) > keyDelayTime_ || keyLastTime_ == 0 )
|
else if ( (currentTime_ - keyLastTime_) > keyDelayTime_ || keyLastTime_ == 0 )
|
||||||
|
|||||||
@ -97,6 +97,7 @@ private:
|
|||||||
|
|
||||||
void render( );
|
void render( );
|
||||||
bool back( bool &exit );
|
bool back( bool &exit );
|
||||||
|
void forceRender( bool render );
|
||||||
void quit( );
|
void quit( );
|
||||||
Page *loadPage( );
|
Page *loadPage( );
|
||||||
Page *loadSplashPage( );
|
Page *loadSplashPage( );
|
||||||
@ -121,6 +122,7 @@ private:
|
|||||||
FontCache fontcache_;
|
FontCache fontcache_;
|
||||||
AttractMode attract_;
|
AttractMode attract_;
|
||||||
bool menuMode_;
|
bool menuMode_;
|
||||||
|
bool mustRender_;
|
||||||
|
|
||||||
std::map<std::string, unsigned int> lastMenuOffsets_;
|
std::map<std::string, unsigned int> lastMenuOffsets_;
|
||||||
std::map<std::string, std::string> lastMenuPlaylists_;
|
std::map<std::string, std::string> lastMenuPlaylists_;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user