Commit a modified version of szigor cli input refactoring patch from #2801291.
The change from the original are mainly moving the input update to an helper and calling it in the frameskip loop like it is done on other frontends.
This commit is contained in:
parent
27e9db8c6b
commit
9ac2a2a48f
|
@ -641,9 +641,49 @@ Draw( void) {
|
|||
return;
|
||||
}
|
||||
|
||||
static void desmume_cycle(int *sdl_quit)
|
||||
{
|
||||
static unsigned short keypad;
|
||||
SDL_Event event;
|
||||
|
||||
/* Look for queued events and update keypad status */
|
||||
/* IMPORTANT: Reenable joystick events iif needed. */
|
||||
if(SDL_JoystickEventState(SDL_QUERY) == SDL_IGNORE)
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
|
||||
/* There's an event waiting to be processed? */
|
||||
while ( !*sdl_quit && SDL_PollEvent(&event))
|
||||
{
|
||||
process_ctrls_event( event, &keypad, nds_screen_size_ratio);
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
#ifdef INCLUDE_OPENGL_2D
|
||||
case SDL_VIDEORESIZE:
|
||||
resizeWindow( event.resize.w, event.resize.h);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_QUIT:
|
||||
*sdl_quit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update mouse position and click */
|
||||
if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y);
|
||||
if(mouse.click)
|
||||
{
|
||||
NDS_releaseTouch();
|
||||
mouse.click = FALSE;
|
||||
}
|
||||
|
||||
update_keypad(keypad); /* Update keypad */
|
||||
NDS_exec<false>();
|
||||
SPU_Emulate_user();
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
static unsigned short keypad = 0;
|
||||
struct my_config my_config;
|
||||
#ifdef GDB_STUB
|
||||
gdbstub_handle_t arm9_gdb_stub;
|
||||
|
@ -863,23 +903,7 @@ int main(int argc, char ** argv) {
|
|||
}
|
||||
|
||||
while(!sdl_quit) {
|
||||
/* Look for queued events and update keypad status */
|
||||
#ifdef INCLUDE_OPENGL_2D
|
||||
sdl_quit = process_ctrls_events( &keypad, resizeWindow, nds_screen_size_ratio);
|
||||
#else
|
||||
sdl_quit = process_ctrls_events( &keypad, NULL, nds_screen_size_ratio);
|
||||
#endif
|
||||
/* Update mouse position and click */
|
||||
if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y);
|
||||
if(mouse.click)
|
||||
{
|
||||
NDS_releaseTouch();
|
||||
mouse.click = FALSE;
|
||||
}
|
||||
|
||||
update_keypad(keypad); /* Update keypad */
|
||||
NDS_exec<false>();
|
||||
SPU_Emulate_user();
|
||||
desmume_cycle(&sdl_quit);
|
||||
|
||||
#ifdef INCLUDE_OPENGL_2D
|
||||
if ( my_config.opengl_2d) {
|
||||
|
@ -889,11 +913,9 @@ int main(int argc, char ** argv) {
|
|||
#endif
|
||||
Draw();
|
||||
|
||||
/* FIXME: this may introduce some lag for input */
|
||||
for ( int i = 0; i < my_config.frameskip; i++ ) {
|
||||
NDS_SkipNextFrame();
|
||||
NDS_exec<false>();
|
||||
SPU_Emulate_user();
|
||||
desmume_cycle(&sdl_quit);
|
||||
}
|
||||
|
||||
if ( !my_config.disable_limiter) {
|
||||
|
|
|
@ -394,120 +394,95 @@ process_joystick_events( u16 *keypad) {
|
|||
|
||||
u16 shift_pressed;
|
||||
|
||||
/* Manage input events */
|
||||
int
|
||||
process_ctrls_events( u16 *keypad,
|
||||
void (*external_videoResizeFn)( u16 width, u16 height),
|
||||
void
|
||||
process_ctrls_event( SDL_Event& event, u16 *keypad,
|
||||
float nds_screen_size_ratio)
|
||||
{
|
||||
u16 key;
|
||||
int cause_quit = 0;
|
||||
SDL_Event event;
|
||||
|
||||
/* IMPORTANT: Reenable joystick events iif needed. */
|
||||
if(SDL_JoystickEventState(SDL_QUERY) == SDL_IGNORE)
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
|
||||
/* There's an event waiting to be processed? */
|
||||
while (SDL_PollEvent(&event))
|
||||
if ( !do_process_joystick_events( keypad, &event)) {
|
||||
switch (event.type)
|
||||
{
|
||||
if ( !do_process_joystick_events( keypad, &event)) {
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_VIDEORESIZE:
|
||||
if ( external_videoResizeFn != NULL) {
|
||||
external_videoResizeFn( event.resize.w, event.resize.h);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym){
|
||||
case SDLK_LSHIFT:
|
||||
shift_pressed |= 1;
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
shift_pressed |= 2;
|
||||
break;
|
||||
default:
|
||||
key = lookup_key(event.key.keysym.sym);
|
||||
ADD_KEY( *keypad, key );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym){
|
||||
case SDLK_LSHIFT:
|
||||
shift_pressed &= ~1;
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
shift_pressed &= ~2;
|
||||
break;
|
||||
|
||||
case SDLK_F1:
|
||||
case SDLK_F2:
|
||||
case SDLK_F3:
|
||||
case SDLK_F4:
|
||||
case SDLK_F5:
|
||||
case SDLK_F6:
|
||||
case SDLK_F7:
|
||||
case SDLK_F8:
|
||||
case SDLK_F9:
|
||||
case SDLK_F10:
|
||||
int prevexec;
|
||||
prevexec = execute;
|
||||
execute = FALSE;
|
||||
SPU_Pause(1);
|
||||
if(!shift_pressed){
|
||||
loadstate_slot(event.key.keysym.sym - SDLK_F1 + 1);
|
||||
}else{
|
||||
savestate_slot(event.key.keysym.sym - SDLK_F1 + 1);
|
||||
}
|
||||
execute = prevexec;
|
||||
SPU_Pause(!execute);
|
||||
break;
|
||||
default:
|
||||
key = lookup_key(event.key.keysym.sym);
|
||||
RM_KEY( *keypad, key );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event.button.button==1)
|
||||
mouse.down = TRUE;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if(!mouse.down)
|
||||
break;
|
||||
else {
|
||||
signed long scaled_x =
|
||||
screen_to_touch_range_x( event.button.x,
|
||||
nds_screen_size_ratio);
|
||||
signed long scaled_y =
|
||||
screen_to_touch_range_y( event.button.y,
|
||||
nds_screen_size_ratio);
|
||||
|
||||
if( scaled_y >= 192)
|
||||
set_mouse_coord( scaled_x, scaled_y - 192);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(mouse.down) mouse.click = TRUE;
|
||||
mouse.down = FALSE;
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
cause_quit = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
switch(event.key.keysym.sym){
|
||||
case SDLK_LSHIFT:
|
||||
shift_pressed |= 1;
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
shift_pressed |= 2;
|
||||
break;
|
||||
default:
|
||||
key = lookup_key(event.key.keysym.sym);
|
||||
ADD_KEY( *keypad, key );
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
return cause_quit;
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym){
|
||||
case SDLK_LSHIFT:
|
||||
shift_pressed &= ~1;
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
shift_pressed &= ~2;
|
||||
break;
|
||||
|
||||
case SDLK_F1:
|
||||
case SDLK_F2:
|
||||
case SDLK_F3:
|
||||
case SDLK_F4:
|
||||
case SDLK_F5:
|
||||
case SDLK_F6:
|
||||
case SDLK_F7:
|
||||
case SDLK_F8:
|
||||
case SDLK_F9:
|
||||
case SDLK_F10:
|
||||
int prevexec;
|
||||
prevexec = execute;
|
||||
execute = FALSE;
|
||||
SPU_Pause(1);
|
||||
if(!shift_pressed){
|
||||
loadstate_slot(event.key.keysym.sym - SDLK_F1 + 1);
|
||||
}else{
|
||||
savestate_slot(event.key.keysym.sym - SDLK_F1 + 1);
|
||||
}
|
||||
execute = prevexec;
|
||||
SPU_Pause(!execute);
|
||||
break;
|
||||
default:
|
||||
key = lookup_key(event.key.keysym.sym);
|
||||
RM_KEY( *keypad, key );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event.button.button==1)
|
||||
mouse.down = TRUE;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if(!mouse.down)
|
||||
break;
|
||||
else {
|
||||
signed long scaled_x =
|
||||
screen_to_touch_range_x( event.button.x,
|
||||
nds_screen_size_ratio);
|
||||
signed long scaled_y =
|
||||
screen_to_touch_range_y( event.button.y,
|
||||
nds_screen_size_ratio);
|
||||
|
||||
if( scaled_y >= 192)
|
||||
set_mouse_coord( scaled_x, scaled_y - 192);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if(mouse.down) mouse.click = TRUE;
|
||||
mouse.down = FALSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,9 +88,8 @@ void update_keypad(u16 keys);
|
|||
u16 get_keypad( void);
|
||||
u16 lookup_key (u16 keyval);
|
||||
u16 lookup_joy_key (u16 keyval);
|
||||
int
|
||||
process_ctrls_events( u16 *keypad,
|
||||
void (*external_videoResizeFn)( u16 width, u16 height),
|
||||
void
|
||||
process_ctrls_event( SDL_Event& event, u16 *keypad,
|
||||
float nds_screen_size_ratio);
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue