From 6e6f06d2a10d53a50d31adc173ee914677ff64ff Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 22 Nov 2007 01:20:57 +0000 Subject: [PATCH] 1) Applied Paul's patch for redirecting messages to a file. 2) Added command line option to select if messages are written to a file or terminal 3) Added some error checking if the log file can't be opened (though this is apparently only working for stdout, but not for stderr???) 4) Replaced the #ifdef DIR_SEPATAROR with a static const in loader. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1302 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/highscore_manager.cpp | 2 +- src/kart_properties_manager.cpp | 2 +- src/loader.hpp | 10 +++---- src/main.cpp | 46 +++++++++++++++++++++++++++++---- src/material.cpp | 2 +- src/track.cpp | 14 +++++----- src/track_manager.cpp | 2 +- src/user_config.cpp | 7 +++++ src/user_config.hpp | 1 + src/world.cpp | 2 +- 10 files changed, 66 insertions(+), 22 deletions(-) diff --git a/src/highscore_manager.cpp b/src/highscore_manager.cpp index 871c8e221..d2c4b8841 100644 --- a/src/highscore_manager.cpp +++ b/src/highscore_manager.cpp @@ -67,7 +67,7 @@ void HighscoreManager::SetFilename() for(unsigned int i=0; iload(tmp.c_str(), "tuxkart-kart", dont_load_models); m_karts_properties.push_back(kp); if(kp->getMaxSteerAngle() > m_max_steer_angle) diff --git a/src/loader.hpp b/src/loader.hpp index 6fcc2a673..b530898e0 100644 --- a/src/loader.hpp +++ b/src/loader.hpp @@ -26,15 +26,15 @@ #include #include "callback_manager.hpp" -#ifdef _MSC_VER -const char DIR_SEPARATOR='\\'; -#else -const char DIR_SEPARATOR='/'; -#endif class Loader : public ssgLoaderOptions { public: +#ifdef _MSC_VER + static const char DIR_SEPARATOR='\\'; +#else + static const char DIR_SEPARATOR='/'; +#endif Loader(); ~Loader(); diff --git a/src/main.cpp b/src/main.cpp index 43944b5d2..de28f52ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,8 @@ # include #endif #include +#include +#include #include "user_config.hpp" #include "track_manager.hpp" @@ -98,6 +100,8 @@ void cmdLineHelp (char* invocation) // " --profile Enable automatic driven profile mode for 20 seconds\n" // " --profile=n Enable automatic driven profile mode for n seconds\n" // " --history Replay history file 'history.dat'\n" + " --log=terminal Write messages to screen\n" + " --log=file Write messages/warning to log files stdout.log/stderr.log\n" " -h, --help Show this help\n" "\n" "You can visit SuperTuxKart's homepage at " @@ -164,7 +168,7 @@ int handleCmdLine(int argc, char **argv) } else if( (!strcmp(argv[i], "--stk-config")) && i+1load(std::string("data")+DIR_SEPARATOR+argv[i+1]); + stk_config->load(std::string("data")+Loader::DIR_SEPARATOR+argv[i+1]); fprintf ( stdout, _("STK config will be read from %s.\n"), argv[i+1] ) ; } else if( (!strcmp(argv[i], "--numkarts") || !strcmp(argv[i], "-k")) && @@ -178,7 +182,7 @@ int handleCmdLine(int argc, char **argv) } race_manager->setNumKarts(user_config->m_karts ); fprintf ( stdout, _("%d karts will be used.\n"), user_config->m_karts); - i++; + i++; } else if( !strcmp(argv[i], "--list-tracks") || !strcmp(argv[i], "-l") ) { @@ -278,7 +282,14 @@ int handleCmdLine(int argc, char **argv) #endif return 0; } - else if( sscanf(argv[i], "--profile=%d", &n)==1) + else if( !strcmp(argv[i], "--log=terminal")) + { + user_config->m_log_errors=false; + } + else if( !strcmp(argv[i], "--log=file")) + { + user_config->m_log_errors=true; + }else if( sscanf(argv[i], "--profile=%d", &n)==1) { user_config->m_profile=n; } @@ -342,7 +353,7 @@ void InitTuxkart() race_manager->setNumLaps (3); race_manager->setRaceMode (RaceSetup::RM_QUICK_RACE); race_manager->setDifficulty(RD_MEDIUM); - stk_config->load(std::string("data")+DIR_SEPARATOR+ "stk_config.data"); + stk_config->load(std::string("data")+Loader::DIR_SEPARATOR+ "stk_config.data"); } //============================================================================= @@ -358,7 +369,26 @@ int main(int argc, char *argv[] ) //handleCmdLine() needs InitTuxkart() so it can't be called first if(!handleCmdLine(argc, argv)) exit(0); - + + if (user_config->m_log_errors) //Enable logging of stdout and stderr to logfile + { + std::string logoutfile = user_config->getConfigDir(); + logoutfile += Loader::DIR_SEPARATOR; + std::string logerrfile = logoutfile; + logoutfile += "stdout.log"; + logerrfile += "stderr.log"; + if(freopen (logoutfile.c_str(),"w",stdout)!=stdout) + { + fprintf(stderr, "Can not open log file '%s'. Writing to stdout instead.\n", + logoutfile.c_str()); + } + if(freopen (logerrfile.c_str(),"w",stderr)!=stderr) + { + fprintf(stderr, "Can not open log file '%s'. Writing to stderr instead.\n", + logerrfile.c_str()); + } + } + //FIXME: this needs a better organization drv_init(); game_manager = new GameManager (); @@ -436,6 +466,12 @@ int main(int argc, char *argv[] ) user_config->saveConfig(); drv_deinit(); + + if (user_config->m_log_errors) //close logfiles + { + fclose(stderr); + fclose(stdout); + } delete highscore_manager; return 0 ; diff --git a/src/material.cpp b/src/material.cpp index 75681c7c6..bbaf3c02c 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -158,7 +158,7 @@ void Material::install () m_state -> setExternalPropertyIndex ( m_index ) ; if ( m_texname != NULL && m_texname [ 0 ] != '\0' ) { - std::string fn=std::string("images")+DIR_SEPARATOR+m_texname; + std::string fn=std::string("images")+Loader::DIR_SEPARATOR+m_texname; m_state -> setTexture ( loader->getPath(fn).c_str(), !(m_clamp_tex & UCLAMP), !(m_clamp_tex & VCLAMP) ); m_state -> enable ( GL_TEXTURE_2D ) ; diff --git a/src/track.cpp b/src/track.cpp index 48ab8d453..895acb6c9 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -457,15 +457,15 @@ void Track::addDebugToScene(int type) const // The segment display must be slightly higher than the // track, otherwise it's not clearly visible. sgVec3 v; - sgCopyVec3(v,m_left_driveline [i ]); v[2]+=0.1; v_array->add(v); - sgCopyVec3(v,m_right_driveline[i ]); v[2]+=0.1; v_array->add(v); - sgCopyVec3(v,m_right_driveline[ip1]); v[2]+=0.1; v_array->add(v); - sgCopyVec3(v,m_left_driveline [ip1]); v[2]+=0.1; v_array->add(v); + sgCopyVec3(v,m_left_driveline [i ]); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,m_right_driveline[i ]); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,m_right_driveline[ip1]); v[2]+=0.1f; v_array->add(v); + sgCopyVec3(v,m_left_driveline [ip1]); v[2]+=0.1f; v_array->add(v); sgVec4 vc; vc[0] = i%2==0 ? 1.0f : 0.0f; vc[1] = 1.0f-v[0]; - vc[2] = 0; - vc[3] = 0.1; + vc[2] = 0.0f; + vc[3] = 0.1f; c_array->add(vc);c_array->add(vc);c_array->add(vc);c_array->add(vc); } // for i // if GL_QUAD_STRIP is used, the colours are smoothed, so the changes @@ -900,7 +900,7 @@ void Track::readDrivelineFromFile(std::vector& line, const std::string& file_ext) { std::string path = "data"; - path += DIR_SEPARATOR; + path += Loader::DIR_SEPARATOR; path += m_ident; path += file_ext; path = loader->getPath(path.c_str()); diff --git a/src/track_manager.cpp b/src/track_manager.cpp index 84a6d3e99..5727896ff 100644 --- a/src/track_manager.cpp +++ b/src/track_manager.cpp @@ -76,7 +76,7 @@ TrackManager::loadTrackList () { if(StringUtils::has_suffix(*i, ".track")) { - std::string track_name= std::string("data")+DIR_SEPARATOR + *i; + std::string track_name= std::string("data")+Loader::DIR_SEPARATOR + *i; m_tracks.push_back(new Track(track_name.c_str())); } } diff --git a/src/user_config.cpp b/src/user_config.cpp index ee45372f1..d7ddb076e 100644 --- a/src/user_config.cpp +++ b/src/user_config.cpp @@ -126,6 +126,7 @@ void UserConfig::setDefaults() m_width = 800; m_height = 600; m_karts = 4; + m_log_errors = true; if(getenv("USERNAME")!=NULL) // for windows m_username=getenv("USERNAME"); @@ -328,6 +329,9 @@ void UserConfig::loadConfig(const std::string& filename) /*get number of karts*/ lisp->get("karts", m_karts); + //get whether to log errors to file + lisp->get("log-errors", m_log_errors); + /*get player configurations*/ for(i=0; iupdate(1./60.); while(!all_finished) { - m_physics->update(1./60.); + m_physics->update(1.f/60.f); all_finished=true; for ( Karts::iterator i=m_kart.begin(); i!=m_kart.end(); i++) {