From ba831f8a3c38c94d42ec9ab4814a837eb8acb8db Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 17 Dec 2015 10:59:55 +0100 Subject: [PATCH] WIP Cleaning --- include/Engine/Network/Client.h | 1 - src/Engine/Network/Client.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index 415a8847..025a1259 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -59,7 +59,6 @@ private: glm::vec2 m_PlayerPositions[MAXCONNECTIONS]; std::string m_PlayerName; int m_PlayerID = -1; - IsWASDKeyDown m_IsWASDKeyDown; // Network logic PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS]; diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index 29b7ddde..c2c486ab 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -5,7 +5,7 @@ using namespace boost::asio::ip; Client::Client() : m_Socket(m_IOService) { - m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.6"), 13); + m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.2"), 13); // Set up network stream m_NextSnapshot.InputForward = ""; m_NextSnapshot.InputRight = ""; @@ -89,19 +89,23 @@ void Client::SendSnapshotToServer() // Reset previouse key state in snapshot. m_NextSnapshot.InputForward = ""; m_NextSnapshot.InputRight = ""; + + auto player = m_World->GetComponent(m_PlayerDefinitions[m_PlayerID].EntityID, "Player"); + + // See if any movement keys are down // We dont care if it's overwritten by later // if statement. Watcha gonna do, right! - if (m_IsWASDKeyDown.W) { + if (player["Forward"]) { m_NextSnapshot.InputForward = "+Forward"; } - if (m_IsWASDKeyDown.A) { + if (player["Left"]) { m_NextSnapshot.InputRight = "-Right"; } - if (m_IsWASDKeyDown.S) { + if (player["Back"]) { m_NextSnapshot.InputForward = "-Forward"; } - if (m_IsWASDKeyDown.D) { + if (player["Right"]) { m_NextSnapshot.InputRight = "+Right"; } @@ -115,8 +119,6 @@ void Client::SendSnapshotToServer() Send(package); } - - if (m_NextSnapshot.InputRight != "") { Package package(MessageType::Event, m_SendPacketID); package.AddString(m_NextSnapshot.InputRight); @@ -291,24 +293,25 @@ void Client::MoveMessageHead(char*& data, size_t& length, size_t stepSize) bool Client::OnInputCommand(const Events::InputCommand & e) { + ComponentWrapper& player = m_World->GetComponent(m_PlayerDefinitions[m_PlayerID].EntityID, "Player"); if (e.Command == "Forward") { if (e.Value > 0) { - m_IsWASDKeyDown.W = true; + (bool&)player["Forward"] = true; } else if (e.Value < 0) { - m_IsWASDKeyDown.S = true; + (bool&)player["Back"] = true; } else { - m_IsWASDKeyDown.W = false; - m_IsWASDKeyDown.S = false; + (bool&)player["Forward"] = false; + (bool&)player["Back"] = false; } } if (e.Command == "Right") { if (e.Value > 0) { - m_IsWASDKeyDown.D = true; + (bool&)player["Right"] = true; } else if (e.Value < 0) { - m_IsWASDKeyDown.A = true; + (bool&)player["Left"] = true; } else { - m_IsWASDKeyDown.A = false; - m_IsWASDKeyDown.D = false; + (bool&)player["Left"] = false; + (bool&)player["Right"] = false; } } if (e.Command == "Sprint") { // Connect for now