From 4488a4d388d2b35d3591b5cc94c470a0748643c7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 13 Feb 2011 03:06:12 +0000 Subject: [PATCH] - make pathfinder caching an ini setting tso its easy to test (disabled by default) - some code cleanup related to threads and sockets --- source/glest_game/ai/path_finder.cpp | 2 +- source/glest_game/graphics/renderer.cpp | 6 ++-- .../glest_game/network/server_interface.cpp | 6 ++-- .../sources/platform/posix/socket.cpp | 28 ++++++++++++------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/source/glest_game/ai/path_finder.cpp b/source/glest_game/ai/path_finder.cpp index 6a16e3af8..a00558b5f 100644 --- a/source/glest_game/ai/path_finder.cpp +++ b/source/glest_game/ai/path_finder.cpp @@ -356,7 +356,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout UnitPathInterface *path= unit->getPath(); // Check the previous path find cache for the unit to see if its good to // use - const bool tryLastPathCache = false; + const bool tryLastPathCache = Config::getInstance().getBool("EnablePathfinderCache","false"); if(tryLastPathCache == true && path != NULL) { UnitPathBasic *basicPathFinder = dynamic_cast(path); if(basicPathFinder != NULL && basicPathFinder->getLastPathCacheQueueCount() > 0) { diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index dfa105afa..dc9717067 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -126,7 +126,7 @@ const float Renderer::magicCircleRadius= 1.f; //perspective values const float Renderer::perspFov= 60.f; -const float Renderer::perspNearPlane= 2.f; +const float Renderer::perspNearPlane= 1.f; //const float Renderer::perspFarPlane= 50.f; const float Renderer::perspFarPlane= 1000.f; @@ -2591,8 +2591,8 @@ void Renderer::renderSelectionEffects() { (showDebugUILevel & debugui_unit_titles) == debugui_unit_titles) { const UnitPathInterface *path= unit->getPath(); - if(path != NULL) { - vector pathList = path->getQueue(); + if(path != NULL && dynamic_cast(path)) { + vector pathList = dynamic_cast(path)->getLastPathCacheQueue(); Vec2i lastPosValue; for(int i = 0; i < pathList.size(); ++i) { diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 0d4dd8deb..3e9c844f7 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -324,7 +324,7 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { } void ServerInterface::updateSlot(ConnectionSlotEvent *event) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(event != NULL) { bool &socketTriggered = event->socketTriggered; bool checkForNewClients = true; @@ -509,7 +509,7 @@ void ServerInterface::updateSocketTriggeredList(std::map & MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->getSocket() != NULL && - slots[i]->getSocket()->isSocketValid() == true) { + connectionSlot->getSocket()->isSocketValid() == true) { socketTriggeredList[connectionSlot->getSocket()->getSocketId()] = false; } } @@ -1188,6 +1188,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { ftpServer = NULL; } +/* SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i)); @@ -1197,6 +1198,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { connectionSlot->getSocket()->setBlock(true); } } +*/ } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 495d9cd73..5839aec5b 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -844,6 +844,7 @@ void Socket::disconnectSocket() { ::closesocket(sock); sock = -1; #endif + safeMutex.ReleaseLock(); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); @@ -893,7 +894,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) { bResult = true; - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] select detected data imaxsocket = %d...\n",__FILE__,__FUNCTION__,imaxsocket); for(std::map::iterator itermap = socketTriggeredList.begin(); itermap != socketTriggeredList.end(); itermap++) @@ -901,7 +902,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) PLATFORM_SOCKET socket = itermap->first; if (FD_ISSET(socket, &rfds)) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] FD_ISSET true for socket %d...\n",__FUNCTION__,socket); itermap->second = true; } @@ -911,7 +912,7 @@ bool Socket::hasDataToRead(std::map &socketTriggeredList) } } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList->size() = %d\n",__FILE__,__FUNCTION__,socketTriggeredList.size()); } } } @@ -1040,6 +1041,7 @@ int Socket::send(const void *data, int dataSize) { #else bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT); #endif + safeMutex.ReleaseLock(); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -1072,13 +1074,13 @@ int Socket::send(const void *data, int dataSize) { #else bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT); #endif - safeMutex.ReleaseLock(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); - if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { break; } + + safeMutex.ReleaseLock(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); } else { int iErr = getLastSocketError(); @@ -1114,16 +1116,17 @@ int Socket::send(const void *data, int dataSize) { #else bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, MSG_NOSIGNAL | MSG_DONTWAIT); #endif - safeMutex.ReleaseLock(); - if(bytesSent > 0) { totalBytesSent += bytesSent; } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { break; } + + safeMutex.ReleaseLock(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); } else { int iErr = getLastSocketError(); @@ -1168,6 +1171,7 @@ int Socket::receive(void *data, int dataSize) { if(isSocketValid() == true) { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); bytesReceived = recv(sock, reinterpret_cast(data), dataSize, 0); + safeMutex.ReleaseLock(); } if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText().c_str()); @@ -1221,6 +1225,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) { //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); + safeMutex.ReleaseLock(); //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } @@ -1321,6 +1326,7 @@ bool Socket::isReadable() { { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); i= select((int)sock + 1, &set, NULL, NULL, &tv); + safeMutex.ReleaseLock(); } if(i < 0) { //if(difftime(time(NULL),lastDebugEvent) >= 1) { @@ -1359,6 +1365,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) { { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); i = select((int)sock + 1, NULL, &set, NULL, &tv); + safeMutex.ReleaseLock(); } if(i < 0 ) { //if(difftime(time(NULL),lastDebugEvent) >= 1) { @@ -1541,6 +1548,7 @@ void ClientSocket::connect(const Ip &ip, int port) { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); err = select((int)sock + 1, NULL, &myset, NULL, &tv); + safeMutex.ReleaseLock(); } if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {