From 8e4ed0515968175cc0cada0e7207e90ac7f65954 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 6 Jan 2012 18:04:01 +0000 Subject: [PATCH] - bugfixes to g3dviewer when loading a unit with particles from commandline (fixes recursive call crash), and added verbose commandline switch for g3dviewer --- source/g3d_viewer/main.cpp | 52 ++++++++++++++----- .../glest_game/network/client_interface.cpp | 6 ++- source/shared_lib/sources/xml/xml_parser.cpp | 12 +++-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 398fef580..87e5745a4 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -105,6 +105,7 @@ const wxChar *GAME_ARGS[] = { wxT("--rotate-x-value"), wxT("--rotate-y-value"), wxT("--screenshot-format"), + wxT("--verbose"), }; enum GAME_ARG_TYPE { @@ -121,6 +122,7 @@ enum GAME_ARG_TYPE { GAME_ARG_ROTATE_X_VALUE, GAME_ARG_ROTATE_Y_VALUE, GAME_ARG_SCREENSHOT_FORMAT, + GAME_ARG_VERBOSE, }; bool hasCommandArgument(int argc, wxChar** argv,const string argName, @@ -1273,15 +1275,19 @@ void MainWindow::loadParticle(string path) { //int height = -1; if(fileExists(unitXML) == true) { + + int size = 0; + int height= 0; + { XmlTree xmlTree; xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *parametersNode= unitNode->getChild("parameters"); //size - int size= parametersNode->getChild("size")->getAttribute("value")->getIntValue(); + size= parametersNode->getChild("size")->getAttribute("value")->getIntValue(); //height - int height= parametersNode->getChild("height")->getAttribute("value")->getIntValue(); - + height= parametersNode->getChild("height")->getAttribute("value")->getIntValue(); + } // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; @@ -1326,6 +1332,8 @@ void MainWindow::loadParticle(string path) { } void MainWindow::loadProjectileParticle(string path) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] particleProjectilePathList.size() = %lu\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleProjectilePathList.size()); + if(timer) timer->Stop(); if(path != "" && fileExists(path) == true) { renderer->end(); @@ -1345,7 +1353,7 @@ void MainWindow::loadProjectileParticle(string path) { try { if(this->particleProjectilePathList.empty() == false) { - printf("this->particleProjectilePathList.size() = %lu\n",this->particleProjectilePathList.size()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("this->particleProjectilePathList.size() = %lu\n",this->particleProjectilePathList.size()); string titlestring=winHeader; for(unsigned int idx = 0; idx < this->particleProjectilePathList.size(); idx++) { @@ -1366,6 +1374,8 @@ void MainWindow::loadProjectileParticle(string path) { int height = -1; if(fileExists(unitXML) == true) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitXML.c_str(),idx); + XmlTree xmlTree; xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); @@ -1378,18 +1388,21 @@ void MainWindow::loadProjectileParticle(string path) { // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; + string particleFile = dir + folderDelimiter + particlePath; { - XmlTree xmlTree; - xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues()); - //const XmlNode *particleSystemNode= xmlTree.getRootNode(); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx); + XmlTree xmlTree; + xmlTree.load(particleFile,Properties::getTagReplacementValues()); + //const XmlNode *particleSystemNode= xmlTree.getRootNode(); - // std::cout << "Loaded successfully, loading values..." << std::endl; + // std::cout << "Loaded successfully, loading values..." << std::endl; } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx); std::map > > loadedFileList; ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType->load(NULL, dir, //### we don't know if there are overrides in the unit XML - dir + folderDelimiter + particlePath,renderer, loadedFileList, + particleFile,renderer, loadedFileList, "g3dviewer",""); // std::cout << "Values loaded, about to read..." << std::endl; @@ -1415,6 +1428,8 @@ void MainWindow::loadProjectileParticle(string path) { ps->setVisible(true); renderer->manageParticleSystem(ps); } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loaded [%s] idx = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx); } SetTitle(ToUnicode(titlestring)); @@ -1431,9 +1446,12 @@ void MainWindow::loadProjectileParticle(string path) { wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal(); } if(timer) timer->Start(100); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] after load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); } void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSplash::load (and own list...) + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] particleSplashPathList.size() = %lu\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleSplashPathList.size()); + if(timer) timer->Stop(); if(path != "" && fileExists(path) == true) { renderer->end(); @@ -1484,11 +1502,12 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; - XmlTree xmlTree; - xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues()); - //const XmlNode *particleSystemNode= xmlTree.getRootNode(); - - // std::cout << "Loaded successfully, loading values..." << std::endl; + { + XmlTree xmlTree; + xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues()); + //const XmlNode *particleSystemNode= xmlTree.getRootNode(); + // std::cout << "Loaded successfully, loading values..." << std::endl; + } std::map > > loadedFileList; ParticleSystemTypeSplash *splashParticleSystemType= new ParticleSystemTypeSplash(); @@ -1534,6 +1553,7 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal(); } if(timer) timer->Start(100); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] after load [%s] particleSplashPathList.size() = %lu\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleSplashPathList.size()); } void MainWindow::onMenuModeNormals(wxCommandEvent &event){ @@ -2008,6 +2028,10 @@ bool App::OnInit() { return false; } + if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_VERBOSE])) == true) { + SystemFlags::VERBOSE_MODE_ENABLED = true; + } + if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT])) == true) { autoScreenShotAndExit = true; diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index c62100755..728fdee92 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -982,8 +982,10 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { return; } - //delay the start a bit, so clients have more room to get messages - sleep(100); + // delay the start a bit, so clients have more room to get messages + // This is to ensure clients don't start ahead of the server and thus + // constantly freeze because they are waiting for the server to catch up + sleep(120); // This triggers LAG update packets to begin as required lastNetworkCommandListSendTime = time(NULL); diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index bfac71d70..3a2bf0c74 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -70,7 +70,7 @@ XmlIo::XmlIo() { XmlIo::initialized= true; } catch(const XMLException &e){ - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error initializing XML system, msg %s\n",__FILE__,__FUNCTION__,__LINE__,e.getMessage()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error initializing XML system, msg %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.getMessage()); throw runtime_error("Error initializing XML system"); } @@ -81,7 +81,7 @@ XmlIo::XmlIo() { implementation = DOMImplementationRegistry::getDOMImplementation(str); } catch(const DOMException &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",__FILE__,__FUNCTION__,__LINE__,ex.getMessage()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.getMessage()); throw runtime_error("Exception while creating XML parser"); } } @@ -135,7 +135,7 @@ XmlNode *XmlIo::load(const string &path, std::map mapTagReplaceme return rootNode; } catch(const DOMException &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while loading: [%s], %s\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg)); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while loading: [%s], %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg)); throw runtime_error("Exception while loading: " + path + ": " + XMLString::transcode(ex.msg)); } } @@ -170,7 +170,7 @@ void XmlIo::save(const string &path, const XmlNode *node){ document->release(); } catch(const DOMException &e){ - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while saving: [%s], %s\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(e.msg)); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while saving: [%s], %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(e.msg)); throw runtime_error("Exception while saving: " + path + ": " + XMLString::transcode(e.msg)); } } @@ -191,6 +191,8 @@ typedef std::vector LoadStack; static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName"); void XmlTree::load(const string &path, std::map mapTagReplacementValues) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); + //printf("XmlTree::load p [%p]\n",this); assert(!loadPath.size()); @@ -208,6 +210,8 @@ void XmlTree::load(const string &path, std::map mapTagReplacement loadPath = path; this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); } void XmlTree::save(const string &path){