From a5aba5cc66bfe6be90e2063750d22d522b40bafb Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 12 Apr 2010 21:40:57 +0000 Subject: [PATCH] Bugfix for tracker#: 2985599 - Added better management of UDP broadcast thread when user toggles on/off network slots. --- .../menu/menu_state_custom_game.cpp | 11 ++++++++++ .../include/platform/posix/socket.h | 1 + .../sources/platform/posix/socket.cpp | 21 +++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 64e49ff7..f9af4946 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -208,32 +208,42 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); if(buttonReturn.mouseClick(x,y)){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + soundRenderer.playFx(coreData.getClickSoundA()); mainMenu->setState(new MenuStateNewGame(program, mainMenu)); } else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); closeUnusedSlots(); soundRenderer.playFx(coreData.getClickSoundC()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + GameSettings gameSettings; loadGameSettings(&gameSettings); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + // Send the game settings to each client if we have at least one networked client if( hasNetworkGameSettings() == true && needToSetChangedGameSettings == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); serverInterface->setGameSettings(&gameSettings,true); needToSetChangedGameSettings = false; lastSetChangedGameSettings = time(NULL); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); bool bOkToStart = serverInterface->launchGame(&gameSettings); if(bOkToStart == true) { program->setState(new Game(program, &gameSettings)); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } else if(listBoxMap.mouseClick(x, y)){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", mapFiles[listBoxMap.getSelectedItemIndex()].c_str()); @@ -329,6 +339,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){ diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 970459bd..3dab6f68 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -181,6 +181,7 @@ protected: BroadCastSocketThread *broadCastThread; void startBroadCastThread(); + bool isBroadCastThreadRunning(); }; diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 9cbd0cd6..b7dfaaf7 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1250,7 +1250,7 @@ void ServerSocket::stopBroadCastThread() { break; } sleep(100); - 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__); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1272,6 +1272,16 @@ void ServerSocket::startBroadCastThread() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +bool ServerSocket::isBroadCastThreadRunning() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + bool isThreadRunning = (broadCastThread != NULL && broadCastThread->getRunningStatus() == true); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] isThreadRunning = %d\n",__FILE__,__FUNCTION__,__LINE__,isThreadRunning); + + return isThreadRunning; +} + void ServerSocket::bind(int port) { //sockaddr structure @@ -1302,7 +1312,14 @@ void ServerSocket::listen(int connectionQueueSize) throwException(szBuf); } - startBroadCastThread(); + if(connectionQueueSize > 0) { + if(isBroadCastThreadRunning() == false) { + startBroadCastThread(); + } + } + else { + stopBroadCastThread(); + } }