From af87e53bbe1df7c7b59df1046b6b0522c6bd34ba Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 11 Apr 2010 01:25:06 +0000 Subject: [PATCH] Bugfix for trace bug#: 2984991 falling back to english text for scenarios text. - Also added more error checking and commented out some excessive debug output statements. --- source/glest_game/game/chat_manager.cpp | 103 +++-- source/glest_game/game/console.cpp | 76 ++++ source/glest_game/game/console.h | 68 ++++ source/glest_game/global/core_data.cpp | 10 + source/glest_game/global/lang.cpp | 18 +- source/glest_game/gui/display.cpp | 15 + source/glest_game/gui/display.h | 2 +- source/glest_game/gui/gui.cpp | 2 +- source/glest_game/main/main.cpp | 2 + source/glest_game/main/program.cpp | 12 +- .../menu/menu_state_custom_game.cpp | 382 ++++++++++-------- .../glest_game/menu/menu_state_join_game.cpp | 4 + .../glest_game/network/server_interface.cpp | 33 +- .../sources/platform/posix/socket.cpp | 3 +- .../sources/platform/sdl/gl_wrap.cpp | 17 +- .../sources/platform/sdl/window.cpp | 8 + .../sound/openal/sound_player_openal.cpp | 6 +- 17 files changed, 522 insertions(+), 239 deletions(-) create mode 100644 source/glest_game/game/console.cpp create mode 100644 source/glest_game/game/console.h diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index a1bb8676e..7ebba0813 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -17,8 +17,10 @@ #include "network_manager.h" #include "lang.h" #include "util.h" +#include #include "leak_dumper.h" +using namespace std; using namespace Shared::Platform; using namespace Shared::Util; @@ -43,42 +45,52 @@ void ChatManager::init(Console* console, int thisTeamIndex){ } void ChatManager::keyDown(char key){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Lang &lang= Lang::getInstance(); + try { + Lang &lang= Lang::getInstance(); - //toggle team mode - if(!editEnabled && key=='H'){ - if(teamMode){ - teamMode= false; - console->addLine(lang.get("ChatMode") + ": " + lang.get("All")); - } - else{ - teamMode= true; - console->addLine(lang.get("ChatMode") + ": " + lang.get("Team")); - } - } - - if(key==vkReturn){ - if(editEnabled){ - GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); - - editEnabled= false; - if(!text.empty()) { - console->addLine(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": " + text); - gameNetworkInterface->sendTextMessage(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": "+ - text, teamMode? thisTeamIndex: -1); + //toggle team mode + if(!editEnabled && key=='H'){ + if(teamMode){ + teamMode= false; + console->addLine(lang.get("ChatMode") + ": " + lang.get("All")); + } + else{ + teamMode= true; + console->addLine(lang.get("ChatMode") + ": " + lang.get("Team")); } } - else{ - editEnabled= true; - text.clear(); + + if(key==vkReturn){ + if(editEnabled){ + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + + editEnabled= false; + if(!text.empty()) { + console->addLine(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": " + text); + gameNetworkInterface->sendTextMessage(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": "+ + text, teamMode? thisTeamIndex: -1); + } + } + else{ + editEnabled= true; + text.clear(); + } + } + else if(key==vkBack){ + if(!text.empty()){ + text.erase(text.end() -1); + } } } - else if(key==vkBack){ - if(!text.empty()){ - text.erase(text.end() -1); - } + catch(const exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void ChatManager::keyPress(char c){ @@ -92,23 +104,32 @@ void ChatManager::keyPress(char c){ void ChatManager::updateNetwork() { - GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); - string text; - string sender; - Config &config= Config::getInstance(); + try { + GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); + string text; + string sender; + Config &config= Config::getInstance(); - if(!gameNetworkInterface->getChatText().empty()) - { - int teamIndex= gameNetworkInterface->getChatTeamIndex(); + if(!gameNetworkInterface->getChatText().empty()) + { + int teamIndex= gameNetworkInterface->getChatTeamIndex(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex); - if(teamIndex==-1 || teamIndex==thisTeamIndex){ - console->addLine(gameNetworkInterface->getChatText(), true); + if(teamIndex==-1 || teamIndex==thisTeamIndex){ + console->addLine(gameNetworkInterface->getChatText(), true); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__); + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); + } } }}//end namespace diff --git a/source/glest_game/game/console.cpp b/source/glest_game/game/console.cpp new file mode 100644 index 000000000..395035c61 --- /dev/null +++ b/source/glest_game/game/console.cpp @@ -0,0 +1,76 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "console.h" + +#include "lang.h" +#include "config.h" +#include "program.h" +#include "game_constants.h" +#include "sound_renderer.h" +#include "core_data.h" +#include +#include "leak_dumper.h" + +using namespace std; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class Console +// ===================================================== + +Console::Console(){ + //config + maxLines= Config::getInstance().getInt("ConsoleMaxLines"); + timeout= Config::getInstance().getInt("ConsoleTimeout"); + + timeElapsed= 0.0f; +} + +void Console::addStdMessage(const string &s){ + addLine(Lang::getInstance().get(s)); +} + +void Console::addLine(string line, bool playSound){ + try + { + if(playSound){ + SoundRenderer::getInstance().playFx(CoreData::getInstance().getClickSoundA()); + } + lines.insert(lines.begin(), StringTimePair(line, timeElapsed)); + if(lines.size()>maxLines){ + lines.pop_back(); + } + } + catch(const exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); + } +} + +void Console::update(){ + timeElapsed+= 1.f/GameConstants::updateFps; + + if(!lines.empty()){ + if(lines.back().second +#include +#include +#include + +using std::string; +using std::vector; +using std::pair; +using namespace std; + +namespace Glest{ namespace Game{ + +// ===================================================== +// class Console +// +// In-game console that shows various types of messages +// ===================================================== + +class Console{ +private: + static const int consoleLines= 5; + +public: + typedef pair StringTimePair; + typedef vector Lines; + typedef Lines::const_iterator LineIterator; + +private: + float timeElapsed; + Lines lines; + + //this should be deleted from here someday + bool won, lost; + + //config + int maxLines; + float timeout; + +public: + Console(); + + int getLineCount() const {return lines.size();} + string getLine(int i) const { if(i < 0 || i >= lines.size()) throw runtime_error("i >= Lines.size()"); return lines[i].first;} + + + void addStdMessage(const string &s); + void addLine(string line, bool playSound= false); + void update(); + bool isEmpty(); +}; + +}}//end namespace + +#endif diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 1889c9d8e..a6f9454f4 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -89,6 +89,8 @@ void CoreData::load(){ displayFont->setType(displayFontName); displayFont->setSize(displayFontSize); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize); + //menu fonts string displayFontNameSmallPrefix= config.getString("FontDisplayPrefix"); string displayFontNameSmallPostfix= config.getString("FontDisplayPostfix"); @@ -98,6 +100,7 @@ void CoreData::load(){ displayFontSmall->setType(displayFontNameSmall); displayFontSmall->setSize(displayFontNameSmallSize); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize); string menuFontNameNormalPrefix= config.getString("FontMenuNormalPrefix"); string menuFontNameNormalPostfix= config.getString("FontMenuNormalPostfix"); @@ -108,6 +111,7 @@ void CoreData::load(){ menuFontNormal->setSize(menuFontNameNormalSize); menuFontNormal->setWidth(Font::wBold); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize); string menuFontNameBigPrefix= config.getString("FontMenuBigPrefix"); string menuFontNameBigPostfix= config.getString("FontMenuBigPostfix"); @@ -117,6 +121,8 @@ void CoreData::load(){ menuFontBig->setType(menuFontNameBig); menuFontBig->setSize(menuFontNameBigSize); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize); + string menuFontNameVeryBigPrefix= config.getString("FontMenuBigPrefix"); string menuFontNameVeryBigPostfix= config.getString("FontMenuBigPostfix"); int menuFontNameVeryBigSize=computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); @@ -125,6 +131,8 @@ void CoreData::load(){ menuFontVeryBig->setType(menuFontNameVeryBig); menuFontVeryBig->setSize(menuFontNameVeryBigSize); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); + //console font string consoleFontNamePrefix= config.getString("FontConsolePrefix"); string consoleFontNamePostfix= config.getString("FontConsolePostfix"); @@ -134,6 +142,8 @@ void CoreData::load(){ consoleFont->setType(consoleFontName); consoleFont->setSize(consoleFontNameSize); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize); + //sounds clickSoundA.load(dir+"/menu/sound/click_a.wav"); clickSoundB.load(dir+"/menu/sound/click_b.wav"); diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 3d24338ca..61b663ff0 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -40,11 +40,15 @@ void Lang::loadStrings(const string &language){ } void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenarioName){ - string path= scenarioDir + "/" + scenarioName + "/" + scenarioName + "_" + language + ".lng"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scenarioDir = [%s] scenarioName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioDir.c_str(),scenarioName.c_str()); + + string scenarioFolder = scenarioDir + "/" + scenarioName + "/"; + string path = scenarioFolder + scenarioName + "_" + language + ".lng"; if(EndsWith(scenarioDir, ".xml") == true) { - path= scenarioDir; - path = path.erase(path.size()-4,4); - path += "_" + language + ".lng"; + scenarioFolder = extractDirectoryPathFromFile(scenarioDir); + path = scenarioFolder + scenarioName + "_" + language + ".lng"; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); } scenarioStrings.clear(); @@ -57,7 +61,9 @@ void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenario SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); //try english otherwise - string path= scenarioDir + "/" +scenarioName + "/" + scenarioName + "_english.lng"; + path = scenarioFolder + scenarioName + "_english.lng"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); + if(fileExists(path)){ scenarioStrings.load(path); } diff --git a/source/glest_game/gui/display.cpp b/source/glest_game/gui/display.cpp index 3d2c8a0fe..e6c7fa500 100644 --- a/source/glest_game/gui/display.cpp +++ b/source/glest_game/gui/display.cpp @@ -13,9 +13,11 @@ #include "metrics.h" #include "command_type.h" +#include "util.h" #include "leak_dumper.h" using namespace Shared::Graphics; +using namespace Shared::Util; namespace Glest{ namespace Game{ @@ -24,6 +26,8 @@ namespace Glest{ namespace Game{ // ===================================================== Display::Display(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + colors[0]= Vec4f(1.f, 1.f, 1.f, 0.0f); colors[1]= Vec4f(1.f, 0.5f, 0.5f, 0.0f); colors[2]= Vec4f(0.5f, 0.5f, 1.0f, 0.0f); @@ -37,6 +41,17 @@ Display::Display(){ currentColor= 0; clear(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +Vec4f Display::getColor() const { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currentColor = %d\n",__FILE__,__FUNCTION__,__LINE__,currentColor); + if(currentColor < 0 || currentColor >= colorCount) { + throw runtime_error("currentColor >= colorCount"); + } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currentColor = %d\n",__FILE__,__FUNCTION__,__LINE__,currentColor); + return colors[currentColor]; } //misc diff --git a/source/glest_game/gui/display.h b/source/glest_game/gui/display.h index 857e38777..cc3599e65 100644 --- a/source/glest_game/gui/display.h +++ b/source/glest_game/gui/display.h @@ -71,7 +71,7 @@ public: bool getDownLighted(int index) const {return downLighted[index];} const CommandType *getCommandType(int i) {return commandTypes[i];} CommandClass getCommandClass(int i) {return commandClasses[i];} - Vec4f getColor() const {return colors[currentColor];} + Vec4f getColor() const; int getProgressBar() const {return progressBar;} int getDownSelectedPos() const {return downSelectedPos;} diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index b90b587a7..400b59d5b 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -309,7 +309,7 @@ void Gui::mouseDoubleClickLeftGraphics(int x, int y){ } void Gui::groupKey(int groupIndex){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); if(isKeyDown(vkControl)){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index a82324316..98c709907 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -221,6 +221,8 @@ void MainWindow::eventKeyDown(char key){ 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__); } void MainWindow::eventKeyUp(char key){ diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 1a68d62e7..959285122 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -191,10 +191,20 @@ void Program::loop(){ //update world while(updateTimer.isTime()){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + GraphicComponent::update(); programState->update(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SoundRenderer::getInstance().update(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + NetworkManager::getInstance().update(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 4644e64f0..64e49ff72 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -349,169 +349,187 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){ void MenuStateCustomGame::render(){ - Renderer &renderer= Renderer::getInstance(); + try { + Renderer &renderer= Renderer::getInstance(); - int i; + int i; - renderer.renderButton(&buttonReturn); - renderer.renderButton(&buttonPlayNow); + renderer.renderButton(&buttonReturn); + renderer.renderButton(&buttonPlayNow); - for(i=0; igetSlot(i); - - assert(connectionSlot!=NULL); - - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__); - - if(connectionSlot->isConnected()) + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { - haveAtLeastOneNetworkClientConnected = true; - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START - ctNetwork\n",__FILE__,__FUNCTION__); - string label = connectionSlot->getName(); - if(connectionSlot->getAllowDownloadDataSynch() == true && - connectionSlot->getAllowGameDataSynchCheck() == true) - { - if(connectionSlot->getNetworkGameDataSynchCheckOk() == false) - { - label = connectionSlot->getName() + " - waiting to synch:"; - if(connectionSlot->getNetworkGameDataSynchCheckOkMap() == false) - { - label = label + " map"; - } - if(connectionSlot->getNetworkGameDataSynchCheckOkTile() == false) - { - label = label + " tile"; - } - if(connectionSlot->getNetworkGameDataSynchCheckOkTech() == false) - { - label = label + " techtree"; - } - //if(connectionSlot->getNetworkGameDataSynchCheckOkFogOfWar() == false) - //{ - // label = label + " FogOfWar == false"; - //} + ConnectionSlot* connectionSlot= serverInterface->getSlot(i); - } - else - { - label = connectionSlot->getName() + " - data synch is ok"; - } - } - else - { - label = connectionSlot->getName(); + assert(connectionSlot!=NULL); - if(connectionSlot->getAllowGameDataSynchCheck() == true && - connectionSlot->getNetworkGameDataSynchCheckOk() == false) - { - label += " - warning synch mismatch for:"; - if(connectionSlot->getNetworkGameDataSynchCheckOkMap() == false) - { - label = label + " map"; - } - if(connectionSlot->getNetworkGameDataSynchCheckOkTile() == false) - { - label = label + " tile"; - } - if(connectionSlot->getNetworkGameDataSynchCheckOkTech() == false) - { - label = label + " techtree"; - } - //if(connectionSlot->getNetworkGameDataSynchCheckOkFogOfWar() == false) - //{ - // label = label + " FogOfWar == false"; - //} - } - } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__); - labelNetStatus[i].setText(label); - } - else - { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] C - ctNetwork\n",__FILE__,__FUNCTION__); - string port=intToStr(config.getInt("ServerPort")); - if(port!="61357"){ - port=port +lang.get(" NonStandardPort")+"!"; + if(connectionSlot->isConnected()) + { + haveAtLeastOneNetworkClientConnected = true; + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__); + + string label = connectionSlot->getName(); + if(connectionSlot->getAllowDownloadDataSynch() == true && + connectionSlot->getAllowGameDataSynchCheck() == true) + { + if(connectionSlot->getNetworkGameDataSynchCheckOk() == false) + { + label = connectionSlot->getName() + " - waiting to synch:"; + if(connectionSlot->getNetworkGameDataSynchCheckOkMap() == false) + { + label = label + " map"; + } + if(connectionSlot->getNetworkGameDataSynchCheckOkTile() == false) + { + label = label + " tile"; + } + if(connectionSlot->getNetworkGameDataSynchCheckOkTech() == false) + { + label = label + " techtree"; + } + //if(connectionSlot->getNetworkGameDataSynchCheckOkFogOfWar() == false) + //{ + // label = label + " FogOfWar == false"; + //} + + } + else + { + label = connectionSlot->getName() + " - data synch is ok"; + } + } + else + { + label = connectionSlot->getName(); + + if(connectionSlot->getAllowGameDataSynchCheck() == true && + connectionSlot->getNetworkGameDataSynchCheckOk() == false) + { + label += " - warning synch mismatch for:"; + if(connectionSlot->getNetworkGameDataSynchCheckOkMap() == false) + { + label = label + " map"; + } + if(connectionSlot->getNetworkGameDataSynchCheckOkTile() == false) + { + label = label + " tile"; + } + if(connectionSlot->getNetworkGameDataSynchCheckOkTech() == false) + { + label = label + " techtree"; + } + //if(connectionSlot->getNetworkGameDataSynchCheckOkFogOfWar() == false) + //{ + // label = label + " FogOfWar == false"; + //} + } + } + + labelNetStatus[i].setText(label); } else { - port=port+")"; + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] C - ctNetwork\n",__FILE__,__FUNCTION__); + string port=intToStr(config.getInt("ServerPort")); + if(port!="61357"){ + port=port +lang.get(" NonStandardPort")+"!"; + } + else + { + port=port+")"; + } + port="("+port; + labelNetStatus[i].setText("--- "+port); } - port="("+port; - labelNetStatus[i].setText("--- "+port); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END - ctNetwork\n",__FILE__,__FUNCTION__); } + else{ + labelNetStatus[i].setText(""); + } + } - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END - ctNetwork\n",__FILE__,__FUNCTION__); - } - else{ - labelNetStatus[i].setText(""); + // Send the game settings to each client if we have at least one networked client + if( serverInterface->getAllowGameDataSynchCheck() == true && + haveAtLeastOneNetworkClientConnected == true && + needToSetChangedGameSettings == true && + difftime(time(NULL),lastSetChangedGameSettings) >= 2) + { + GameSettings gameSettings; + loadGameSettings(&gameSettings); + serverInterface->setGameSettings(&gameSettings); + + needToSetChangedGameSettings = false; + lastSetChangedGameSettings = time(NULL); } + + //call the chat manager + chatManager.updateNetwork(); + + //console + console.update(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); } - - // Send the game settings to each client if we have at least one networked client - if( serverInterface->getAllowGameDataSynchCheck() == true && - haveAtLeastOneNetworkClientConnected == true && - needToSetChangedGameSettings == true && - difftime(time(NULL),lastSetChangedGameSettings) >= 2) - { - GameSettings gameSettings; - loadGameSettings(&gameSettings); - serverInterface->setGameSettings(&gameSettings); - - needToSetChangedGameSettings = false; - lastSetChangedGameSettings = time(NULL); - } - - //call the chat manager - chatManager.updateNetwork(); - - //console - console.update(); } void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); int factionCount= 0; @@ -546,7 +564,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str()); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } // ============ PRIVATE =========================== @@ -555,18 +573,25 @@ bool MenuStateCustomGame::hasNetworkGameSettings() { bool hasNetworkSlot = false; - for(int i=0; i(listBoxControls[i].getSelectedItemIndex()); - if(ct != ctClosed) + try { + for(int i=0; i(listBoxControls[i].getSelectedItemIndex()); + if(ct != ctClosed) { - hasNetworkSlot = true; - break; + if(ct == ctNetwork) + { + hasNetworkSlot = true; + break; + } } } } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); + } return hasNetworkSlot; } @@ -641,50 +666,71 @@ void MenuStateCustomGame::reloadFactions(){ } void MenuStateCustomGame::updateControlers(){ - bool humanPlayer= false; + try { + bool humanPlayer= false; - for(int i= 0; igetSlot(i)->isConnected()){ - listBoxControls[i].setSelectedItemIndex(ctClosed); + try { + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + for(int i= 0; igetSlot(i)->isConnected()){ + listBoxControls[i].setSelectedItemIndex(ctClosed); + } } } + updateNetworkSlots(); + } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); } - updateNetworkSlots(); } void MenuStateCustomGame::updateNetworkSlots() { - ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + try { + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); - for(int i= 0; igetSlot(i) == NULL && listBoxControls[i].getSelectedItemIndex() == ctNetwork) + for(int i= 0; iaddSlot(i); - } - if(serverInterface->getSlot(i) != NULL && listBoxControls[i].getSelectedItemIndex() != ctNetwork) - { - serverInterface->removeSlot(i); + if(serverInterface->getSlot(i) == NULL && listBoxControls[i].getSelectedItemIndex() == ctNetwork) + { + serverInterface->addSlot(i); + } + if(serverInterface->getSlot(i) != NULL && listBoxControls[i].getSelectedItemIndex() != ctNetwork) + { + serverInterface->removeSlot(i); + } } } + catch(const std::exception &ex) { + char szBuf[1024]=""; + sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + throw runtime_error(szBuf); + } } void MenuStateCustomGame::keyDown(char key) diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index 473e32208..7dca33855 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -362,6 +362,8 @@ void MenuStateJoinGame::update() //process network messages if(clientInterface->isConnected()) { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //update lobby clientInterface->updateLobby(); @@ -391,6 +393,8 @@ void MenuStateJoinGame::update() SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - C\n",__FILE__,__FUNCTION__); } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } if(clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index d760ebd47..286310da3 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -173,10 +173,12 @@ void ServerInterface::update() //teamMessageData.sourceTeamIndex = i; //vctTeamMessages.push_back(teamMessageData); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d for SlotIndex# %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex,i); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d for SlotIndex# %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex,i); NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex); broadcastMessage(&networkMessageText, i); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); break; } } @@ -349,12 +351,18 @@ void ServerInterface::waitUntilReady(Checksum* checksum){ } void ServerInterface::sendTextMessage(const string &text, int teamIndex){ + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + NetworkMessageText networkMessageText(text, Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), teamIndex); broadcastMessage(&networkMessageText); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } void ServerInterface::quitGame(bool userManuallyQuit) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(userManuallyQuit == true) { string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!"; @@ -364,12 +372,16 @@ void ServerInterface::quitGame(bool userManuallyQuit) NetworkMessageQuit networkMessageQuit; broadcastMessage(&networkMessageQuit); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } string ServerInterface::getNetworkStatus() const{ Lang &lang= Lang::getInstance(); string str; + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + for(int i= 0; iisConnected()) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); connectionSlot->sendMessage(networkMessage); } else if(gameHasBeenInitiated == true) @@ -452,12 +471,12 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int } } - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot){ - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); for(int i= 0; iisConnected()){ - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] before sendMessage\n",__FILE__,__FUNCTION__); connectionSlot->sendMessage(networkMessage); } } } - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } void ServerInterface::updateListen() diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 6b0397439..3eb9fd5ef 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -975,8 +975,7 @@ void ServerSocket::listen(int connectionQueueSize) throwException(szBuf); } - broadCastThread = new BroadCastSocketThread(); - broadCastThread->start(); + startBroadCastThread(); } diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 7aedbf05e..d2b1736e2 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -125,22 +125,22 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, for(unsigned int i = 0; i < static_cast (charCount); ++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__); if(i < fontInfo->min_char_or_byte2 || i > fontInfo->max_char_or_byte2) { float width = static_cast(6); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] setting size = %f\n",__FILE__,__FUNCTION__,__LINE__,width); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] setting size = %f\n",__FILE__,__FUNCTION__,__LINE__,width); metrics.setWidth(i, width); } else { - 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__); int p = i - fontInfo->min_char_or_byte2; - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,p,fontInfo->per_char); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,p,fontInfo->per_char); if(fontInfo->per_char == NULL) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),p,fontInfo->per_char); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),p,fontInfo->per_char); XCharStruct *charinfo = &(fontInfo->min_bounds); //int charWidth = charinfo->rbearing - charinfo->lbearing; @@ -148,11 +148,11 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, //int spanLength = (charWidth + 7) / 8; if(charinfo != NULL) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] charinfo->width = %d\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),charinfo->width); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] charinfo->width = %d\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),charinfo->width); metrics.setWidth(i, static_cast (charinfo->width)); } else { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size 6\n",__FILE__,__FUNCTION__,__LINE__,type.c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size 6\n",__FILE__,__FUNCTION__,__LINE__,type.c_str()); metrics.setWidth(i, static_cast(6)); } @@ -162,7 +162,7 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, if(width <= 0) { width = static_cast(6); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size = %f\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),width); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size = %f\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),width); metrics.setWidth(i, width); } } @@ -179,7 +179,6 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] glerror = %d\n",__FILE__,__FUNCTION__,__LINE__,glerror); - XFreeFont(display, fontInfo); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 0cfacc9b8..6df9f6ac1 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -128,8 +128,11 @@ bool Window::handleEvent() { } if(global_window) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + global_window->eventKeyDown(getKey(event.key.keysym)); global_window->eventKeyPress(static_cast(event.key.keysym.unicode)); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } break; case SDL_KEYUP: @@ -153,6 +156,11 @@ bool Window::handleEvent() { std::cerr << "(b) Couldn't process event: " << e.what() << "\n"; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (b) Couldn't process event: [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); } + catch(...) { + std::cerr << "(b) Couldn't process event: [UNKNOWN ERROR]\n"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] (b) Couldn't process event: [UNKNOWN ERROR]\n",__FILE__,__FUNCTION__,__LINE__); + } + } //printf("END [%d]\n",event.type); diff --git a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp index e930ada5b..358d2aa59 100644 --- a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp +++ b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp @@ -32,12 +32,12 @@ SoundSource::SoundSource() SoundSource::~SoundSource() { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); stop(); alDeleteSources(1, &source); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } bool SoundSource::playing() @@ -195,7 +195,7 @@ void StreamSoundSource::update() //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); if(sound == 0) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); return; }