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:
@@ -4,9 +4,9 @@
|
|||||||
struct SnapshotDefinitions
|
struct SnapshotDefinitions
|
||||||
{
|
{
|
||||||
// "+Forward" is 8 characters * sizeof(char) = 8
|
// "+Forward" is 8 characters * sizeof(char) = 8
|
||||||
char* InputForward = new char[8];
|
std::string InputForward;
|
||||||
// "+Right" is 6 characters * sizeof(char) = 6
|
// "+Right" is 6 characters * sizeof(char) = 6
|
||||||
char* InputRight = new char[6];
|
std::string InputRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IsWASDKeyDown
|
struct IsWASDKeyDown
|
||||||
|
|||||||
@@ -77,19 +77,19 @@ void Client::SendSnapshotToServer()
|
|||||||
Package message(MessageType::Event, m_SendPacketID);
|
Package message(MessageType::Event, m_SendPacketID);
|
||||||
message.AddString(m_NextSnapshot.InputForward);
|
message.AddString(m_NextSnapshot.InputForward);
|
||||||
Send(message);
|
Send(message);
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputForward = "";
|
||||||
m_NextSnapshot.InputRight = "";
|
m_NextSnapshot.InputRight = "";
|
||||||
// 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 (m_IsWASDKeyDown.W) {
|
||||||
m_NextSnapshot.InputRight = "+Forward";
|
m_NextSnapshot.InputForward = "+Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.A) {
|
if (m_IsWASDKeyDown.A) {
|
||||||
m_NextSnapshot.InputRight = "-Right";
|
m_NextSnapshot.InputRight = "-Right";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.S) {
|
if (m_IsWASDKeyDown.S) {
|
||||||
m_NextSnapshot.InputRight = "-Forward";
|
m_NextSnapshot.InputForward = "-Forward";
|
||||||
}
|
}
|
||||||
if (m_IsWASDKeyDown.D) {
|
if (m_IsWASDKeyDown.D) {
|
||||||
m_NextSnapshot.InputRight = "+Right";
|
m_NextSnapshot.InputRight = "+Right";
|
||||||
@@ -148,6 +148,9 @@ void Client::ParseConnect(char* data, size_t len)
|
|||||||
{
|
{
|
||||||
memcpy(&m_PacketID, data, sizeof(int));
|
memcpy(&m_PacketID, data, sizeof(int));
|
||||||
m_PreviousPacketID = m_PacketID;
|
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;
|
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)
|
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;
|
std::string tempName;
|
||||||
for (size_t i = 0; i < MAXCONNECTIONS; i++) {
|
for (size_t i = 0; i < MAXCONNECTIONS; i++) {
|
||||||
// We're checking for empty name for now. This might not be the best way,
|
// 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
|
// if no packets lost, difference should be equal to 1
|
||||||
int difference = m_PacketID - m_PreviousPacketID;
|
int difference = m_PacketID - m_PreviousPacketID;
|
||||||
if (difference != 1) {
|
if (difference != 1) {
|
||||||
for (int i = m_PreviousPacketID + 1; i < m_PacketID; i++)
|
LOG_INFO("%i Packet(s) were lost...", difference);
|
||||||
{
|
|
||||||
LOG_INFO("Packet %i was lost...", i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
#include "Network/Server.h"
|
#include "Network/Server.h"
|
||||||
|
|
||||||
Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 13))
|
Server::Server() : m_Socket(m_IOService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 13))
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Server::Start(World* world)
|
void Server::Start(World* world)
|
||||||
@@ -49,7 +47,7 @@ void Server::ReadFromClients()
|
|||||||
int snapshotInterval = 50;
|
int snapshotInterval = 50;
|
||||||
int timeToCheckTimeOutTime = 100;
|
int timeToCheckTimeOutTime = 100;
|
||||||
|
|
||||||
while(m_ThreadIsRunning) {
|
while (m_ThreadIsRunning) {
|
||||||
// m_ThreadIsRunning might be unnecessary but the
|
// m_ThreadIsRunning might be unnecessary but the
|
||||||
// program crashed if it executed m_Socket.available()
|
// program crashed if it executed m_Socket.available()
|
||||||
// when closing the program.
|
// when closing the program.
|
||||||
@@ -310,7 +308,7 @@ void Server::ParseEvent(char * data, size_t length)
|
|||||||
void Server::ParseConnect(char * data, size_t length)
|
void Server::ParseConnect(char * data, size_t length)
|
||||||
{
|
{
|
||||||
std::cout << "Parsing connection." << std::endl;
|
std::cout << "Parsing connection." << std::endl;
|
||||||
|
// Check if player is already connected
|
||||||
for (int i = 0; i < MAXCONNECTIONS; i++) {
|
for (int i = 0; i < MAXCONNECTIONS; i++) {
|
||||||
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
|
if (m_PlayerDefinitions[i].Endpoint.address() == m_ReceiverEndpoint.address()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user