Cleaned code

This commit is contained in:
stiffly
2015-12-17 10:47:08 +01:00
parent 97a0d97b0b
commit 4c29e071af
2 changed files with 43 additions and 47 deletions
+10 -13
View File
@@ -5,7 +5,6 @@
#include <ctime> #include <ctime>
#include <glm/common.hpp> #include <glm/common.hpp>
#include <GLFW/glfw3.h> // For input event
#include "Network/MessageType.h" #include "Network/MessageType.h"
#include "Network/NetworkDefinitions.h" #include "Network/NetworkDefinitions.h"
@@ -14,8 +13,6 @@
#include "Network/WinLeakCheck.h" #include "Network/WinLeakCheck.h"
#include "Core/World.h" #include "Core/World.h"
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Input/EInputCommand.h" #include "Input/EInputCommand.h"
#include "Network/Network.h" #include "Network/Network.h"
@@ -33,7 +30,6 @@ private:
int Receive(char* data, size_t length); int Receive(char* data, size_t length);
void Send(Package& message); void Send(Package& message);
int CreateMessage(MessageType type, std::string message, char* data);
void Connect(); void Connect();
void Disconnect(); void Disconnect();
void Ping(); void Ping();
@@ -47,7 +43,7 @@ private:
void CreateNewPlayer(int i); void CreateNewPlayer(int i);
void IdentifyPacketLoss(); void IdentifyPacketLoss();
// udp stuff // UDP logic
boost::asio::ip::udp::endpoint m_ReceiverEndpoint; boost::asio::ip::udp::endpoint m_ReceiverEndpoint;
boost::asio::io_service m_IOService; boost::asio::io_service m_IOService;
boost::asio::ip::udp::socket m_Socket; boost::asio::ip::udp::socket m_Socket;
@@ -57,22 +53,23 @@ private:
unsigned int m_PreviousPacketID = 0; unsigned int m_PreviousPacketID = 0;
unsigned int m_SendPacketID = 0; unsigned int m_SendPacketID = 0;
// Game Logic // Game logic
std::vector<unsigned int> m_PlayersToCreate;
World* m_World; World* m_World;
int m_PlayerID = -1; std::vector<unsigned int> m_PlayersToCreate;
glm::vec2 m_PlayerPositions[MAXCONNECTIONS]; glm::vec2 m_PlayerPositions[MAXCONNECTIONS];
std::string m_PlayerName;
int m_PlayerID = -1;
IsWASDKeyDown m_IsWASDKeyDown;
// Network logic
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS]; PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
SnapshotDefinitions m_NextSnapshot; SnapshotDefinitions m_NextSnapshot;
std::clock_t m_StartPingTime;
double m_DurationOfPingTime;
std::string m_PlayerName;
bool m_ThreadIsRunning = true; bool m_ThreadIsRunning = true;
double m_DurationOfPingTime;
std::clock_t m_StartPingTime;
// Use to check if we should send disconnect message // Use to check if we should send disconnect message
// if game is turned of by closing window. // if game is turned of by closing window.
bool m_WasStarted = false; bool m_WasStarted = false;
IsWASDKeyDown m_IsWASDKeyDown;
// Events // Events
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
+3 -4
View File
@@ -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.2"), 13); m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.6"), 13);
// Set up network stream // Set up network stream
m_NextSnapshot.InputForward = ""; m_NextSnapshot.InputForward = "";
m_NextSnapshot.InputRight = ""; m_NextSnapshot.InputRight = "";
@@ -294,8 +294,7 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
if (e.Command == "Forward") { if (e.Command == "Forward") {
if (e.Value > 0) { if (e.Value > 0) {
m_IsWASDKeyDown.W = true; m_IsWASDKeyDown.W = true;
} } else if (e.Value < 0) {
else if (e.Value < 0) {
m_IsWASDKeyDown.S = true; m_IsWASDKeyDown.S = true;
} else { } else {
m_IsWASDKeyDown.W = false; m_IsWASDKeyDown.W = false;
@@ -312,7 +311,7 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
m_IsWASDKeyDown.D = false; m_IsWASDKeyDown.D = false;
} }
} }
if (e.Command == "Sprint") { // Temp connect if (e.Command == "Sprint") { // Connect for now
Connect(); Connect();
} }
return false; return false;