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.
This commit is contained in:
parent
e2dfe00574
commit
0fffdaca01
|
@ -52,7 +52,6 @@
|
||||||
#include "render3D.h"
|
#include "render3D.h"
|
||||||
#include "rasterize.h"
|
#include "rasterize.h"
|
||||||
#include "saves.h"
|
#include "saves.h"
|
||||||
#include "mic.h"
|
|
||||||
#include "firmware.h"
|
#include "firmware.h"
|
||||||
#include "GPU_osd.h"
|
#include "GPU_osd.h"
|
||||||
#include "desmume_config.h"
|
#include "desmume_config.h"
|
||||||
|
@ -125,10 +124,6 @@ const u16 cli_kb_cfg[NB_KEYS] =
|
||||||
SDLK_o // BOOST
|
SDLK_o // BOOST
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef FAKE_MIC
|
|
||||||
static BOOL enable_fake_mic;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class configured_features : public CommandLine
|
class configured_features : public CommandLine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -459,6 +454,11 @@ opengl_Draw( GLuint *texture, int software_convert) {
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
static void
|
||||||
Draw( void) {
|
Draw( void) {
|
||||||
SDL_Surface *rawImage;
|
SDL_Surface *rawImage;
|
||||||
|
@ -474,80 +474,23 @@ Draw( void) {
|
||||||
return;
|
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;
|
SDL_Event event;
|
||||||
|
|
||||||
|
cfg->nds_screen_size_ratio = nds_screen_size_ratio;
|
||||||
|
|
||||||
/* Look for queued events and update keypad status */
|
/* Look for queued events and update keypad status */
|
||||||
/* IMPORTANT: Reenable joystick events iif needed. */
|
/* IMPORTANT: Reenable joystick events iif needed. */
|
||||||
if(SDL_JoystickEventState(SDL_QUERY) == SDL_IGNORE)
|
if(SDL_JoystickEventState(SDL_QUERY) == SDL_IGNORE)
|
||||||
SDL_JoystickEventState(SDL_ENABLE);
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
|
|
||||||
/* There's an event waiting to be processed? */
|
/* There's an event waiting to be processed? */
|
||||||
while ( !*sdl_quit &&
|
while ( !cfg->sdl_quit &&
|
||||||
(SDL_PollEvent(&event) || (!focused && SDL_WaitEvent(&event))))
|
(SDL_PollEvent(&event) || (!cfg->focused && SDL_WaitEvent(&event))))
|
||||||
{
|
{
|
||||||
process_ctrls_event( event, &keypad, nds_screen_size_ratio);
|
process_ctrls_event( event, cfg);
|
||||||
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update mouse position and click */
|
/* Update mouse position and click */
|
||||||
if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y);
|
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;
|
mouse.click = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_keypad(keypad); /* Update keypad */
|
update_keypad(cfg->keypad); /* Update keypad */
|
||||||
NDS_exec<false>();
|
NDS_exec<false>();
|
||||||
SPU_Emulate_user();
|
SPU_Emulate_user();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
struct configured_features my_config;
|
struct configured_features my_config;
|
||||||
|
struct ctrls_event_config ctrls_cfg;
|
||||||
#ifdef GDB_STUB
|
#ifdef GDB_STUB
|
||||||
gdbstub_handle_t arm9_gdb_stub;
|
gdbstub_handle_t arm9_gdb_stub;
|
||||||
gdbstub_handle_t arm7_gdb_stub;
|
gdbstub_handle_t arm7_gdb_stub;
|
||||||
|
@ -576,8 +520,6 @@ int main(int argc, char ** argv) {
|
||||||
int limiter_frame_counter = 0;
|
int limiter_frame_counter = 0;
|
||||||
SDL_sem *fps_limiter_semaphore = NULL;
|
SDL_sem *fps_limiter_semaphore = NULL;
|
||||||
SDL_TimerID limiter_timer = NULL;
|
SDL_TimerID limiter_timer = NULL;
|
||||||
int sdl_quit = 0;
|
|
||||||
int boost = 0;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
|
@ -815,14 +757,23 @@ int main(int argc, char ** argv) {
|
||||||
aggDraw.hud->attach(GPU_screen, 256, 384, 512);
|
aggDraw.hud->attach(GPU_screen, 256, 384, 512);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(!sdl_quit) {
|
ctrls_cfg.boost = 0;
|
||||||
desmume_cycle(&sdl_quit, &boost, &my_config);
|
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();
|
osd->update();
|
||||||
DrawHUD();
|
DrawHUD();
|
||||||
#ifdef INCLUDE_OPENGL_2D
|
#ifdef INCLUDE_OPENGL_2D
|
||||||
if ( my_config.opengl_2d) {
|
if ( my_config.opengl_2d) {
|
||||||
opengl_Draw( screen_texture, my_config.soft_colour_convert);
|
opengl_Draw( screen_texture, my_config.soft_colour_convert);
|
||||||
|
ctrls_cfg.resize_cb = &resizeWindow;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -831,10 +782,10 @@ int main(int argc, char ** argv) {
|
||||||
|
|
||||||
for ( int i = 0; i < my_config.frameskip; i++ ) {
|
for ( int i = 0; i < my_config.frameskip; i++ ) {
|
||||||
NDS_SkipNextFrame();
|
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;
|
limiter_frame_counter += 1 + my_config.frameskip;
|
||||||
if ( limiter_frame_counter >= my_config.fps_limiter_frame_period) {
|
if ( limiter_frame_counter >= my_config.fps_limiter_frame_period) {
|
||||||
limiter_frame_counter = 0;
|
limiter_frame_counter = 0;
|
||||||
|
|
|
@ -25,6 +25,10 @@
|
||||||
#include "SPU.h"
|
#include "SPU.h"
|
||||||
#include "commandline.h"
|
#include "commandline.h"
|
||||||
#include "NDSSystem.h"
|
#include "NDSSystem.h"
|
||||||
|
#include "GPU_osd.h"
|
||||||
|
#ifdef FAKE_MIC
|
||||||
|
#include "mic.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
u16 keyboard_cfg[NB_KEYS];
|
u16 keyboard_cfg[NB_KEYS];
|
||||||
u16 joypad_cfg[NB_KEYS];
|
u16 joypad_cfg[NB_KEYS];
|
||||||
|
@ -421,13 +425,30 @@ process_joystick_events( u16 *keypad) {
|
||||||
u16 shift_pressed;
|
u16 shift_pressed;
|
||||||
|
|
||||||
void
|
void
|
||||||
process_ctrls_event( SDL_Event& event, u16 *keypad,
|
process_ctrls_event( SDL_Event& event,
|
||||||
float nds_screen_size_ratio)
|
struct ctrls_event_config *cfg)
|
||||||
{
|
{
|
||||||
u16 key;
|
u16 key;
|
||||||
if ( !do_process_joystick_events( keypad, &event)) {
|
if ( !do_process_joystick_events( &cfg->keypad, &event)) {
|
||||||
switch (event.type)
|
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:
|
case SDL_KEYDOWN:
|
||||||
switch(event.key.keysym.sym){
|
switch(event.key.keysym.sym){
|
||||||
case SDLK_LSHIFT:
|
case SDLK_LSHIFT:
|
||||||
|
@ -438,13 +459,36 @@ process_ctrls_event( SDL_Event& event, u16 *keypad,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
key = lookup_key(event.key.keysym.sym);
|
key = lookup_key(event.key.keysym.sym);
|
||||||
ADD_KEY( *keypad, key );
|
ADD_KEY( cfg->keypad, key );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
switch(event.key.keysym.sym){
|
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:
|
case SDLK_LSHIFT:
|
||||||
shift_pressed &= ~1;
|
shift_pressed &= ~1;
|
||||||
break;
|
break;
|
||||||
|
@ -476,7 +520,7 @@ process_ctrls_event( SDL_Event& event, u16 *keypad,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
key = lookup_key(event.key.keysym.sym);
|
key = lookup_key(event.key.keysym.sym);
|
||||||
RM_KEY( *keypad, key );
|
RM_KEY( cfg->keypad, key );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -491,10 +535,10 @@ process_ctrls_event( SDL_Event& event, u16 *keypad,
|
||||||
else {
|
else {
|
||||||
signed long scaled_x =
|
signed long scaled_x =
|
||||||
screen_to_touch_range_x( event.button.x,
|
screen_to_touch_range_x( event.button.x,
|
||||||
nds_screen_size_ratio);
|
cfg->nds_screen_size_ratio);
|
||||||
signed long scaled_y =
|
signed long scaled_y =
|
||||||
screen_to_touch_range_y( event.button.y,
|
screen_to_touch_range_y( event.button.y,
|
||||||
nds_screen_size_ratio);
|
cfg->nds_screen_size_ratio);
|
||||||
|
|
||||||
if( scaled_y >= 192)
|
if( scaled_y >= 192)
|
||||||
set_mouse_coord( scaled_x, 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;
|
mouse.down = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_QUIT:
|
||||||
|
cfg->sdl_quit = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,17 @@ extern mouse_status mouse;
|
||||||
void set_mouse_coord(signed long x,signed long y);
|
void set_mouse_coord(signed long x,signed long y);
|
||||||
#endif // !GTK_UI
|
#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[]);
|
void load_default_config(const u16 kbCfg[]);
|
||||||
BOOL init_joy( void);
|
BOOL init_joy( void);
|
||||||
void uninit_joy( void);
|
void uninit_joy( void);
|
||||||
|
@ -91,8 +102,8 @@ u16 get_keypad( void);
|
||||||
u16 lookup_key (u16 keyval);
|
u16 lookup_key (u16 keyval);
|
||||||
u16 lookup_joy_key (u16 keyval);
|
u16 lookup_joy_key (u16 keyval);
|
||||||
void
|
void
|
||||||
process_ctrls_event( SDL_Event& event, u16 *keypad,
|
process_ctrls_event( SDL_Event& event,
|
||||||
float nds_screen_size_ratio);
|
struct ctrls_event_config *cfg);
|
||||||
|
|
||||||
void
|
void
|
||||||
process_joystick_events( u16 *keypad);
|
process_joystick_events( u16 *keypad);
|
||||||
|
|
Loading…
Reference in New Issue