WIP Cleaning
This commit is contained in:
@@ -59,7 +59,6 @@ private:
|
|||||||
glm::vec2 m_PlayerPositions[MAXCONNECTIONS];
|
glm::vec2 m_PlayerPositions[MAXCONNECTIONS];
|
||||||
std::string m_PlayerName;
|
std::string m_PlayerName;
|
||||||
int m_PlayerID = -1;
|
int m_PlayerID = -1;
|
||||||
IsWASDKeyDown m_IsWASDKeyDown;
|
|
||||||
|
|
||||||
// Network logic
|
// Network logic
|
||||||
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
|
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using namespace boost::asio::ip;
|
|||||||
|
|
||||||
Client::Client() : m_Socket(m_IOService)
|
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
|
// Set up network stream
|
||||||
m_NextSnapshot.InputForward = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
@@ -89,19 +89,23 @@ void Client::SendSnapshotToServer()
|
|||||||
// Reset previouse key state in snapshot.
|
// Reset previouse key state in snapshot.
|
||||||
m_NextSnapshot.InputForward = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
|
|
||||||
|
auto player = m_World->GetComponent(m_PlayerDefinitions[m_PlayerID].EntityID, "Player");
|
||||||
|
|
||||||
|
|
||||||
// See if any movement keys are down
|
// See if any movement keys are down
|
||||||
// We dont care if it's overwritten by later
|
// We dont care if it's overwritten by later
|
||||||
// if statement. Watcha gonna do, right!
|
// if statement. Watcha gonna do, right!
|
||||||
if (m_IsWASDKeyDown.W) {
|
if (player["Forward"]) {
|
||||||
m_NextSnapshot.InputForward = "+Forward";
|
m_NextSnapshot.InputForward = "+Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.A) {
|
if (player["Left"]) {
|
||||||
m_NextSnapshot.InputRight = "-Right";
|
m_NextSnapshot.InputRight = "-Right";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.S) {
|
if (player["Back"]) {
|
||||||
m_NextSnapshot.InputForward = "-Forward";
|
m_NextSnapshot.InputForward = "-Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.D) {
|
if (player["Right"]) {
|
||||||
m_NextSnapshot.InputRight = "+Right";
|
m_NextSnapshot.InputRight = "+Right";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,8 +119,6 @@ void Client::SendSnapshotToServer()
|
|||||||
Send(package);
|
Send(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (m_NextSnapshot.InputRight != "") {
|
if (m_NextSnapshot.InputRight != "") {
|
||||||
Package package(MessageType::Event, m_SendPacketID);
|
Package package(MessageType::Event, m_SendPacketID);
|
||||||
package.AddString(m_NextSnapshot.InputRight);
|
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)
|
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||||
{
|
{
|
||||||
|
ComponentWrapper& player = m_World->GetComponent(m_PlayerDefinitions[m_PlayerID].EntityID, "Player");
|
||||||
if (e.Command == "Forward") {
|
if (e.Command == "Forward") {
|
||||||
if (e.Value > 0) {
|
if (e.Value > 0) {
|
||||||
m_IsWASDKeyDown.W = true;
|
(bool&)player["Forward"] = true;
|
||||||
} else if (e.Value < 0) {
|
} else if (e.Value < 0) {
|
||||||
m_IsWASDKeyDown.S = true;
|
(bool&)player["Back"] = true;
|
||||||
} else {
|
} else {
|
||||||
m_IsWASDKeyDown.W = false;
|
(bool&)player["Forward"] = false;
|
||||||
m_IsWASDKeyDown.S = false;
|
(bool&)player["Back"] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.Command == "Right") {
|
if (e.Command == "Right") {
|
||||||
if (e.Value > 0) {
|
if (e.Value > 0) {
|
||||||
m_IsWASDKeyDown.D = true;
|
(bool&)player["Right"] = true;
|
||||||
} else if (e.Value < 0) {
|
} else if (e.Value < 0) {
|
||||||
m_IsWASDKeyDown.A = true;
|
(bool&)player["Left"] = true;
|
||||||
} else {
|
} else {
|
||||||
m_IsWASDKeyDown.A = false;
|
(bool&)player["Left"] = false;
|
||||||
m_IsWASDKeyDown.D = false;
|
(bool&)player["Right"] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.Command == "Sprint") { // Connect for now
|
if (e.Command == "Sprint") { // Connect for now
|
||||||
|
|||||||
Reference in New Issue
Block a user