Sync info about pressed wiimote button

This commit is contained in:
mimimi085181 2017-07-15 00:33:23 +02:00
parent 8b1e61b00a
commit acde0b8b6c
3 changed files with 33 additions and 5 deletions

View File

@ -16,13 +16,14 @@
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h"
#include "Core/Movie.h"
#include "Core/NetPlayClient.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h"
// Limit the amount of wiimote connect requests, when a button is pressed in disconnected state
std::array<u8, 4> last_connect_request_counter;
static std::array<u8, 4> s_last_connect_request_counter;
namespace Wiimote
{
@ -118,7 +119,7 @@ void ResetAllWiimotes()
void LoadConfig()
{
s_config.LoadConfig(false);
last_connect_request_counter.fill(0);
s_last_connect_request_counter.fill(0);
}
void Resume()
@ -149,9 +150,11 @@ void InterruptChannel(int number, u16 channel_id, const void* data, u32 size)
bool ButtonPressed(int number)
{
if (last_connect_request_counter[number] > 0)
if (s_last_connect_request_counter[number] > 0)
{
--last_connect_request_counter[number];
--s_last_connect_request_counter[number];
if (g_wiimote_sources[number] && NetPlay::IsNetPlayRunning())
Wiimote::NetPlay_GetButtonPress(number, false);
return false;
}
@ -164,6 +167,9 @@ bool ButtonPressed(int number)
if (WIIMOTE_SRC_REAL & g_wiimote_sources[number])
button_pressed = WiimoteReal::CheckForButtonPress(number);
if (g_wiimote_sources[number] && NetPlay::IsNetPlayRunning())
button_pressed = Wiimote::NetPlay_GetButtonPress(number, button_pressed);
return button_pressed;
}
@ -184,7 +190,7 @@ void Update(int number, bool connected)
Connect(number, true);
// arbitrary value so it doesn't try to send multiple requests before Dolphin can react
// if Wii Remotes are polled at 200Hz then this results in one request being sent per 500ms
last_connect_request_counter[number] = 100;
s_last_connect_request_counter[number] = 100;
}
}
}

View File

@ -78,6 +78,7 @@ void ControlChannel(int number, u16 channel_id, const void* data, u32 size);
void InterruptChannel(int number, u16 channel_id, const void* data, u32 size);
bool ButtonPressed(int number);
void Update(int number, bool connected);
bool NetPlay_GetButtonPress(int wiimote, bool pressed);
}
namespace WiimoteReal

View File

@ -1280,6 +1280,27 @@ bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size,
return false;
}
// Sync the info whether a button was pressed or not. Used for the reconnect on button press feature
bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
// Use the reporting mode 0 for the button pressed event, the real ones start at RT_REPORT_CORE
u8 data[2] = {static_cast<u8>(pressed), 0};
if (netplay_client)
{
if (netplay_client->WiimoteUpdate(wiimote, data, 2, 0))
{
return data[0];
}
PanicAlertT("Netplay has desynced in NetPlay_GetButtonPress()");
return false;
}
return pressed;
}
// called from ---CPU--- thread
// so all players' games get the same time
//