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
This commit is contained in:
parent
c62f8622da
commit
6e6f06d2a1
@ -67,7 +67,7 @@ void HighscoreManager::SetFilename()
|
||||
for(unsigned int i=0; i<m_filename.size(); i++)
|
||||
{
|
||||
if(m_filename[i]=='\\' || m_filename[i]=='/')
|
||||
m_filename[i]=DIR_SEPARATOR;
|
||||
m_filename[i]=Loader::DIR_SEPARATOR;
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -68,7 +68,7 @@ void KartPropertiesManager::loadKartData(bool dont_load_models)
|
||||
if (StringUtils::has_suffix(*i, ".tkkf"))
|
||||
{
|
||||
KartProperties* kp = new KartProperties();
|
||||
std::string tmp= std::string("data")+DIR_SEPARATOR + *i;
|
||||
std::string tmp= std::string("data")+Loader::DIR_SEPARATOR + *i;
|
||||
kp->load(tmp.c_str(), "tuxkart-kart", dont_load_models);
|
||||
m_karts_properties.push_back(kp);
|
||||
if(kp->getMaxSteerAngle() > m_max_steer_angle)
|
||||
|
@ -26,15 +26,15 @@
|
||||
#include <set>
|
||||
#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();
|
||||
|
||||
|
42
src/main.cpp
42
src/main.cpp
@ -38,6 +38,8 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <stdexcept>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#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+1<argc )
|
||||
{
|
||||
stk_config->load(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")) &&
|
||||
@ -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");
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
@ -359,6 +370,25 @@ 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 ();
|
||||
@ -437,6 +467,12 @@ int main(int argc, char *argv[] )
|
||||
|
||||
drv_deinit();
|
||||
|
||||
if (user_config->m_log_errors) //close logfiles
|
||||
{
|
||||
fclose(stderr);
|
||||
fclose(stdout);
|
||||
}
|
||||
|
||||
delete highscore_manager;
|
||||
return 0 ;
|
||||
}
|
||||
|
@ -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 ) ;
|
||||
|
@ -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<sgVec3Wrapper>& 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());
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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; i<PLAYERS; ++i)
|
||||
{
|
||||
@ -505,6 +509,9 @@ void UserConfig::saveConfig(const std::string& filename)
|
||||
writer.writeComment("number of karts. -1 means use all");
|
||||
writer.write("karts\t", m_karts);
|
||||
|
||||
writer.writeComment("error logging to log (true) or stderr (false)");
|
||||
writer.write("log-errors\t", m_log_errors);
|
||||
|
||||
/* write player configurations */
|
||||
for(i=0; i<PLAYERS; ++i)
|
||||
{
|
||||
|
@ -91,6 +91,7 @@ public:
|
||||
int m_height;
|
||||
int m_karts;
|
||||
Player m_player[PLAYERS];
|
||||
bool m_log_errors;
|
||||
|
||||
UserConfig();
|
||||
UserConfig(const std::string& filename);
|
||||
|
@ -256,7 +256,7 @@ void World::resetAllKarts()
|
||||
for(int i=0; i<10; i++) m_physics->update(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++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user