Add GCPadStatus.isConnected boolean

This commit is contained in:
Michael Maltese 2017-02-09 15:03:43 -08:00 committed by Léo Lam
parent bb1c794657
commit 379e28b58c
5 changed files with 58 additions and 43 deletions

View File

@ -601,34 +601,41 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
{
std::string display_str = StringFromFormat("P%d:", controllerID + 1);
if (padState.A)
display_str += " A";
if (padState.B)
display_str += " B";
if (padState.X)
display_str += " X";
if (padState.Y)
display_str += " Y";
if (padState.Z)
display_str += " Z";
if (padState.Start)
display_str += " START";
if (padState.is_connected)
{
if (padState.A)
display_str += " A";
if (padState.B)
display_str += " B";
if (padState.X)
display_str += " X";
if (padState.Y)
display_str += " Y";
if (padState.Z)
display_str += " Z";
if (padState.Start)
display_str += " START";
if (padState.DPadUp)
display_str += " UP";
if (padState.DPadDown)
display_str += " DOWN";
if (padState.DPadLeft)
display_str += " LEFT";
if (padState.DPadRight)
display_str += " RIGHT";
if (padState.reset)
display_str += " RESET";
if (padState.DPadUp)
display_str += " UP";
if (padState.DPadDown)
display_str += " DOWN";
if (padState.DPadLeft)
display_str += " LEFT";
if (padState.DPadRight)
display_str += " RIGHT";
if (padState.reset)
display_str += " RESET";
display_str += Analog1DToString(padState.TriggerL, " L");
display_str += Analog1DToString(padState.TriggerR, " R");
display_str += Analog2DToString(padState.AnalogStickX, padState.AnalogStickY, " ANA");
display_str += Analog2DToString(padState.CStickX, padState.CStickY, " C");
display_str += Analog1DToString(padState.TriggerL, " L");
display_str += Analog1DToString(padState.TriggerR, " R");
display_str += Analog2DToString(padState.AnalogStickX, padState.AnalogStickY, " ANA");
display_str += Analog2DToString(padState.CStickX, padState.CStickY, " C");
}
else
{
display_str += " DISCONNECTED";
}
std::lock_guard<std::mutex> guard(s_input_display_lock);
s_InputDisplay[controllerID] = std::move(display_str);
@ -782,6 +789,8 @@ void CheckPadStatus(GCPadStatus* PadStatus, int controllerID)
s_padState.CStickX = PadStatus->substickX;
s_padState.CStickY = PadStatus->substickY;
s_padState.is_connected = PadStatus->isConnected;
s_padState.disc = s_bDiscChange;
s_bDiscChange = false;
s_padState.reset = s_bReset;
@ -1031,24 +1040,25 @@ void LoadInput(const std::string& filename)
"is %d frames long.\n\n"
"On frame %td, the current movie presses:\n"
"Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, "
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d"
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d, Connected=%d"
"\n\n"
"On frame %td, the savestate's movie presses:\n"
"Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, "
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d",
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d, Connected=%d",
frame, (int)s_totalFrames, (int)tmpHeader.frameCount, frame, (int)curPadState.Start,
(int)curPadState.A, (int)curPadState.B, (int)curPadState.X, (int)curPadState.Y,
(int)curPadState.Z, (int)curPadState.DPadUp, (int)curPadState.DPadDown,
(int)curPadState.DPadLeft, (int)curPadState.DPadRight, (int)curPadState.L,
(int)curPadState.R, (int)curPadState.TriggerL, (int)curPadState.TriggerR,
(int)curPadState.AnalogStickX, (int)curPadState.AnalogStickY,
(int)curPadState.CStickX, (int)curPadState.CStickY, frame, (int)movPadState.Start,
(int)movPadState.A, (int)movPadState.B, (int)movPadState.X, (int)movPadState.Y,
(int)movPadState.Z, (int)movPadState.DPadUp, (int)movPadState.DPadDown,
(int)movPadState.DPadLeft, (int)movPadState.DPadRight, (int)movPadState.L,
(int)movPadState.R, (int)movPadState.TriggerL, (int)movPadState.TriggerR,
(int)movPadState.AnalogStickX, (int)movPadState.AnalogStickY,
(int)movPadState.CStickX, (int)movPadState.CStickY);
(int)curPadState.CStickX, (int)curPadState.CStickY, (int)curPadState.is_connected,
frame, (int)movPadState.Start, (int)movPadState.A, (int)movPadState.B,
(int)movPadState.X, (int)movPadState.Y, (int)movPadState.Z, (int)movPadState.DPadUp,
(int)movPadState.DPadDown, (int)movPadState.DPadLeft, (int)movPadState.DPadRight,
(int)movPadState.L, (int)movPadState.R, (int)movPadState.TriggerL,
(int)movPadState.TriggerR, (int)movPadState.AnalogStickX,
(int)movPadState.AnalogStickY, (int)movPadState.CStickX, (int)movPadState.CStickY,
(int)curPadState.is_connected);
}
}
}
@ -1113,6 +1123,8 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
memcpy(&s_padState, &s_temp_input[s_currentByte], sizeof(ControllerState));
s_currentByte += sizeof(ControllerState);
PadStatus->isConnected = s_padState.is_connected;
PadStatus->triggerLeft = s_padState.TriggerL;
PadStatus->triggerRight = s_padState.TriggerR;

View File

@ -39,10 +39,11 @@ struct ControllerState
bool Start : 1, A : 1, B : 1, X : 1, Y : 1, Z : 1; // Binary buttons, 6 bits
bool DPadUp : 1, DPadDown : 1, // Binary D-Pad buttons, 4 bits
DPadLeft : 1, DPadRight : 1;
bool L : 1, R : 1; // Binary triggers, 2 bits
bool disc : 1; // Checks for disc being changed
bool reset : 1; // Console reset button
bool reserved : 2; // Reserved bits used for padding, 2 bits
bool L : 1, R : 1; // Binary triggers, 2 bits
bool disc : 1; // Checks for disc being changed
bool reset : 1; // Console reset button
bool is_connected : 1; // Should controller be treated as connected
bool reserved : 1; // Reserved bits used for padding, 1 bit
u8 TriggerL, TriggerR; // Triggers, 16 bits
u8 AnalogStickX, AnalogStickY; // Main Stick, 16 bits

View File

@ -326,7 +326,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
PadMapping map = 0;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// Trusting server for good map value (>=0 && <4)
// add to pad buffer
@ -753,7 +753,7 @@ void NetPlayClient::SendPadState(const int in_game_pad, const GCPadStatus& pad)
packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
packet << static_cast<PadMapping>(in_game_pad);
packet << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX
<< pad.substickY << pad.triggerLeft << pad.triggerRight;
<< pad.substickY << pad.triggerLeft << pad.triggerRight << pad.isConnected;
SendAsync(std::move(packet));
}

View File

@ -520,7 +520,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
PadMapping map = 0;
GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight;
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// If the data is not from the correct player,
// then disconnect them.
@ -533,7 +533,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_DATA;
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY
<< pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight;
<< pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight
<< pad.isConnected;
SendToClients(spac, player.pid);
}

View File

@ -40,6 +40,7 @@ struct GCPadStatus
u8 triggerRight; // 0 <= triggerRight <= 255
u8 analogA; // 0 <= analogA <= 255
u8 analogB; // 0 <= analogB <= 255
bool isConnected{true};
static const u8 MAIN_STICK_CENTER_X = 0x80;
static const u8 MAIN_STICK_CENTER_Y = 0x80;