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
+2 -2
View File
@@ -4,9 +4,9 @@
struct SnapshotDefinitions
{
// "+Forward" is 8 characters * sizeof(char) = 8
char* InputForward = new char[8];
std::string InputForward;
// "+Right" is 6 characters * sizeof(char) = 6
char* InputRight = new char[6];
std::string InputRight;
};
struct IsWASDKeyDown
+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);
}
}
+4 -6
View File
@@ -1,12 +1,10 @@
#include "Network/Server.h"
Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 13))
{
}
{ }
Server::~Server()
{
}
{ }
void Server::Start(World* world)
@@ -49,7 +47,7 @@ void Server::ReadFromClients()
int snapshotInterval = 50;
int timeToCheckTimeOutTime = 100;
while(m_ThreadIsRunning) {
while (m_ThreadIsRunning) {
// m_ThreadIsRunning might be unnecessary but the
// program crashed if it executed m_Socket.available()
// when closing the program.
@@ -310,7 +308,7 @@ void Server::ParseEvent(char * data, size_t length)
void Server::ParseConnect(char * data, size_t length)
{
std::cout << "Parsing connection." << std::endl;
// Check if player is already connected
for (int i = 0; i < MAXCONNECTIONS; i++) {
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
return;