diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 05b95156..637d0f28 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1744,10 +1744,12 @@ void Game::render2d(){ 10, metrics.getVirtualH() - mh - 90 - 210 - (i * 16), false); } - if(renderer.getAllowRenderUnitTitles() == false) { - renderer.setAllowRenderUnitTitles(true); + if((renderer.getShowDebugUILevel() & debugui_unit_titles) == debugui_unit_titles) { + if(renderer.getAllowRenderUnitTitles() == false) { + renderer.setAllowRenderUnitTitles(true); + } + renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f)); } - renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f)); } //network status diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 17280f56..188be574 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -150,6 +150,7 @@ Renderer::Renderer() { this->menu = NULL; this->game = NULL; showDebugUI = false; + showDebugUILevel = debugui_fps; modelRenderer = NULL; textRenderer = NULL; particleRenderer = NULL; @@ -2439,7 +2440,9 @@ void Renderer::renderSelectionEffects() { //selection circle if(world->getThisFactionIndex() == unit->getFactionIndex()) { - if( showDebugUI == true && unit->getCommandSize() > 0 && + if( showDebugUI == true && + ((showDebugUILevel & debugui_unit_titles) == debugui_unit_titles) && + unit->getCommandSize() > 0 && dynamic_cast(unit->getCurrCommand()->getCommandType()) != NULL) { glColor4f(unit->getHpRatio(), unit->getHpRatio(), unit->getHpRatio(), 0.3f); } @@ -4744,5 +4747,15 @@ Texture2D * Renderer::findFactionLogoTexture(string logoFilename) { return result; } +void Renderer::cycleShowDebugUILevel() { + if((showDebugUILevel & debugui_fps) != debugui_fps || + (showDebugUILevel & debugui_unit_titles) != debugui_unit_titles) { + showDebugUILevel |= debugui_fps; + showDebugUILevel |= debugui_unit_titles; + } + else { + showDebugUILevel = debugui_fps; + } +} }}//end namespace diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 1bf7d2af..be309270 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -42,6 +42,11 @@ #include "leak_dumper.h" +enum DebugUILevelType { + debugui_fps = 0x01, + debugui_unit_titles = 0x02 +}; + namespace Glest{ namespace Game{ using namespace Shared::Graphics; @@ -246,6 +251,7 @@ private: bool no2DMouseRendering; bool showDebugUI; + int showDebugUILevel; int lastRenderFps; float smoothedRenderFps; @@ -412,6 +418,10 @@ public: bool getShowDebugUI() const { return showDebugUI; } void setShowDebugUI(bool value) { showDebugUI = value; } + int getShowDebugUILevel() const { return showDebugUILevel; } + void setShowDebugUILevel(int value) { showDebugUILevel=value; } + void cycleShowDebugUILevel(); + void setLastRenderFps(int value); int getLastRenderFps() const { return lastRenderFps;} diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index c0fefebe..9a2e273c 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -664,9 +664,15 @@ void MainWindow::eventKeyDown(char key){ Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); if(key == configKeys.getCharKey("HotKeyShowDebug")) { + Renderer &renderer= Renderer::getInstance(); - bool showDebugUI = renderer.getShowDebugUI(); - renderer.setShowDebugUI(!showDebugUI); + if(keystate.mod & (KMOD_LCTRL | KMOD_RCTRL)) { + renderer.cycleShowDebugUILevel(); + } + else { + bool showDebugUI = renderer.getShowDebugUI(); + renderer.setShowDebugUI(!showDebugUI); + } } else if(key == configKeys.getCharKey("ReloadINI")) { Config &config = Config::getInstance(); @@ -1579,6 +1585,7 @@ int glestMain(int argc, char** argv) { return -1; } + //setVBOSupported(false); // Explicitly disable VBO's if(config.getBool("DisableVBO","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_DISABLE_VBO]) == true) { setVBOSupported(false); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 5a6ff068..a37a84c9 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -513,7 +513,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b GraphicComponent::applyAllCustomProperties(containerName); - publishToMasterserverThread = new SimpleTaskThread(this,0,25); + publishToMasterserverThread = new SimpleTaskThread(this,0,200); publishToMasterserverThread->setUniqueID(__FILE__); publishToMasterserverThread->start(); diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index ace659e2..bcc8f790 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -298,9 +298,13 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { if(serverInterface->getServerSocket() != NULL && serverInterface->getServerSocket()->hasDataToRead() == true) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] about to accept new client connection playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); - socket = serverInterface->getServerSocket()->accept(); + 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); - if(socket != NULL) { + if(newSocket != NULL) { + // Set Socket as non-blocking + newSocket->setBlock(false); + socket = newSocket; + this->connectedTime = time(NULL); this->clearChatInfo(); this->name = ""; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 6944900d..c8e29b32 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -330,6 +330,8 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) { bool checkForNewClients = true; // Safety check since we can experience a disconnect and the slot is NULL + //Chrono chrono; + //chrono.start(); ConnectionSlot *connectionSlot = NULL; MutexSafeWrapper safeMutexSlot(NULL); if(event->triggerId >= 0 && event->triggerId < GameConstants::maxPlayers) { @@ -341,17 +343,29 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",__FILE__,__FUNCTION__,__LINE__,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()); + if(connectionSlot != NULL && (gameHasBeenInitiated == false || (connectionSlot->getSocket() != NULL && socketTriggered == true))) { 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); connectionSlot->update(checkForNewClients,event->triggerId); + //chrono.start(); + 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()); + // This means no clients are trying to connect at the moment if(connectionSlot != NULL && connectionSlot->getSocket() == NULL) { checkForNewClients = false; } } + //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(); } diff --git a/source/shared_lib/include/platform/sdl/thread.h b/source/shared_lib/include/platform/sdl/thread.h index 7b9b4570..f7fa8a19 100644 --- a/source/shared_lib/include/platform/sdl/thread.h +++ b/source/shared_lib/include/platform/sdl/thread.h @@ -71,10 +71,11 @@ class Mutex { private: SDL_mutex* mutex; int refCount; - + string ownerId; public: - Mutex(); + Mutex(string ownerId=""); ~Mutex(); + void setOwnerId(string ownerId) { this->ownerId = ownerId; } void p(); void v(); int getRefCount() const { return refCount; } diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 3a794202..58ccd3ab 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -83,12 +83,18 @@ void Mesh::end() { ReleaseVBOs(); delete [] vertices; + vertices=NULL; delete [] normals; + normals=NULL; delete [] texCoords; + texCoords=NULL; delete [] tangents; + tangents=NULL; delete [] indices; + indices=NULL; delete interpolationData; + interpolationData=NULL; if(textureManager != NULL) { for(int i = 0; i < meshTextureCount; ++i) { @@ -109,11 +115,15 @@ void Mesh::buildInterpolationData(){ } void Mesh::updateInterpolationData(float t, bool cycle) { - interpolationData->update(t, cycle); + if(interpolationData != NULL) { + interpolationData->update(t, cycle); + } } void Mesh::updateInterpolationVertices(float t, bool cycle) { - interpolationData->updateVertices(t, cycle); + if(interpolationData != NULL) { + interpolationData->updateVertices(t, cycle); + } } void Mesh::BuildVBOs() { @@ -155,6 +165,9 @@ void Mesh::BuildVBOs() { delete [] normals; normals = NULL; delete [] indices; indices = NULL; + delete interpolationData; + interpolationData = NULL; + hasBuiltVBOs = true; } } @@ -167,6 +180,7 @@ void Mesh::ReleaseVBOs() { glDeleteBuffersARB( 1, &m_nVBOTexCoords ); // Get A Valid Name glDeleteBuffersARB( 1, &m_nVBONormals ); // Get A Valid Name glDeleteBuffersARB( 1, &m_nVBOIndexes ); // Get A Valid Name + hasBuiltVBOs = false; } } } diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 7f1ad5a3..54a7cdee 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1072,6 +1072,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] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent); @@ -1113,6 +1114,8 @@ 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; } @@ -1186,6 +1189,7 @@ int Socket::receive(void *data, int dataSize) { else if(Socket::isReadable() == true) { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); bytesReceived = recv(sock, reinterpret_cast(data), dataSize, 0); + safeMutex.ReleaseLock(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived); } @@ -1207,7 +1211,7 @@ int Socket::peek(void *data, int dataSize) { ssize_t err = 0; if(isSocketValid() == true) { - MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); + MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize)); err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); } if(err < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) { @@ -1217,7 +1221,7 @@ int Socket::peek(void *data, int dataSize) { disconnectSocket(); } else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 ERROR EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__); time_t tStartTimer = time(NULL); while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) && @@ -1232,6 +1236,7 @@ int Socket::peek(void *data, int dataSize) { else if(Socket::isReadable() == true) { MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); err = recv(sock, reinterpret_cast(data), dataSize, MSG_PEEK); + safeMutex.ReleaseLock(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err); } diff --git a/source/shared_lib/sources/platform/sdl/thread.cpp b/source/shared_lib/sources/platform/sdl/thread.cpp index 80396a58..7c3c57d8 100644 --- a/source/shared_lib/sources/platform/sdl/thread.cpp +++ b/source/shared_lib/sources/platform/sdl/thread.cpp @@ -77,8 +77,9 @@ void Thread::resume() { // Mutex // ===================================== -Mutex::Mutex() { +Mutex::Mutex(string ownerId) { refCount=0; + this->ownerId = ownerId; mutex = SDL_CreateMutex(); assert(mutex != NULL); if(mutex == NULL) { @@ -91,9 +92,15 @@ Mutex::Mutex() { Mutex::~Mutex() { if(mutex == NULL) { char szBuf[1024]=""; - snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__); + snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str()); throw runtime_error(szBuf); } + else if(refCount >= 1) { + char szBuf[1024]=""; + snprintf(szBuf,1023,"In [%s::%s Line: %d] about to destroy mutex refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str()); + throw runtime_error(szBuf); + } + SDL_DestroyMutex(mutex); mutex=NULL; } @@ -101,7 +108,7 @@ Mutex::~Mutex() { void Mutex::p() { if(mutex == NULL) { char szBuf[1024]=""; - snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__); + snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str()); throw runtime_error(szBuf); } SDL_mutexP(mutex); @@ -111,7 +118,7 @@ void Mutex::p() { void Mutex::v() { if(mutex == NULL) { char szBuf[1024]=""; - snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__); + snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str()); throw runtime_error(szBuf); } refCount--;