Fixed bug which made the player not able to move diagonally.

Fixed a bug were m_PlayerID was not set for the client when connecting.
This commit is contained in:
Jocke
2015-12-14 16:35:43 +01:00
parent 23c3f0709b
commit 63db236dfa
3 changed files with 79 additions and 81 deletions
+8 -8
View File
@@ -77,19 +77,19 @@ void Client::SendSnapshotToServer()
Package message(MessageType::Event, m_SendPacketID);
message.AddString(m_NextSnapshot.InputForward);
Send(message);
m_NextSnapshot.InputRight = "";
m_NextSnapshot.InputForward = "";
m_NextSnapshot.InputRight = "";
// 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) {
m_NextSnapshot.InputRight = "+Forward";
m_NextSnapshot.InputForward = "+Forward";
}
if (m_IsWASDKeyDown.A) {
m_NextSnapshot.InputRight = "-Right";
}
if (m_IsWASDKeyDown.S) {
m_NextSnapshot.InputRight = "-Forward";
m_NextSnapshot.InputForward = "-Forward";
}
if (m_IsWASDKeyDown.D) {
m_NextSnapshot.InputRight = "+Right";
@@ -148,6 +148,9 @@ void Client::ParseConnect(char* data, size_t len)
{
memcpy(&m_PacketID, data, sizeof(int));
m_PreviousPacketID = m_PacketID;
MoveMessageHead(data, len, sizeof(int));
memcpy(&m_PlayerID, data, sizeof(int));
MoveMessageHead(data, len, sizeof(int));
std::cout << m_PacketID << ": I am player: " << m_PlayerID << std::endl;
}
@@ -184,7 +187,7 @@ void Client::ParseEventMessage(char* data, size_t length)
void Client::ParseSnapshot(char* data, size_t length)
{
std::cout << m_PacketID << ": Parsing incoming snapshot." << std::endl;
//std::cout << m_PacketID << ": Parsing incoming snapshot." << std::endl;
std::string tempName;
for (size_t i = 0; i < MAXCONNECTIONS; i++) {
// We're checking for empty name for now. This might not be the best way,
@@ -332,9 +335,6 @@ void Client::IdentifyPacketLoss()
// if no packets lost, difference should be equal to 1
int difference = m_PacketID - m_PreviousPacketID;
if (difference != 1) {
for (int i = m_PreviousPacketID + 1; i < m_PacketID; i++)
{
LOG_INFO("Packet %i was lost...", i);
}
LOG_INFO("%i Packet(s) were lost...", difference);
}
}