NetPlayClient: Make m_state private

Also turns it into an enum class.
This commit is contained in:
Lioncash 2016-01-24 21:58:56 -05:00
parent 102672a797
commit 1d8ff504a5
2 changed files with 21 additions and 21 deletions

View File

@ -59,8 +59,7 @@ NetPlayClient::~NetPlayClient()
// called from ---GUI--- thread // called from ---GUI--- thread
NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, const std::string& centralServer, u16 centralPort) NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, const std::string& centralServer, u16 centralPort)
: m_state(Failure) : m_dialog(dialog)
, m_dialog(dialog)
, m_client(nullptr) , m_client(nullptr)
, m_server(nullptr) , m_server(nullptr)
, m_is_running(false) , m_is_running(false)
@ -134,7 +133,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
m_traversal_client->ReconnectToServer(); m_traversal_client->ReconnectToServer();
m_traversal_client->m_Client = this; m_traversal_client->m_Client = this;
m_host_spec = address; m_host_spec = address;
m_state = WaitingForTraversalClientConnection; m_connection_state = ConnectionState::WaitingForTraversalClientConnection;
OnTraversalStateChanged(); OnTraversalStateChanged();
m_connecting = true; m_connecting = true;
@ -156,7 +155,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
m_server = netEvent.peer; m_server = netEvent.peer;
if (Connect()) if (Connect())
{ {
m_state = Connected; m_connection_state = ConnectionState::Connected;
m_thread = std::thread(&NetPlayClient::ThreadFunc, this); m_thread = std::thread(&NetPlayClient::ThreadFunc, this);
} }
return; return;
@ -501,7 +500,7 @@ void NetPlayClient::Disconnect()
{ {
ENetEvent netEvent; ENetEvent netEvent;
m_connecting = false; m_connecting = false;
m_state = Failure; m_connection_state = ConnectionState::Failure;
if (m_server) if (m_server)
enet_peer_disconnect(m_server, 0); enet_peer_disconnect(m_server, 0);
else else
@ -766,13 +765,13 @@ void NetPlayClient::ClearBuffers()
// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread
void NetPlayClient::OnTraversalStateChanged() void NetPlayClient::OnTraversalStateChanged()
{ {
if (m_state == WaitingForTraversalClientConnection && if (m_connection_state == ConnectionState::WaitingForTraversalClientConnection &&
m_traversal_client->m_State == TraversalClient::Connected) m_traversal_client->m_State == TraversalClient::Connected)
{ {
m_state = WaitingForTraversalClientConnectReady; m_connection_state = ConnectionState::WaitingForTraversalClientConnectReady;
m_traversal_client->ConnectToClient(m_host_spec); m_traversal_client->ConnectToClient(m_host_spec);
} }
else if (m_state != Failure && else if (m_connection_state != ConnectionState::Failure &&
m_traversal_client->m_State == TraversalClient::Failure) m_traversal_client->m_State == TraversalClient::Failure)
{ {
Disconnect(); Disconnect();
@ -782,9 +781,9 @@ void NetPlayClient::OnTraversalStateChanged()
// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread
void NetPlayClient::OnConnectReady(ENetAddress addr) void NetPlayClient::OnConnectReady(ENetAddress addr)
{ {
if (m_state == WaitingForTraversalClientConnectReady) if (m_connection_state == ConnectionState::WaitingForTraversalClientConnectReady)
{ {
m_state = Connecting; m_connection_state = ConnectionState::Connecting;
enet_host_connect(m_client, &addr, 0, 0); enet_host_connect(m_client, &addr, 0, 0);
} }
} }
@ -793,7 +792,7 @@ void NetPlayClient::OnConnectReady(ENetAddress addr)
void NetPlayClient::OnConnectFailed(u8 reason) void NetPlayClient::OnConnectFailed(u8 reason)
{ {
m_connecting = false; m_connecting = false;
m_state = Failure; m_connection_state = ConnectionState::Failure;
switch (reason) switch (reason)
{ {
case TraversalConnectFailedClientDidntRespond: case TraversalConnectFailedClientDidntRespond:

View File

@ -80,16 +80,6 @@ public:
static void SendTimeBase(); static void SendTimeBase();
enum State
{
WaitingForTraversalClientConnection,
WaitingForTraversalClientConnectReady,
Connecting,
WaitingForHelloResponse,
Connected,
Failure
} m_state;
protected: protected:
void ClearBuffers(); void ClearBuffers();
@ -128,6 +118,16 @@ protected:
bool m_is_recording; bool m_is_recording;
private: private:
enum class ConnectionState
{
WaitingForTraversalClientConnection,
WaitingForTraversalClientConnectReady,
Connecting,
WaitingForHelloResponse,
Connected,
Failure
};
void UpdateDevices(); void UpdateDevices();
void SendPadState(const PadMapping in_game_pad, const GCPadStatus& np); void SendPadState(const PadMapping in_game_pad, const GCPadStatus& np);
void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw); void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw);
@ -137,6 +137,7 @@ private:
bool Connect(); bool Connect();
bool m_is_connected = false; bool m_is_connected = false;
ConnectionState m_connection_state = ConnectionState::Failure;
PlayerId m_pid; PlayerId m_pid;
std::map<PlayerId, Player> m_players; std::map<PlayerId, Player> m_players;