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();
NetworkMessageType msg = nmtInvalid;
int waitLoopCount = 0;
uint64 waitLoopCount = 0;
while(msg == nmtInvalid) {
msg = getNextMessageType(true);
if(msg == nmtInvalid) {
@ -1073,7 +1073,7 @@ NetworkMessageType ClientInterface::waitForMessage()
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;
}

View File

@ -394,16 +394,21 @@ NetworkMessageCommandList::NetworkMessageCommandList(int32 frameCount) {
}
bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand){
if(data.header.commandCount < maxCommandCount){
data.commands[static_cast<int>(data.header.commandCount)]= *networkCommand;
data.header.commandCount++;
return true;
}
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);
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;
// if(data.header.commandCount < maxCommandCount){
// data.commands[static_cast<int>(data.header.commandCount)]= *networkCommand;
// data.header.commandCount++;
// return true;
// }
// 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);
// 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;
data.commands.push_back(*networkCommand);
data.header.commandCount++;
return true;
}
bool NetworkMessageCommandList::receive(Socket* socket) {
@ -468,8 +473,10 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
//int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
if(data.header.commandCount > 0) {
data.commands.resize(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(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) {
for(int idx = 0 ; idx < data.header.commandCount; ++idx) {
@ -498,7 +505,11 @@ void NetworkMessageCommandList::send(Socket* socket) const {
assert(data.header.messageType==nmtCommandList);
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) {
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)
class NetworkMessageCommandList: public NetworkMessage {
private:
static const int maxCommandCount = 2496; // can be as large as 65535
//static const int maxCommandCount = 2496; // can be as large as 65535
private:
struct DataHeader {
@ -281,7 +281,8 @@ private:
struct Data {
DataHeader header;
NetworkCommand commands[maxCommandCount];
//NetworkCommand commands[maxCommandCount];
std::vector<NetworkCommand> commands;
};
private: