Packets now dynamically allocates more memory when they need it.

Increased local receive buffer for Client and Server() and removed the magic number that was used
In Server.h and Client.h
(char readBuffer[INPUTSIZE] = { 0 }).
Packets start size has now been increased to 512 bytes.
Changed ComponentInfo::FieldsInOrder to store strings instead of pointers.
Removed HasEntity() and are now using ValidEntity() instead.
This commit is contained in:
Jocke
2016-01-12 12:00:19 +01:00
parent b37ffc7449
commit 236230d12c
13 changed files with 307 additions and 356 deletions
+3 -2
View File
@@ -32,7 +32,7 @@ private:
// Sending message to server logic
int bytesRead = -1;
char readBuf[1024] = { 0 };
char readBuf[INPUTSIZE] = { 0 };
int snapshotInterval = 33;
std::clock_t previousSnapshotMessage = std::clock();
@@ -59,7 +59,7 @@ private:
// Private member functions
void readFromServer();
void sendSnapshotToServer();
int receive(char* data, size_t length);
int receive(char* data, size_t length);
void send(Packet& packet);
void connect();
void disconnect();
@@ -67,6 +67,7 @@ private:
void moveMessageHead(char*& data, size_t& length, size_t stepSize);
void parseMessageType(Packet& packet);
void parseEventMessage(Packet& packet);
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType);
void parseConnect(Packet& packet);
void parsePing();
void parseServerPing();
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Network/Packet.h"
#define MAXCONNECTIONS 8
#define INPUTSIZE 128
#define INPUTSIZE 4097
class Network
{
+5 -4
View File
@@ -23,8 +23,8 @@ public:
{
// Check if we are trying to add more than the package can fit.
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for!");
return;
LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2);
resizeData();
}
memcpy(m_Data + m_Offset, &val, sizeof(T));
m_Offset += sizeof(T);
@@ -43,7 +43,7 @@ public:
return returnValue;
}
// Add a string to the message
void WriteString(std::string str);
void WriteString(const std::string& str);
// Add data to the message
void WriteData(char* data, int sizeOfData);
// Pops the first element as if it was a string.
@@ -59,7 +59,8 @@ private:
char* m_Data;
unsigned int m_ReturnDataOffset = 0;
int m_Offset = 0;
unsigned int m_MaxPacketSize = 128;
unsigned int m_MaxPacketSize = 512;
void resizeData();
};
#endif
+1 -2
View File
@@ -30,7 +30,7 @@ private:
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
// Sending messages to client logic
char readBuffer[1024] = { 0 };
char readBuffer[INPUTSIZE] = { 0 };
int bytesRead = 0;
// time for previouse message
std::clock_t previousePingMessage = std::clock();
@@ -67,7 +67,6 @@ private:
void moveMessageHead(char*& data, size_t& length, size_t stepSize);
void broadcast(std::string message);
void broadcast(Packet& packet);
//void parseShitTest(Packet& packet); // Remove this when network is working
void sendSnapshot();
void sendPing();
void checkForTimeOuts();