- attempt to see if this helps network performance

This commit is contained in:
Mark Vejvoda 2013-03-23 22:32:51 +00:00
parent ef58a2285d
commit 159cdc40d0
4 changed files with 15 additions and 15 deletions

View File

@ -898,7 +898,7 @@ void ClientInterface::updateFrame(int *checkFrame) {
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
int waitMilliseconds = (checkFrame == NULL ? 1 : 0); int waitMicroseconds = (checkFrame == NULL ? 100 : 0);
int simulateLag = Config::getInstance().getInt("SimulateClientLag","0"); int simulateLag = Config::getInstance().getInt("SimulateClientLag","0");
bool done= false; bool done= false;
while(done == false && this->quitThread == false) { while(done == false && this->quitThread == false) {
@ -906,7 +906,7 @@ void ClientInterface::updateFrame(int *checkFrame) {
//printf("BEFORE Client get networkMessageType\n"); //printf("BEFORE Client get networkMessageType\n");
//wait for the next message //wait for the next message
NetworkMessageType networkMessageType = waitForMessage(waitMilliseconds); NetworkMessageType networkMessageType = waitForMessage(waitMicroseconds);
//printf("AFTER Client got networkMessageType = %d\n",networkMessageType); //printf("AFTER Client got networkMessageType = %d\n",networkMessageType);
@ -1233,13 +1233,13 @@ bool ClientInterface::getNetworkCommand(int frameCount, int currentCachedPending
//cachedPendingCommands.erase(frameCount); //cachedPendingCommands.erase(frameCount);
cachedPendingCommands[frameCount].clear(); cachedPendingCommands[frameCount].clear();
} }
safeMutex.ReleaseLock(); safeMutex.ReleaseLock(true);
result = true; result = true;
break; break;
} }
else { else {
safeMutex.ReleaseLock(); safeMutex.ReleaseLock(true);
// No data for this frame // No data for this frame
//if(cachedPendingCommandsIndex > currentCachedPendingCommandsIndex) { //if(cachedPendingCommandsIndex > currentCachedPendingCommandsIndex) {
// break; // break;
@ -1721,7 +1721,7 @@ string ClientInterface::getNetworkStatus() {
return szBuf; return szBuf;
} }
NetworkMessageType ClientInterface::waitForMessage(int waitMilliseconds) NetworkMessageType ClientInterface::waitForMessage(int waitMicroseconds)
{ {
// Debug! // Debug!
/* /*
@ -1744,7 +1744,7 @@ NetworkMessageType ClientInterface::waitForMessage(int waitMilliseconds)
NetworkMessageType msg = nmtInvalid; NetworkMessageType msg = nmtInvalid;
//uint64 waitLoopCount = 0; //uint64 waitLoopCount = 0;
while(msg == nmtInvalid && this->quitThread == false) { while(msg == nmtInvalid && this->quitThread == false) {
msg = getNextMessageType(waitMilliseconds); msg = getNextMessageType(waitMicroseconds);
if(msg == nmtInvalid) { if(msg == nmtInvalid) {
if(chrono.getMillis() % 250 == 0 && isConnected() == false) { if(chrono.getMillis() % 250 == 0 && isConnected() == false) {
if(quit == false) { if(quit == false) {
@ -1781,8 +1781,8 @@ NetworkMessageType ClientInterface::waitForMessage(int waitMilliseconds)
close(); close();
return msg; return msg;
} }
// Sleep ever second we wait to let other threads work // Sleep every x milli-seconds we wait to let other threads work
else if(chrono.getMillis() % 25 == 0) { else if(chrono.getMillis() % 50 == 0) {
sleep(5); sleep(5);
} }

View File

@ -178,7 +178,7 @@ public:
protected: protected:
Mutex * getServerSynchAccessor() { return NULL; } Mutex * getServerSynchAccessor() { return NULL; }
NetworkMessageType waitForMessage(int waitMilliseconds=0); NetworkMessageType waitForMessage(int waitMicroseconds=0);
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType); bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
void updateFrame(int *checkFrame); void updateFrame(int *checkFrame);

View File

@ -152,8 +152,8 @@ public:
static bool hasDataToRead(PLATFORM_SOCKET socket); static bool hasDataToRead(PLATFORM_SOCKET socket);
bool hasDataToRead(); bool hasDataToRead();
static bool hasDataToReadWithWait(PLATFORM_SOCKET socket,int waitMilliseconds); static bool hasDataToReadWithWait(PLATFORM_SOCKET socket,int waitMicroseconds);
bool hasDataToReadWithWait(int waitMilliseconds); bool hasDataToReadWithWait(int waitMicroseconds);
virtual void disconnectSocket(); virtual void disconnectSocket();

View File

@ -1077,12 +1077,12 @@ bool Socket::hasDataToRead(PLATFORM_SOCKET socket)
return bResult; return bResult;
} }
bool Socket::hasDataToReadWithWait(int waitMilliseconds) { bool Socket::hasDataToReadWithWait(int waitMicroseconds) {
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE); MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
return Socket::hasDataToReadWithWait(sock,waitMilliseconds) ; return Socket::hasDataToReadWithWait(sock,waitMicroseconds) ;
} }
bool Socket::hasDataToReadWithWait(PLATFORM_SOCKET socket,int waitMilliseconds) { bool Socket::hasDataToReadWithWait(PLATFORM_SOCKET socket,int waitMicroseconds) {
bool bResult = false; bool bResult = false;
Chrono chono; Chrono chono;
@ -1098,7 +1098,7 @@ bool Socket::hasDataToReadWithWait(PLATFORM_SOCKET socket,int waitMilliseconds)
/* Wait up to 0 seconds. */ /* Wait up to 0 seconds. */
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1000 * waitMilliseconds; tv.tv_usec = waitMicroseconds;
int retval = 0; int retval = 0;
{ {