void load_tux() { char cwd[BUFF_LEN]; if ( tuxLoaded == True ) return; tuxLoaded = True; registerHierCallbacks( g_game.tcl_interp ); register_tux_callbacks( g_game.tcl_interp ); initialize_scene_graph(); if ( getcwd( cwd, BUFF_LEN ) == NULL ) { handle_system_error( 1, "getcwd failed" ); } if ( chdir( getparam_data_dir() ) != 0 ) { /* Print a more informative warning since this is a common error */ handle_system_error( 1, "Can't find the tuxracer data " "directory. Please check the\nvalue of `data_dir' in " "~/.tuxracer/options and set it to the location where you\n" "installed the TRWC-data files.\n\n" "Couldn't chdir to %s", getparam_data_dir() ); /* handle_system_error( 1, "couldn't chdir to %s", getparam_data_dir() ); */ } if ( Tcl_EvalFile( g_game.tcl_interp, "tux.tcl") == TCL_ERROR ) { handle_error( 1, "error evalating %s/tux.tcl: %s\n" "Please check the value of `data_dir' in ~/.tuxracer/options " "and make sure it\npoints to the location of the " "latest version of the TRWC-data files.", getparam_data_dir(), Tcl_GetStringResult( g_game.tcl_interp ) ); } check_assertion( !Tcl_InterpDeleted( g_game.tcl_interp ), "Tcl interpreter deleted" ); if ( chdir( cwd ) != 0 ) { handle_system_error( 1, "couldn't chdir to %s", cwd ); } }
int main(int argc, char *argv[]) { try{ // used to catch all unhandled Errors and Assertions // print copyright notice std::cout << "PlanetPenguin Racer " VERSION " -- http://racer.planetpenguin.de\n" << "(c) 2004-2006 PlanetPenguin Racer team\n" << "(c) 1999-2001 Jasmin F. Patry\n" << "<*****@*****.**>\n" << "PlanetPenguin Racer comes with ABSOLUTELY NO WARRANTY.\n" << "This is free software,\nand you are welcome to redistribute it under certain conditions.\n" << "See http://www.gnu.org/copyleft/gpl.html for details.\n" << std::endl; // initialize performance test if activated ppogl::initPerftest(); // set current directory to be used as base ppogl::os::setBaseDir(); // set user directory to "~/.ppracer/" ppogl::os::setUserDir(ppogl::os::getHomeDir()+".ppracer/"); // parse comandline options getopts(argc,argv); // set logging to be verbose if possible if(verbose){ init_log(); ppogl::Log::Instance()->setLevel(ppogl::LogUnknown); if(verbose>1){ // set log system to print long messages ppogl::Log::Instance()->setVerbose(true); init_log(); } } // seed the random number generator srand( time(NULL) ); if(GameMode::exp_multiscreen==GameMode::MULTISCREEN_NONE){ GameMgr::getInstance().numPlayers = 1; }else{ GameMgr::getInstance().numPlayers = 2; } ppogl::Config::getInstance().init(&script,"ppconfig"); register_cfile_callbacks(); bool create_cfile=true; if(cfile.empty()){ cfile=get_config_file_name(); } if( !resetConfig && ppogl::os::isFile(cfile) ){ script.doFile(cfile); // check whether the user set the data directory per commandline option if(data_dir.empty()){ data_dir = PPConfig.getString("data_dir"); } PP_MESSAGE("Load config file"); create_cfile=false; }else if(data_dir.empty()){ data_dir = DATA_DIR; } if(ppogl::os::isDirectory(data_dir)==false){ PP_ERROR("Unable to find data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } if(ppogl::os::isFile(data_dir+"/config.nut")==false){ PP_ERROR("Unable to find needed file config.nut in the data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } script.doFile(data_dir+"/config.nut"); PPConfig.setString("data_dir",data_dir); if(create_cfile){ write_config_file(); } /* * Initialize rendering context, create window */ winsys_init(WINDOW_TITLE, WINDOW_TITLE); /* * Initial OpenGL settings */ gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // init compiled_vertex extension gl::EXTcompiledVertexArrayInit(); // print OpenGL debugging information if(verbose) print_gl_info(); /* * Load the game data and initialize game state */ register_key_frame_callbacks(); Course::registerCallbacks(); FogPlane::registerCallbacks(); register_course_light_callbacks(); PartSys::registerCallbacks(); register_course_manager_callbacks(); register_hier_callbacks(); register_tux_callbacks(); // init audio PP_MESSAGE("Init audio"); if(PPConfig.getBool("disable_audio")==false){ bool stereo = PPConfig.getBool("audio_stereo"); ppogl::AudioMgr::Format format; int freq; switch(PPConfig.getInt("audio_format_mode")){ case 0: format = ppogl::AudioMgr::FORMAT_8; break; case 1: format = ppogl::AudioMgr::FORMAT_16; break; default: format = ppogl::AudioMgr::FORMAT_8; } switch(PPConfig.getInt("audio_freq_mode")){ case 0: freq = ppogl::AudioMgr::FQ_11; break; case 1: freq = ppogl::AudioMgr::FQ_22; break; case 2: freq = ppogl::AudioMgr::FQ_44; break; default: freq = ppogl::AudioMgr::FQ_11; } ppogl::AudioMgr::getInstance().init(freq,format,stereo); if(PPConfig.getBool("sound_enabled")==false){ ppogl::AudioMgr::getInstance().enableSound(false); } if(PPConfig.getBool("music_enabled")==false){ ppogl::AudioMgr::getInstance().enableMusic(false); } // set volumes ppogl::AudioMgr::getInstance().setMusicVolume( PPConfig.getInt("music_volume")); ppogl::AudioMgr::getInstance().setSoundVolume( PPConfig.getInt("sound_volume")); } PP_MESSAGE("Load translation: " << PPConfig.getString("ui_language")); // Setup translations script.doFile(data_dir+"/translations/languages.nut"); script.doFile(data_dir+"/translations/"+PPConfig.getString("ui_language")+".nut"); script.doFile(data_dir+"/init.nut"); // load "cached" configuration values GameConfig::update(); fpsCounter.setMaxFPS(PPConfig.getInt("gui_max_fps")); PP_MESSAGE("Init joystick"); GameMode::joystick.init(); init_ui_snow(); for(int i=0; i<GameMgr::getInstance().numPlayers; i++){ // Placeholder name until we give players way to enter name players[i].name = "tux"; players[i].loadData(); players[i].num = i; } GameMode::mode = GameMode::NO_MODE; if(Benchmark::getMode()==Benchmark::NONE){ GameMode::setMode(GameMode::SPLASH); }else{ GameMode::setMode(GameMode::BENCHMARK); } GameMgr::getInstance().difficulty = CourseData::DIFFICULTY_NORMAL; SDL_ShowCursor(false); PP_MESSAGE("Entering event loop"); winsys_process_events(); return 0; }catch(ppogl::Error &e){ /* * It's possible that an exception is thrown outside of main. * In most cases this is a problem with the object * destruction during program termination. * If we see the abort message (see below) we known * that the exception is thrown within main(). */ std::cerr << "Aborting main function :(" << std::endl; abort(); } }