Fixed bug that cause the program to crash when closing if a server had been started.

Removed memory leaks in Client.cpp.
This commit is contained in:
Jocke
2015-12-09 14:41:26 +01:00
7 changed files with 90 additions and 31 deletions
+8 -3
View File
@@ -8,12 +8,14 @@
#include <GLFW/glfw3.h> // For input event
#include "Network/MessageType.h"
#include "Network/NetworkDefines.h"
#include "Network/NetworkDefinitions.h"
#include "Network/PlayerDefinition.h"
#include "Network/SnapshotDefinitions.h"
#include "Network/WinLeakCheck.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
class Client
@@ -24,8 +26,8 @@ public:
void Start(World* world, EventBroker* eventBroker);
void Close();
private:
// Threaded
void ReadFromServer();
void SendToServer();
int Receive(char* data, size_t length);
int CreateMessage(MessageType type, std::string message, char* data);
@@ -50,6 +52,7 @@ private:
int m_PlayerID = -1;
glm::vec2 m_PlayerPositions[MAXCONNECTIONS];
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
SnapshotDefinitions m_NextSnapshot;
std::clock_t m_StartPingTime;
double m_DurationOfPingTime;
std::string m_PlayerName;
@@ -61,7 +64,9 @@ private:
// Events
EventBroker* m_EventBroker;
EventRelay<Client, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown &e);
bool OnKeyDown(const Events::KeyDown &e);
EventRelay<Client, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp &e);
};
#endif
+5 -3
View File
@@ -1,15 +1,17 @@
#ifndef Server_h__
#define Server_h__
#include <string>
#include <ctime>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <glm/common.hpp>
#include "NetworkDefines.h"
#include "MessageType.h"
#include "Core/World.h"
#include "Network/MessageType.h"
#include "Network/NetworkDefinitions.h"
#include "Network/PlayerDefinition.h"
#include "Core/World.h"
class Server
{
@@ -0,0 +1,12 @@
#ifndef SnapshotDefinitions_h__
#define SnapshotDefinitions_h__
struct SnapshotDefinitions
{
// "+Forward" is 8 characters * sizeof(char) = 8
char* inputForward = new char[8];
// "+Right" is 6 characters * sizeof(char) = 6
char* inputRight = new char[6];
};
#endif