NetPlayClient: Extract control mapping checking to its own function
This commit is contained in:
parent
8588c8fd31
commit
e6ad76fa70
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
@ -1017,27 +1018,22 @@ void NetPlayClient::Stop()
|
||||||
if (!m_is_running.load())
|
if (!m_is_running.load())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool isPadMapped = false;
|
|
||||||
for (PadMapping mapping : m_pad_map)
|
|
||||||
{
|
|
||||||
if (mapping == m_local_player->pid)
|
|
||||||
{
|
|
||||||
isPadMapped = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (PadMapping mapping : m_wiimote_map)
|
|
||||||
{
|
|
||||||
if (mapping == m_local_player->pid)
|
|
||||||
{
|
|
||||||
isPadMapped = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell the server to stop if we have a pad mapped in game.
|
// Tell the server to stop if we have a pad mapped in game.
|
||||||
if (isPadMapped)
|
if (LocalPlayerHasControllerMapped())
|
||||||
SendStopGamePacket();
|
SendStopGamePacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// called from ---GUI--- thread
|
||||||
|
bool NetPlayClient::LocalPlayerHasControllerMapped() const
|
||||||
|
{
|
||||||
|
const auto mapping_matches_player_id = [this](const PadMapping& mapping) {
|
||||||
|
return mapping == m_local_player->pid;
|
||||||
|
};
|
||||||
|
|
||||||
|
return std::any_of(m_pad_map.begin(), m_pad_map.end(), mapping_matches_player_id) ||
|
||||||
|
std::any_of(m_wiimote_map.begin(), m_wiimote_map.end(), mapping_matches_player_id);
|
||||||
|
}
|
||||||
|
|
||||||
u8 NetPlayClient::InGamePadToLocalPad(u8 ingame_pad)
|
u8 NetPlayClient::InGamePadToLocalPad(u8 ingame_pad)
|
||||||
{
|
{
|
||||||
// not our pad
|
// not our pad
|
||||||
|
|
|
@ -129,6 +129,8 @@ private:
|
||||||
Failure
|
Failure
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool LocalPlayerHasControllerMapped() const;
|
||||||
|
|
||||||
void SendStartGamePacket();
|
void SendStartGamePacket();
|
||||||
void SendStopGamePacket();
|
void SendStopGamePacket();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue