From 0fffdaca01e3b296cd316f9813720ce51393a057 Mon Sep 17 00:00:00 2001 From: riccardom Date: Wed, 7 Apr 2010 12:51:47 +0000 Subject: [PATCH] Move cli frontend event processing to process_ctrls_event Unify the switch Instead of evaluating sdl events both in ctrlsdl and cli frontend. With this change now ctrlsdl gets in touch with both GPU_osd and fake mic code. --- desmume/src/cli/main.cpp | 103 ++++++++++----------------------------- desmume/src/ctrlssdl.cpp | 62 ++++++++++++++++++++--- desmume/src/ctrlssdl.h | 15 +++++- 3 files changed, 95 insertions(+), 85 deletions(-) diff --git a/desmume/src/cli/main.cpp b/desmume/src/cli/main.cpp index 959cb5d31..0a6abf5c9 100644 --- a/desmume/src/cli/main.cpp +++ b/desmume/src/cli/main.cpp @@ -52,7 +52,6 @@ #include "render3D.h" #include "rasterize.h" #include "saves.h" -#include "mic.h" #include "firmware.h" #include "GPU_osd.h" #include "desmume_config.h" @@ -125,10 +124,6 @@ const u16 cli_kb_cfg[NB_KEYS] = SDLK_o // BOOST }; -#ifdef FAKE_MIC -static BOOL enable_fake_mic; -#endif - class configured_features : public CommandLine { public: @@ -459,6 +454,11 @@ opengl_Draw( GLuint *texture, int software_convert) { } #endif +/* this is a stub for resizeWindow_stub in the case of no gl headers or no opengl 2d */ +static void +resizeWindow_stub (u16 width, u16 height) { +} + static void Draw( void) { SDL_Surface *rawImage; @@ -474,80 +474,23 @@ Draw( void) { return; } -static void desmume_cycle(int *sdl_quit, int *boost, struct configured_features * my_config) +static void desmume_cycle(struct ctrls_event_config * cfg) { - static unsigned short keypad; - static int focused = 1; SDL_Event event; + cfg->nds_screen_size_ratio = nds_screen_size_ratio; + /* 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) || (!focused && SDL_WaitEvent(&event)))) + while ( !cfg->sdl_quit && + (SDL_PollEvent(&event) || (!cfg->focused && SDL_WaitEvent(&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_ACTIVEEVENT: - if (my_config->auto_pause && (event.active.state & SDL_APPINPUTFOCUS )) - { - if (event.active.gain) - { - focused = 1; - SPU_Pause(0); - osd->addLine("Auto pause disabled\n"); - } - else - { - focused = 0; - SPU_Pause(1); - } - } - break; - - case SDL_KEYUP: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - *sdl_quit = 1; - break; -#ifdef FAKE_MIC - case SDLK_m: - enable_fake_mic = !enable_fake_mic; - Mic_DoNoise(enable_fake_mic); - if (enable_fake_mic) - osd->addLine("Fake mic enabled\n"); - else - osd->addLine("Fake mic disabled\n"); - break; -#endif - case SDLK_o: - *boost = !(*boost); - if (*boost) - osd->addLine("Boost mode enabled\n"); - else - osd->addLine("Boost mode disabled\n"); - break; - default: - break; - } - break; - - case SDL_QUIT: - *sdl_quit = 1; - break; - } - } + process_ctrls_event( event, cfg); + } /* Update mouse position and click */ if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y); @@ -557,13 +500,14 @@ static void desmume_cycle(int *sdl_quit, int *boost, struct configured_features mouse.click = FALSE; } - update_keypad(keypad); /* Update keypad */ + update_keypad(cfg->keypad); /* Update keypad */ NDS_exec(); SPU_Emulate_user(); } int main(int argc, char ** argv) { struct configured_features my_config; + struct ctrls_event_config ctrls_cfg; #ifdef GDB_STUB gdbstub_handle_t arm9_gdb_stub; gdbstub_handle_t arm7_gdb_stub; @@ -576,8 +520,6 @@ int main(int argc, char ** argv) { int limiter_frame_counter = 0; SDL_sem *fps_limiter_semaphore = NULL; SDL_TimerID limiter_timer = NULL; - int sdl_quit = 0; - int boost = 0; int error; GKeyFile *keyfile; @@ -815,14 +757,23 @@ int main(int argc, char ** argv) { aggDraw.hud->attach(GPU_screen, 256, 384, 512); #endif - while(!sdl_quit) { - desmume_cycle(&sdl_quit, &boost, &my_config); + ctrls_cfg.boost = 0; + ctrls_cfg.sdl_quit = 0; + ctrls_cfg.auto_pause = my_config.auto_pause; + ctrls_cfg.focused = 1; + ctrls_cfg.fake_mic = 0; + ctrls_cfg.keypad = 0; + ctrls_cfg.resize_cb = &resizeWindow_stub; + + while(!ctrls_cfg.sdl_quit) { + desmume_cycle(&ctrls_cfg); osd->update(); DrawHUD(); #ifdef INCLUDE_OPENGL_2D if ( my_config.opengl_2d) { opengl_Draw( screen_texture, my_config.soft_colour_convert); + ctrls_cfg.resize_cb = &resizeWindow; } else #endif @@ -831,10 +782,10 @@ int main(int argc, char ** argv) { for ( int i = 0; i < my_config.frameskip; i++ ) { NDS_SkipNextFrame(); - desmume_cycle(&sdl_quit, &boost, &my_config); + desmume_cycle(&ctrls_cfg); } - if ( !my_config.disable_limiter && !boost) { + if ( !my_config.disable_limiter && !ctrls_cfg.boost) { limiter_frame_counter += 1 + my_config.frameskip; if ( limiter_frame_counter >= my_config.fps_limiter_frame_period) { limiter_frame_counter = 0; diff --git a/desmume/src/ctrlssdl.cpp b/desmume/src/ctrlssdl.cpp index 80aeb23dc..74bb64afc 100644 --- a/desmume/src/ctrlssdl.cpp +++ b/desmume/src/ctrlssdl.cpp @@ -25,6 +25,10 @@ #include "SPU.h" #include "commandline.h" #include "NDSSystem.h" +#include "GPU_osd.h" +#ifdef FAKE_MIC +#include "mic.h" +#endif u16 keyboard_cfg[NB_KEYS]; u16 joypad_cfg[NB_KEYS]; @@ -421,13 +425,30 @@ process_joystick_events( u16 *keypad) { u16 shift_pressed; void -process_ctrls_event( SDL_Event& event, u16 *keypad, - float nds_screen_size_ratio) +process_ctrls_event( SDL_Event& event, + struct ctrls_event_config *cfg) { u16 key; - if ( !do_process_joystick_events( keypad, &event)) { + if ( !do_process_joystick_events( &cfg->keypad, &event)) { switch (event.type) { + case SDL_VIDEORESIZE: + cfg->resize_cb( event.resize.w, event.resize.h); + break; + + case SDL_ACTIVEEVENT: + if (cfg->auto_pause && (event.active.state & SDL_APPINPUTFOCUS )) { + if (event.active.gain) { + cfg->focused = 1; + SPU_Pause(0); + osd->addLine("Auto pause disabled\n"); + } else { + cfg->focused = 0; + SPU_Pause(1); + } + } + break; + case SDL_KEYDOWN: switch(event.key.keysym.sym){ case SDLK_LSHIFT: @@ -438,13 +459,36 @@ process_ctrls_event( SDL_Event& event, u16 *keypad, break; default: key = lookup_key(event.key.keysym.sym); - ADD_KEY( *keypad, key ); + ADD_KEY( cfg->keypad, key ); break; } break; case SDL_KEYUP: switch(event.key.keysym.sym){ + case SDLK_ESCAPE: + cfg->sdl_quit = 1; + break; + +#ifdef FAKE_MIC + case SDLK_m: + cfg->fake_mic = !cfg->fake_mic; + Mic_DoNoise(cfg->fake_mic); + if (cfg->fake_mic) + osd->addLine("Fake mic enabled\n"); + else + osd->addLine("Fake mic disabled\n"); + break; +#endif + + case SDLK_o: + cfg->boost = !cfg->boost; + if (cfg->boost) + osd->addLine("Boost mode enabled\n"); + else + osd->addLine("Boost mode disabled\n"); + break; + case SDLK_LSHIFT: shift_pressed &= ~1; break; @@ -476,7 +520,7 @@ process_ctrls_event( SDL_Event& event, u16 *keypad, break; default: key = lookup_key(event.key.keysym.sym); - RM_KEY( *keypad, key ); + RM_KEY( cfg->keypad, key ); break; } break; @@ -491,10 +535,10 @@ process_ctrls_event( SDL_Event& event, u16 *keypad, else { signed long scaled_x = screen_to_touch_range_x( event.button.x, - nds_screen_size_ratio); + cfg->nds_screen_size_ratio); signed long scaled_y = screen_to_touch_range_y( event.button.y, - nds_screen_size_ratio); + cfg->nds_screen_size_ratio); if( scaled_y >= 192) set_mouse_coord( scaled_x, scaled_y - 192); @@ -506,6 +550,10 @@ process_ctrls_event( SDL_Event& event, u16 *keypad, mouse.down = FALSE; break; + case SDL_QUIT: + cfg->sdl_quit = 1; + break; + default: break; } diff --git a/desmume/src/ctrlssdl.h b/desmume/src/ctrlssdl.h index 516d64186..6b368cbed 100644 --- a/desmume/src/ctrlssdl.h +++ b/desmume/src/ctrlssdl.h @@ -77,6 +77,17 @@ extern mouse_status mouse; void set_mouse_coord(signed long x,signed long y); #endif // !GTK_UI +struct ctrls_event_config { + unsigned short keypad; + float nds_screen_size_ratio; + int auto_pause; + int focused; + int sdl_quit; + int boost; + int fake_mic; + void (*resize_cb)(u16 width, u16 height); +}; + void load_default_config(const u16 kbCfg[]); BOOL init_joy( void); void uninit_joy( void); @@ -91,8 +102,8 @@ u16 get_keypad( void); u16 lookup_key (u16 keyval); u16 lookup_joy_key (u16 keyval); void -process_ctrls_event( SDL_Event& event, u16 *keypad, - float nds_screen_size_ratio); +process_ctrls_event( SDL_Event& event, + struct ctrls_event_config *cfg); void process_joystick_events( u16 *keypad);