removed limit of network commands count (2496) and just use dynamically sized vectors (this may make game play more stable when there are lots of commands issued)

This commit is contained in:
Mark Vejvoda 2011-10-28 01:58:15 +00:00
parent 421e38cab4
commit 1293771964
3 changed files with 28 additions and 16 deletions

View File

@ -1024,7 +1024,7 @@ NetworkMessageType ClientInterface::waitForMessage()
chrono.start(); chrono.start();
NetworkMessageType msg = nmtInvalid; NetworkMessageType msg = nmtInvalid;
int waitLoopCount = 0; uint64 waitLoopCount = 0;
while(msg == nmtInvalid) { while(msg == nmtInvalid) {
msg = getNextMessageType(true); msg = getNextMessageType(true);
if(msg == nmtInvalid) { if(msg == nmtInvalid) {
@ -1073,7 +1073,7 @@ NetworkMessageType ClientInterface::waitForMessage()
waitLoopCount++; waitLoopCount++;
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %ull, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg);
return msg; return msg;
} }

View File

@ -394,16 +394,21 @@ NetworkMessageCommandList::NetworkMessageCommandList(int32 frameCount) {
} }
bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand){ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand){
if(data.header.commandCount < maxCommandCount){ // if(data.header.commandCount < maxCommandCount){
data.commands[static_cast<int>(data.header.commandCount)]= *networkCommand; // data.commands[static_cast<int>(data.header.commandCount)]= *networkCommand;
data.header.commandCount++; // data.header.commandCount++;
return true; // return true;
} // }
else { // else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount); // if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount); // SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount);
} // }
return false; // return false;
data.commands.push_back(*networkCommand);
data.header.commandCount++;
return true;
} }
bool NetworkMessageCommandList::receive(Socket* socket) { bool NetworkMessageCommandList::receive(Socket* socket) {
@ -468,8 +473,10 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
//int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount); //int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
if(data.header.commandCount > 0) { if(data.header.commandCount > 0) {
data.commands.resize(data.header.commandCount);
int totalMsgSize = (sizeof(NetworkCommand) * data.header.commandCount); int totalMsgSize = (sizeof(NetworkCommand) * data.header.commandCount);
result = NetworkMessage::receive(socket, &data.commands, totalMsgSize, true); result = NetworkMessage::receive(socket, &data.commands[0], totalMsgSize, true);
if(result == true) { if(result == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) {
for(int idx = 0 ; idx < data.header.commandCount; ++idx) { for(int idx = 0 ; idx < data.header.commandCount; ++idx) {
@ -498,7 +505,11 @@ void NetworkMessageCommandList::send(Socket* socket) const {
assert(data.header.messageType==nmtCommandList); assert(data.header.messageType==nmtCommandList);
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount); int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
NetworkMessage::send(socket, &data, totalMsgSize); //NetworkMessage::send(socket, &data, totalMsgSize);
NetworkMessage::send(socket, &data.header, commandListHeaderSize);
if(data.header.commandCount > 0) {
NetworkMessage::send(socket, &data.commands[0], (sizeof(NetworkCommand) * data.header.commandCount));
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d, frameCount = %d, data.commandCount = %d\n",

View File

@ -268,7 +268,7 @@ public:
#pragma pack(push, 1) #pragma pack(push, 1)
class NetworkMessageCommandList: public NetworkMessage { class NetworkMessageCommandList: public NetworkMessage {
private: private:
static const int maxCommandCount = 2496; // can be as large as 65535 //static const int maxCommandCount = 2496; // can be as large as 65535
private: private:
struct DataHeader { struct DataHeader {
@ -281,7 +281,8 @@ private:
struct Data { struct Data {
DataHeader header; DataHeader header;
NetworkCommand commands[maxCommandCount]; //NetworkCommand commands[maxCommandCount];
std::vector<NetworkCommand> commands;
}; };
private: private: