diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index bcc8f790..378fbef2 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -278,6 +278,8 @@ ConnectionSlot::~ConnectionSlot() { } void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { + //Chrono chrono; + //chrono.start(); try { clearThreadErrorList(); @@ -285,6 +287,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { slotThreadWorker->purgeCompletedEvents(); } + //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(socket == NULL) { if(networkGameDataSynchCheckOkMap) networkGameDataSynchCheckOkMap = false; if(networkGameDataSynchCheckOkTile) networkGameDataSynchCheckOkTile = false; @@ -293,10 +297,22 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { // Is the listener socket ready to be read? if(checkForNewClients == true) { + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] BEFORE accept new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getOpenSlotCount()); bool hasOpenSlots = (serverInterface->getOpenSlotCount() > 0); - if(serverInterface->getServerSocket() != NULL && - serverInterface->getServerSocket()->hasDataToRead() == true) { + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + + bool hasData = (serverInterface->getServerSocket() != NULL && serverInterface->getServerSocket()->hasDataToRead() == true); + + //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(hasData == true) { + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] about to accept new client connection playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); Socket *newSocket = serverInterface->getServerSocket()->accept(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] called accept new client connection playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); @@ -305,6 +321,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { newSocket->setBlock(false); socket = newSocket; + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + this->connectedTime = time(NULL); this->clearChatInfo(); this->name = ""; @@ -313,10 +331,14 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { this->receivedNetworkGameStatus = false; this->gotIntro = false; + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__)); this->vctPendingNetworkCommandList.clear(); safeMutexSlot.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()); + this->currentFrameCount = 0; this->currentLagCount = 0; this->lastReceiveCommandListTime = 0; @@ -329,11 +351,18 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { // this->slotThreadWorker->start(); //} + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); serverInterface->updateListen(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); + + //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()); } + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + //send intro message when connected if(socket != NULL) { RandomGen random; @@ -348,6 +377,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { sendMessage(&networkMessageIntro); } + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + close(); } else { @@ -356,15 +387,23 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(socket != NULL) { NetworkMessageIntro networkMessageIntro(sessionKey,getNetworkVersionString(), getHostName(), playerIndex, nmgstOk, 0, ServerSocket::getFTPServerPort()); sendMessage(&networkMessageIntro); + + //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()); } else { + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(socket != NULL && socket->isConnected()) { + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + this->clearChatInfo(); bool gotTextMsg = true; @@ -724,12 +763,18 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } } + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + validateConnection(); + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__); close(); + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -740,7 +785,11 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); threadErrorList.push_back(ex.what()); + + //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()); } void ConnectionSlot::validateConnection() { diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index c8e29b32..eb0c33c9 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -351,11 +351,11 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) { if(connectionSlot->isConnected() == false || socketTriggered == true) { //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); - safeMutexSlot.ReleaseLock(true); + //safeMutexSlot.ReleaseLock(true); connectionSlot->update(checkForNewClients,event->triggerId); //chrono.start(); - safeMutexSlot.Lock(); + //safeMutexSlot.Lock(); connectionSlot = slots[event->triggerId]; //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 3b6ad639..c0beb956 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -141,7 +141,7 @@ public: int getDataToRead(bool wantImmediateReply=false); int send(const void *data, int dataSize); int receive(void *data, int dataSize); - int peek(void *data, int dataSize); + int peek(void *data, int dataSize, bool mustGetData=true); void setBlock(bool block); static void setBlock(bool block, PLATFORM_SOCKET socket); diff --git a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp index 6e638f15..27b0f74a 100644 --- a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp @@ -143,7 +143,7 @@ void ModelRendererGl::renderMesh(Mesh *mesh) { } else{ glEnable(GL_CULL_FACE); - glPolygonOffset(0.05, 0); + glPolygonOffset(0.05f, 0.0f); } //set color diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 54a7cdee..495d9cd7 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1206,23 +1206,41 @@ int Socket::receive(void *data, int dataSize) { return static_cast(bytesReceived); } -int Socket::peek(void *data, int dataSize) { +int Socket::peek(void *data, int dataSize,bool mustGetData) { + //Chrono chrono; + //chrono.start(); + const int MAX_PEEK_WAIT_SECONDS = 3; ssize_t err = 0; if(isSocketValid() == true) { + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize)); + + //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); + + //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()); + if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR PEEKING SOCKET DATA error while sending socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str()); //throwException(szBuf); + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + disconnectSocket(); + + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); } - else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { + else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN && mustGetData == true) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 ERROR EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__); + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + time_t tStartTimer = time(NULL); while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && (difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) { @@ -1241,16 +1259,27 @@ int Socket::peek(void *data, int dataSize) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err); } } + + //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()); + if(err <= 0) { - int iErr = getLastSocketError(); - disconnectSocket(); + if(mustGetData == true || getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { + int iErr = getLastSocketError(); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str()); - //throwException(szBuf); + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + + disconnectSocket(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str()); + //throwException(szBuf); + } } + //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); + return static_cast(err); } @@ -1369,12 +1398,11 @@ bool Socket::isConnected() { if(isWritable(false) == false) { return false; } - //if the socket is readable it is connected if we can read a byte from it if(isReadable()) { char tmp; - int err = peek(&tmp, 1); - if(err <= 0) { + int err = peek(&tmp, 1, false); + if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) { return false; } } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index a6ffb537..bb3ff68b 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -18,6 +18,7 @@ #include "sdl_private.h" #include "noimpl.h" #include "util.h" +#include "opengl.h" #ifdef WIN32 @@ -381,6 +382,13 @@ void Window::setupGraphicsScreen(int depthBits, int stencilBits, bool hardware_a SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, newStencilBits); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, newDepthBits); + + // setup LOD bias factor + //const float lodBias = std::max(std::min( configHandler->Get("TextureLODBias", 0.0f) , 4.0f), -4.0f); + const float lodBias = std::max(std::min( 0.0f , 4.0f), -4.0f); + if (fabs(lodBias)>0.01f) { + glTexEnvf(GL_TEXTURE_FILTER_CONTROL,GL_TEXTURE_LOD_BIAS, lodBias ); + } } #ifdef WIN32