- make pathfinder caching an ini setting tso its easy to test (disabled by default)

- some code cleanup related to threads and sockets
This commit is contained in:
Mark Vejvoda
2011-02-13 03:06:12 +00:00
parent 91a56e7805
commit 4488a4d388
4 changed files with 26 additions and 16 deletions

View File

@@ -356,7 +356,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
UnitPathInterface *path= unit->getPath(); UnitPathInterface *path= unit->getPath();
// Check the previous path find cache for the unit to see if its good to // Check the previous path find cache for the unit to see if its good to
// use // use
const bool tryLastPathCache = false; const bool tryLastPathCache = Config::getInstance().getBool("EnablePathfinderCache","false");
if(tryLastPathCache == true && path != NULL) { if(tryLastPathCache == true && path != NULL) {
UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path); UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path);
if(basicPathFinder != NULL && basicPathFinder->getLastPathCacheQueueCount() > 0) { if(basicPathFinder != NULL && basicPathFinder->getLastPathCacheQueueCount() > 0) {

View File

@@ -126,7 +126,7 @@ const float Renderer::magicCircleRadius= 1.f;
//perspective values //perspective values
const float Renderer::perspFov= 60.f; 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= 50.f;
const float Renderer::perspFarPlane= 1000.f; const float Renderer::perspFarPlane= 1000.f;
@@ -2591,8 +2591,8 @@ void Renderer::renderSelectionEffects() {
(showDebugUILevel & debugui_unit_titles) == debugui_unit_titles) { (showDebugUILevel & debugui_unit_titles) == debugui_unit_titles) {
const UnitPathInterface *path= unit->getPath(); const UnitPathInterface *path= unit->getPath();
if(path != NULL) { if(path != NULL && dynamic_cast<const UnitPathBasic *>(path)) {
vector<Vec2i> pathList = path->getQueue(); vector<Vec2i> pathList = dynamic_cast<const UnitPathBasic *>(path)->getLastPathCacheQueue();
Vec2i lastPosValue; Vec2i lastPosValue;
for(int i = 0; i < pathList.size(); ++i) { for(int i = 0; i < pathList.size(); ++i) {

View File

@@ -324,7 +324,7 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) {
} }
void ServerInterface::updateSlot(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) { if(event != NULL) {
bool &socketTriggered = event->socketTriggered; bool &socketTriggered = event->socketTriggered;
bool checkForNewClients = true; bool checkForNewClients = true;
@@ -509,7 +509,7 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i)); MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i));
ConnectionSlot* connectionSlot= slots[i]; ConnectionSlot* connectionSlot= slots[i];
if(connectionSlot != NULL && connectionSlot->getSocket() != NULL && if(connectionSlot != NULL && connectionSlot->getSocket() != NULL &&
slots[i]->getSocket()->isSocketValid() == true) { connectionSlot->getSocket()->isSocketValid() == true) {
socketTriggeredList[connectionSlot->getSocket()->getSocketId()] = false; socketTriggeredList[connectionSlot->getSocket()->getSocketId()] = false;
} }
} }
@@ -1188,6 +1188,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
ftpServer = NULL; ftpServer = NULL;
} }
/*
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__);
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(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); connectionSlot->getSocket()->setBlock(true);
} }
} }
*/
} }
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__);

View File

@@ -844,6 +844,7 @@ void Socket::disconnectSocket() {
::closesocket(sock); ::closesocket(sock);
sock = -1; sock = -1;
#endif #endif
safeMutex.ReleaseLock();
} }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
@@ -893,7 +894,7 @@ bool Socket::hasDataToRead(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList)
{ {
bResult = true; 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<PLATFORM_SOCKET,bool>::iterator itermap = socketTriggeredList.begin(); for(std::map<PLATFORM_SOCKET,bool>::iterator itermap = socketTriggeredList.begin();
itermap != socketTriggeredList.end(); itermap++) itermap != socketTriggeredList.end(); itermap++)
@@ -901,7 +902,7 @@ bool Socket::hasDataToRead(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList)
PLATFORM_SOCKET socket = itermap->first; PLATFORM_SOCKET socket = itermap->first;
if (FD_ISSET(socket, &rfds)) 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; itermap->second = true;
} }
@@ -911,7 +912,7 @@ bool Socket::hasDataToRead(std::map<PLATFORM_SOCKET,bool> &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 #else
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT); bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
#endif #endif
safeMutex.ReleaseLock();
//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__);
} }
@@ -1072,13 +1074,13 @@ int Socket::send(const void *data, int dataSize) {
#else #else
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT); bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
#endif #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) { if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
break; 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 { else {
int iErr = getLastSocketError(); int iErr = getLastSocketError();
@@ -1114,16 +1116,17 @@ int Socket::send(const void *data, int dataSize) {
#else #else
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, MSG_NOSIGNAL | MSG_DONTWAIT); bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, MSG_NOSIGNAL | MSG_DONTWAIT);
#endif #endif
safeMutex.ReleaseLock();
if(bytesSent > 0) { if(bytesSent > 0) {
totalBytesSent += bytesSent; 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) { if(bytesSent < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
break; break;
} }
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
} }
else { else {
int iErr = getLastSocketError(); int iErr = getLastSocketError();
@@ -1168,6 +1171,7 @@ int Socket::receive(void *data, int dataSize) {
if(isSocketValid() == true) { if(isSocketValid() == true) {
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0); bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
safeMutex.ReleaseLock();
} }
if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { 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()); 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()); //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<char*>(data), dataSize, MSG_PEEK); err = recv(sock, reinterpret_cast<char*>(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()); //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__)); MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
i= select((int)sock + 1, &set, NULL, NULL, &tv); i= select((int)sock + 1, &set, NULL, NULL, &tv);
safeMutex.ReleaseLock();
} }
if(i < 0) { if(i < 0) {
//if(difftime(time(NULL),lastDebugEvent) >= 1) { //if(difftime(time(NULL),lastDebugEvent) >= 1) {
@@ -1359,6 +1365,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
{ {
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
i = select((int)sock + 1, NULL, &set, NULL, &tv); i = select((int)sock + 1, NULL, &set, NULL, &tv);
safeMutex.ReleaseLock();
} }
if(i < 0 ) { if(i < 0 ) {
//if(difftime(time(NULL),lastDebugEvent) >= 1) { //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__)); MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
err = select((int)sock + 1, NULL, &myset, NULL, &tv); err = select((int)sock + 1, NULL, &myset, NULL, &tv);
safeMutex.ReleaseLock();
} }
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) { if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {