mirror of
https://github.com/glest/glest-source.git
synced 2025-08-22 16:02:50 +02:00
updated custom menu with more mutex protection
This commit is contained in:
@@ -284,8 +284,11 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
MenuStateCustomGame::~MenuStateCustomGame() {
|
MenuStateCustomGame::~MenuStateCustomGame() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -298,20 +301,20 @@ MenuStateCustomGame::~MenuStateCustomGame() {
|
|||||||
|
|
||||||
|
|
||||||
void MenuStateCustomGame::returnToParentMenu(){
|
void MenuStateCustomGame::returnToParentMenu(){
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
if(parentMenuIsMs)
|
if(parentMenuIsMs) {
|
||||||
{
|
|
||||||
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
|
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
|
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
|
|
||||||
CoreData &coreData= CoreData::getInstance();
|
CoreData &coreData= CoreData::getInstance();
|
||||||
@@ -382,8 +385,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
|
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
lastMasterserverPublishing = 0;
|
lastMasterserverPublishing = 0;
|
||||||
publishToMasterserver();
|
//publishToMasterserver();
|
||||||
simpleTask();
|
//simpleTask();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
@@ -599,6 +602,7 @@ void MenuStateCustomGame::render(){
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
int i;
|
int i;
|
||||||
renderer.renderButton(&buttonReturn);
|
renderer.renderButton(&buttonReturn);
|
||||||
renderer.renderButton(&buttonPlayNow);
|
renderer.renderButton(&buttonPlayNow);
|
||||||
@@ -661,8 +665,12 @@ void MenuStateCustomGame::update()
|
|||||||
int currentConnectionCount=0;
|
int currentConnectionCount=0;
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
|
|
||||||
if(showMasterserverError)
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
|
bool masterServerErr = showMasterserverError;
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
if(masterServerErr)
|
||||||
{
|
{
|
||||||
|
safeMutex.Lock();
|
||||||
if(EndsWith(masterServererErrorToShow, "wrong router setup") == true)
|
if(EndsWith(masterServererErrorToShow, "wrong router setup") == true)
|
||||||
{
|
{
|
||||||
masterServererErrorToShow=lang.get("wrong router setup");
|
masterServererErrorToShow=lang.get("wrong router setup");
|
||||||
@@ -671,12 +679,14 @@ void MenuStateCustomGame::update()
|
|||||||
listBoxPublishServer.setSelectedItemIndex(1);
|
listBoxPublishServer.setSelectedItemIndex(1);
|
||||||
mainMessageBoxState=1;
|
mainMessageBoxState=1;
|
||||||
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// handle setting changes from clients
|
// handle setting changes from clients
|
||||||
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
||||||
|
safeMutex.Lock();
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
{
|
{
|
||||||
if(switchSetupRequests[i]!=NULL)
|
if(switchSetupRequests[i]!=NULL)
|
||||||
@@ -726,9 +736,11 @@ void MenuStateCustomGame::update()
|
|||||||
switchSetupRequests[i]=NULL;
|
switchSetupRequests[i]=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -830,52 +842,78 @@ void MenuStateCustomGame::update()
|
|||||||
labelNetStatus[i].setText("");
|
labelNetStatus[i].setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
|
bool checkDataSynch = (serverInterface->getAllowGameDataSynchCheck() == true &&
|
||||||
|
//haveAtLeastOneNetworkClientConnected == true &&
|
||||||
|
needToSetChangedGameSettings == true &&
|
||||||
|
difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
// Send the game settings to each client if we have at least one networked client
|
// Send the game settings to each client if we have at least one networked client
|
||||||
if( serverInterface->getAllowGameDataSynchCheck() == true &&
|
if(checkDataSynch == true)
|
||||||
//haveAtLeastOneNetworkClientConnected == true &&
|
|
||||||
needToSetChangedGameSettings == true &&
|
|
||||||
difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
|
||||||
{
|
{
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
loadGameSettings(&gameSettings);
|
loadGameSettings(&gameSettings);
|
||||||
serverInterface->setGameSettings(&gameSettings);
|
serverInterface->setGameSettings(&gameSettings);
|
||||||
|
|
||||||
|
safeMutex.Lock();
|
||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(hasOneNetworkSlotOpen)
|
if(hasOneNetworkSlotOpen)
|
||||||
{
|
{
|
||||||
|
safeMutex.Lock();
|
||||||
//listBoxPublishServer.setSelectedItemIndex(0);
|
//listBoxPublishServer.setSelectedItemIndex(0);
|
||||||
listBoxPublishServer.setEditable(true);
|
listBoxPublishServer.setEditable(true);
|
||||||
listBoxEnableServerControlledAI.setEditable(true);
|
listBoxEnableServerControlledAI.setEditable(true);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
safeMutex.Lock();
|
||||||
listBoxPublishServer.setSelectedItemIndex(1);
|
listBoxPublishServer.setSelectedItemIndex(1);
|
||||||
listBoxPublishServer.setEditable(false);
|
listBoxPublishServer.setEditable(false);
|
||||||
listBoxEnableServerControlledAI.setEditable(false);
|
listBoxEnableServerControlledAI.setEditable(false);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(difftime(time(NULL),lastMasterserverPublishing) >= 5 ){
|
safeMutex.Lock();
|
||||||
|
bool republishToMaster = (difftime(time(NULL),lastMasterserverPublishing) >= 5);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
|
if(republishToMaster == true) {
|
||||||
|
safeMutex.Lock();
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
lastMasterserverPublishing = time(NULL);
|
lastMasterserverPublishing = time(NULL);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(listBoxPublishServer.getEditable() &&
|
safeMutex.Lock();
|
||||||
listBoxPublishServer.getSelectedItemIndex() == 0 &&
|
bool callPublishNow = (listBoxPublishServer.getEditable() &&
|
||||||
needToRepublishToMasterserver == true) {
|
listBoxPublishServer.getSelectedItemIndex() == 0 &&
|
||||||
|
needToRepublishToMasterserver == true);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
|
if(callPublishNow == true) {
|
||||||
// give it to me baby, aha aha ...
|
// give it to me baby, aha aha ...
|
||||||
publishToMasterserver();
|
publishToMasterserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
safeMutex.Lock();
|
||||||
{
|
bool broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
|
if(broadCastSettings == true) {
|
||||||
|
safeMutex.Lock();
|
||||||
needToBroadcastServerSettings=true;
|
needToBroadcastServerSettings=true;
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//call the chat manager
|
//call the chat manager
|
||||||
@@ -884,17 +922,25 @@ void MenuStateCustomGame::update()
|
|||||||
//console
|
//console
|
||||||
console.update();
|
console.update();
|
||||||
|
|
||||||
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
safeMutex.Lock();
|
||||||
|
broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
|
|
||||||
|
if(broadCastSettings == true)
|
||||||
{// reset timer here on bottom becasue used for different things
|
{// reset timer here on bottom becasue used for different things
|
||||||
|
safeMutex.Lock();
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(currentConnectionCount>soundConnectionCount){
|
safeMutex.Lock();
|
||||||
soundConnectionCount=currentConnectionCount;
|
if(currentConnectionCount > soundConnectionCount){
|
||||||
|
soundConnectionCount = currentConnectionCount;
|
||||||
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
||||||
}
|
}
|
||||||
soundConnectionCount=currentConnectionCount;
|
soundConnectionCount = currentConnectionCount;
|
||||||
|
safeMutex.ReleaseLock(false);
|
||||||
}
|
}
|
||||||
catch(const std::exception &ex) {
|
catch(const std::exception &ex) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
@@ -913,10 +959,9 @@ void MenuStateCustomGame::publishToMasterserver()
|
|||||||
loadGameSettings(&gameSettings);
|
loadGameSettings(&gameSettings);
|
||||||
string serverinfo="";
|
string serverinfo="";
|
||||||
|
|
||||||
for(int i= 0; i < mapInfo.players; ++i)
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
{
|
for(int i= 0; i < mapInfo.players; ++i) {
|
||||||
if(listBoxControls[i].getSelectedItemIndex() != ctClosed)
|
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
||||||
{
|
|
||||||
slotCountUsed++;
|
slotCountUsed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1233,8 +1278,6 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
//!!!
|
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ERROR = [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ERROR = [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
Reference in New Issue
Block a user