Netplay: Implement batching for Wiimotes.
This commit is contained in:
parent
aade584180
commit
a1563f2def
|
@ -354,14 +354,28 @@ void BluetoothEmuDevice::Update()
|
|||
|
||||
if (NetPlay::IsNetPlayRunning())
|
||||
{
|
||||
std::array<WiimoteEmu::SerializedWiimoteState, MAX_BBMOTES> serialized;
|
||||
std::array<NetPlay::NetPlayClient::WiimoteDataBatchEntry, MAX_BBMOTES> batch;
|
||||
size_t batch_count = 0;
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if (next_call[i] != WiimoteDevice::NextUpdateInputCall::None)
|
||||
if (next_call[i] == WiimoteDevice::NextUpdateInputCall::None)
|
||||
continue;
|
||||
serialized[i] = WiimoteEmu::SerializeDesiredState(wiimote_states[i]);
|
||||
batch[batch_count].state = &serialized[i];
|
||||
batch[batch_count].wiimote = static_cast<int>(i);
|
||||
++batch_count;
|
||||
}
|
||||
|
||||
if (batch_count > 0)
|
||||
{
|
||||
WiimoteEmu::SerializedWiimoteState serialized_state =
|
||||
WiimoteEmu::SerializeDesiredState(wiimote_states[i]);
|
||||
NetPlay::NetPlay_GetWiimoteData(static_cast<int>(i), &serialized_state);
|
||||
if (!WiimoteEmu::DeserializeDesiredState(&wiimote_states[i], serialized_state))
|
||||
NetPlay::NetPlay_GetWiimoteData(
|
||||
std::span<NetPlay::NetPlayClient::WiimoteDataBatchEntry>(batch.data(), batch_count));
|
||||
|
||||
for (size_t i = 0; i < batch_count; ++i)
|
||||
{
|
||||
const int wiimote = batch[i].wiimote;
|
||||
if (!WiimoteEmu::DeserializeDesiredState(&wiimote_states[wiimote], serialized[wiimote]))
|
||||
PanicAlertFmtT("Received invalid Wii Remote data from Netplay.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2051,28 +2051,26 @@ u64 NetPlayClient::GetInitialRTCValue() const
|
|||
}
|
||||
|
||||
// called from ---CPU--- thread
|
||||
bool NetPlayClient::WiimoteUpdate(int wiimote_number,
|
||||
WiimoteEmu::SerializedWiimoteState* target_state)
|
||||
bool NetPlayClient::WiimoteUpdate(const std::span<WiimoteDataBatchEntry>& entries)
|
||||
{
|
||||
for (const WiimoteDataBatchEntry& entry : entries)
|
||||
{
|
||||
const int local_wiimote = InGameWiimoteToLocalWiimote(wiimote_number);
|
||||
DEBUG_LOG_FMT(
|
||||
NETPLAY,
|
||||
"Entering WiimoteUpdate() with wiimote_number {}, local_wiimote {}, target_state [{:02x}]",
|
||||
wiimote_number, local_wiimote,
|
||||
fmt::join(std::span(target_state->data.data(), target_state->length), ", "));
|
||||
const int local_wiimote = InGameWiimoteToLocalWiimote(entry.wiimote);
|
||||
DEBUG_LOG_FMT(NETPLAY,
|
||||
"Entering WiimoteUpdate() with wiimote {}, local_wiimote {}, state [{:02x}]",
|
||||
entry.wiimote, local_wiimote,
|
||||
fmt::join(std::span(entry.state->data.data(), entry.state->length), ", "));
|
||||
if (local_wiimote < 4)
|
||||
{
|
||||
sf::Packet packet;
|
||||
packet << MessageID::WiimoteData;
|
||||
if (AddLocalWiimoteToBuffer(local_wiimote, *target_state, packet))
|
||||
if (AddLocalWiimoteToBuffer(local_wiimote, *entry.state, packet))
|
||||
SendAsync(std::move(packet));
|
||||
}
|
||||
}
|
||||
|
||||
// Now, we either use the data pushed earlier, or wait for the
|
||||
// other clients to send it to us
|
||||
while (m_wiimote_buffer[wiimote_number].Size() == 0)
|
||||
while (m_wiimote_buffer[entry.wiimote].Size() == 0)
|
||||
{
|
||||
if (!m_is_running.IsSet())
|
||||
{
|
||||
|
@ -2082,11 +2080,12 @@ bool NetPlayClient::WiimoteUpdate(int wiimote_number,
|
|||
m_wii_pad_event.Wait();
|
||||
}
|
||||
|
||||
m_wiimote_buffer[wiimote_number].Pop(*target_state);
|
||||
m_wiimote_buffer[entry.wiimote].Pop(*entry.state);
|
||||
|
||||
DEBUG_LOG_FMT(NETPLAY, "Exiting WiimoteUpdate() with wiimote {}, state [{:02x}]", entry.wiimote,
|
||||
fmt::join(std::span(entry.state->data.data(), entry.state->length), ", "));
|
||||
}
|
||||
|
||||
DEBUG_LOG_FMT(NETPLAY, "Exiting WiimoteUpdate() with wiimote_number {}, target_state [{:02x}]",
|
||||
wiimote_number,
|
||||
fmt::join(std::span(target_state->data.data(), target_state->length), ", "));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2681,12 +2680,12 @@ bool SerialInterface::CSIDevice_GCController::NetPlay_GetInput(int pad_num, GCPa
|
|||
return false;
|
||||
}
|
||||
|
||||
bool NetPlay::NetPlay_GetWiimoteData(int wiimote, WiimoteEmu::SerializedWiimoteState* target_state)
|
||||
bool NetPlay::NetPlay_GetWiimoteData(const std::span<NetPlayClient::WiimoteDataBatchEntry>& entries)
|
||||
{
|
||||
std::lock_guard lk(crit_netplay_client);
|
||||
|
||||
if (netplay_client)
|
||||
return netplay_client->WiimoteUpdate(wiimote, target_state);
|
||||
return netplay_client->WiimoteUpdate(entries);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
@ -134,7 +135,12 @@ public:
|
|||
std::string GetCurrentGolfer();
|
||||
|
||||
// Send and receive pads values
|
||||
bool WiimoteUpdate(int wiimote_number, WiimoteEmu::SerializedWiimoteState* target_state);
|
||||
struct WiimoteDataBatchEntry
|
||||
{
|
||||
int wiimote;
|
||||
WiimoteEmu::SerializedWiimoteState* state;
|
||||
};
|
||||
bool WiimoteUpdate(const std::span<WiimoteDataBatchEntry>& entries);
|
||||
bool GetNetPads(int pad_nb, bool from_vi, GCPadStatus* pad_status);
|
||||
|
||||
u64 GetInitialRTCValue() const;
|
||||
|
@ -345,6 +351,6 @@ private:
|
|||
|
||||
void NetPlay_Enable(NetPlayClient* const np);
|
||||
void NetPlay_Disable();
|
||||
bool NetPlay_GetWiimoteData(int wiimote, WiimoteEmu::SerializedWiimoteState* target_state);
|
||||
bool NetPlay_GetWiimoteData(const std::span<NetPlayClient::WiimoteDataBatchEntry>& entries);
|
||||
unsigned int NetPlay_GetLocalWiimoteForSlot(unsigned int slot);
|
||||
} // namespace NetPlay
|
||||
|
|
Loading…
Reference in New Issue