- attempt to fix masterserver losing publish setting and/or open network slot

- attempt to fix high cpu usage on masterserver (and clients) when waiting for others during the start of a network game
This commit is contained in:
Mark Vejvoda 2011-11-14 05:18:09 +00:00
parent 252080b3b0
commit 8050e25538
3 changed files with 41 additions and 7 deletions

View File

@ -375,7 +375,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
listBoxPublishServer.init(50, networkPos, 100);
listBoxPublishServer.pushBackItem(lang.get("Yes"));
listBoxPublishServer.pushBackItem(lang.get("No"));
if(openNetworkSlots && parentMenuState!=pLanGame) {
if(this->masterserverMode == true ||
(openNetworkSlots == true && parentMenuState != pLanGame)) {
listBoxPublishServer.setSelectedItemIndex(0);
}
else {
@ -1999,7 +2000,9 @@ void MenuStateCustomGame::update() {
mainMessageBoxState=1;
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
listBoxPublishServer.setSelectedItemIndex(1);
if(this->masterserverMode == false) {
listBoxPublishServer.setSelectedItemIndex(1);
}
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setPublishEnabled(listBoxPublishServer.getSelectedItemIndex() == 0);
@ -2153,7 +2156,8 @@ void MenuStateCustomGame::update() {
}
}
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork ||
listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
hasOneNetworkSlotOpen=true;
if(serverInterface->getSlot(i) != NULL &&
@ -2353,13 +2357,26 @@ void MenuStateCustomGame::update() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
if(hasOneNetworkSlotOpen) {
//listBoxPublishServer.setSelectedItemIndex(0);
if(this->masterserverMode == true || hasOneNetworkSlotOpen == true) {
if(this->masterserverMode == true) {
listBoxPublishServer.setSelectedItemIndex(0);
}
listBoxPublishServer.setEditable(true);
//listBoxEnableServerControlledAI.setEditable(true);
// Masterserver always needs one network slot
if(this->masterserverMode == true && hasOneNetworkSlotOpen == false) {
for(int i= 0; i < mapInfo.players; ++i) {
if(listBoxControls[i].getSelectedItemIndex() != ctNetwork &&
listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) {
listBoxControls[i].setSelectedItemIndex(ctNetwork);
}
}
updateNetworkSlots();
}
}
else
{
else {
listBoxPublishServer.setSelectedItemIndex(1);
listBoxPublishServer.setEditable(false);

View File

@ -694,11 +694,21 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
Lang &lang= Lang::getInstance();
int64 lastMillisCheck = 0;
uint64 waitLoopIterationCount = 0;
const uint64 MAX_LOOP_COUNT_BEFORE_SLEEP = 300;
//wait until we get a ready message from the server
while(true) {
// FOR TESTING ONLY - delay to see the client count up while waiting
//sleep(2000);
waitLoopIterationCount++;
if(waitLoopIterationCount > 0 && waitLoopIterationCount % MAX_LOOP_COUNT_BEFORE_SLEEP == 0) {
sleep(1);
waitLoopIterationCount = 0;
}
if(isConnected() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -1175,7 +1175,14 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
}
Lang &lang= Lang::getInstance();
uint64 waitLoopIterationCount = 0;
const uint64 MAX_LOOP_COUNT_BEFORE_SLEEP = 300;
while(exitServer == false && allReady == false && logger.getCancelLoading() == false) {
waitLoopIterationCount++;
if(waitLoopIterationCount > 0 && waitLoopIterationCount % MAX_LOOP_COUNT_BEFORE_SLEEP == 0) {
sleep(1);
waitLoopIterationCount = 0;
}
vector<string> waitingForHosts;
allReady= true;
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {