Fix wiimotes regression

== DETAILS
- only call disconnect when we're actually disconnecting a remote
  (e.g. read errors or remote goes to sleep).
- clean up some compile warnings introduced by others (mainly
  unused variables)
This commit is contained in:
Nathan Strong 2021-10-16 23:56:15 -07:00
parent 2f4cfe2a02
commit 5b4b766459
2 changed files with 22 additions and 15 deletions

View File

@ -149,8 +149,15 @@ static void kpad_register(unsigned channel, uint8_t device_type)
{ {
int slot; int slot;
kpad_deregister(channel); if(device_type == WIIMOTE_TYPE_NONE) {
slot = get_slot_for_channel(channel); kpad_deregister(channel);
return;
}
slot = joypad_state.kpad.channel_slot_map[channel];
if(slot < 0) {
slot = get_slot_for_channel(channel);
}
if (slot < 0) if (slot < 0)
{ {
@ -158,8 +165,10 @@ static void kpad_register(unsigned channel, uint8_t device_type)
return; return;
} }
joypad_state.kpad.wiimotes[channel].type = device_type; joypad_state.kpad.wiimotes[channel].type = device_type;
joypad_state.pads[slot].input_driver = &kpad_driver; joypad_state.kpad.channel_slot_map[channel] = slot;
joypad_state.pads[slot].input_driver = &kpad_driver;
joypad_state.pads[slot].connected = true;
input_pad_connect(slot, &kpad_driver); input_pad_connect(slot, &kpad_driver);
} }
} }
@ -232,8 +241,9 @@ static void kpad_poll(void)
if (result == 0) if (result == 0)
{ {
joypad_state.kpad.poll_failures[channel]++; joypad_state.kpad.poll_failures[channel]++;
if (joypad_state.kpad.poll_failures[channel] > 5) if (joypad_state.kpad.poll_failures[channel] > 5) {
kpad_deregister(channel); kpad_deregister(channel);
}
continue; continue;
} }
joypad_state.kpad.poll_failures[channel] = 0; joypad_state.kpad.poll_failures[channel] = 0;

View File

@ -262,8 +262,8 @@
#define RUNLOOP_MSG_QUEUE_LOCK(runloop_st) slock_lock((runloop_st)->msg_queue_lock) #define RUNLOOP_MSG_QUEUE_LOCK(runloop_st) slock_lock((runloop_st)->msg_queue_lock)
#define RUNLOOP_MSG_QUEUE_UNLOCK(runloop_st) slock_unlock((runloop_st)->msg_queue_lock) #define RUNLOOP_MSG_QUEUE_UNLOCK(runloop_st) slock_unlock((runloop_st)->msg_queue_lock)
#else #else
#define RUNLOOP_MSG_QUEUE_LOCK(runloop_st) #define RUNLOOP_MSG_QUEUE_LOCK(runloop_st) (void)(runloop_st)
#define RUNLOOP_MSG_QUEUE_UNLOCK(runloop_st) #define RUNLOOP_MSG_QUEUE_UNLOCK(runloop_st) (void)(runloop_st)
#endif #endif
/* Custom forward declarations */ /* Custom forward declarations */
@ -5793,14 +5793,13 @@ static bool command_event_disk_control_append_image(
rarch_system_info_t *sys_info, rarch_system_info_t *sys_info,
const char *path) const char *path)
{ {
runloop_state_t *runloop_st = &runloop_state;
input_driver_state_t *input_st = input_state_get_ptr(); input_driver_state_t *input_st = input_state_get_ptr();
if ( !sys_info || if ( !sys_info ||
!disk_control_append_image(&sys_info->disk_control, path)) !disk_control_append_image(&sys_info->disk_control, path))
return false; return false;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
if (runloop_st->use_sram) if (runloop_state.use_sram)
autosave_deinit(); autosave_deinit();
#endif #endif
@ -16924,8 +16923,6 @@ static void do_runahead(
#else #else
const bool have_dynamic = false; const bool have_dynamic = false;
#endif #endif
runloop_state_t
*runloop_st = &runloop_state;
video_driver_state_t video_driver_state_t
*video_st = video_state_get_ptr(); *video_st = video_state_get_ptr();
uint64_t frame_count = video_st->frame_count; uint64_t frame_count = video_st->frame_count;
@ -17018,7 +17015,7 @@ static void do_runahead(
if ( runloop_st->input_is_dirty if ( runloop_st->input_is_dirty
|| p_rarch->runahead_force_input_dirty) || p_rarch->runahead_force_input_dirty)
{ {
runloop_st->input_is_dirty = false; runloop_state.input_is_dirty = false;
if (!runahead_save_state(p_rarch)) if (!runahead_save_state(p_rarch))
{ {
@ -19053,12 +19050,12 @@ static void retroarch_fail(struct rarch_state *p_rarch,
bool retroarch_main_quit(void) bool retroarch_main_quit(void)
{ {
struct rarch_state *p_rarch = &rarch_st;
runloop_state_t *runloop_st = &runloop_state; runloop_state_t *runloop_st = &runloop_state;
video_driver_state_t*video_st = video_state_get_ptr(); video_driver_state_t*video_st = video_state_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
#ifdef HAVE_DISCORD #ifdef HAVE_DISCORD
struct rarch_state *p_rarch = &rarch_st;
discord_state_t *discord_st = &p_rarch->discord_st; discord_state_t *discord_st = &p_rarch->discord_st;
if (discord_is_inited) if (discord_is_inited)
{ {
@ -21229,9 +21226,9 @@ bool core_unset_netplay_callbacks(void)
bool core_set_cheat(retro_ctx_cheat_info_t *info) bool core_set_cheat(retro_ctx_cheat_info_t *info)
{ {
struct rarch_state *p_rarch = &rarch_st;
runloop_state_t *runloop_st = &runloop_state; runloop_state_t *runloop_st = &runloop_state;
#if defined(HAVE_RUNAHEAD) && (defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)) #if defined(HAVE_RUNAHEAD) && (defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB))
struct rarch_state *p_rarch = &rarch_st;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool run_ahead_enabled = false; bool run_ahead_enabled = false;
unsigned run_ahead_frames = 0; unsigned run_ahead_frames = 0;
@ -21267,9 +21264,9 @@ bool core_set_cheat(retro_ctx_cheat_info_t *info)
bool core_reset_cheat(void) bool core_reset_cheat(void)
{ {
struct rarch_state *p_rarch = &rarch_st;
runloop_state_t *runloop_st = &runloop_state; runloop_state_t *runloop_st = &runloop_state;
#if defined(HAVE_RUNAHEAD) && (defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)) #if defined(HAVE_RUNAHEAD) && (defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB))
struct rarch_state *p_rarch = &rarch_st;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool run_ahead_enabled = false; bool run_ahead_enabled = false;
unsigned run_ahead_frames = 0; unsigned run_ahead_frames = 0;