예제 #1
0
파일: main.c 프로젝트: wosigh/tuxracer
int main( int argc, char **argv ) 
{
    /* Print copyright notice */

    fprintf( stderr, 
         "Tux Rider World Challenge -- http://www.barlow-server.com\n"
         "a fork from:\n"
         "Tux Racer " VERSION " -- a Sunspire Studios Production "
	     "(http://www.sunspirestudios.com)\n"
	     "(c) 1999-2000 Jasmin F. Patry "
	     "<*****@*****.**>\n"
	     "\"Tux Racer\" is a trademark of Jasmin F. Patry\n"
	     "Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. "
	     "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\n" );

    /* Init the game clock */
    g_game.secs_since_start = 0;

    /* Seed the random number generator */
    srand( time(NULL) );


    /*
     * Set up the game configuration
     */

    /* Don't support multiplayer, yet... */
    g_game.num_players = 2;

    /* Create a Tcl interpreter */
    g_game.tcl_interp = Tcl_CreateInterp();

    if ( g_game.tcl_interp == NULL ) {
	handle_error( 1, "cannot create Tcl interpreter" ); 
    }

    /* Setup the configuration variables and read the ~/.tuxracer/options file */
    init_game_configuration();
    read_config_file();

    /* Set up the debugging modes */
    init_debug();

    /* Setup diagnostic log if requested */
    if ( getparam_write_diagnostic_log() ) {
	setup_diagnostic_log();
    }

    /*
     * Setup Tcl stdout and stderr channels to point to C stdout and stderr 
     * streams
     */
    setup_tcl_std_channels();


    /* 
     * Initialize rendering context, create window
     */
    winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE );


    /* Ingore key-repeat messages */
    winsys_enable_key_repeat(0);


    /* Set up a function to clean up when program exits */
    winsys_atexit( cleanup );

    /* 
     * Initial OpenGL settings 
     */
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    init_opengl_extensions();

    /* Print OpenGL debugging information if requested */
    if ( debug_mode_is_active( DEBUG_GL_INFO ) ) {
	print_debug( DEBUG_GL_INFO, 
		     "OpenGL information:" );
	print_gl_info();
    }


    /* 
     * Load the game data and initialize game state
     */
    register_game_config_callbacks( g_game.tcl_interp );
    register_course_load_tcl_callbacks( g_game.tcl_interp );
    register_key_frame_callbacks( g_game.tcl_interp );
    register_fog_callbacks( g_game.tcl_interp );
    register_course_light_callbacks( g_game.tcl_interp );
    register_particle_callbacks( g_game.tcl_interp );
    register_texture_callbacks( g_game.tcl_interp );
    register_font_callbacks( g_game.tcl_interp );
    register_sound_tcl_callbacks( g_game.tcl_interp );
    register_sound_data_tcl_callbacks( g_game.tcl_interp );
    register_course_manager_callbacks( g_game.tcl_interp );


    init_saved_games();
    load_tux();
    init_textures();
    init_fonts();
    init_audio_data();
    init_audio();
    init_ui_manager();
    init_course_manager();
    init_joystick();

    /* Read the tuxracer_init.tcl file */
    read_game_init_script();

    /* Need to set up an initial view position for select_course 
       (quadtree simplification)
    */
    
    //Player 0 = classic mode player ; Player 1 = Speed Only Mode Player
    
    g_game.player[0].view.pos = make_point( 0., 0., 0. );
    g_game.player[1].view.pos = make_point( 0., 0., 0. );
    

    /* Placeholder name until we give players way to enter name */
    g_game.player[0].name = "noname";
    g_game.player[1].name = "nonameSpeedOnly";
   

    init_preview();

    splash_screen_register();
    intro_register();
    racing_register();
    game_over_register();
    paused_register();
    reset_register();
    game_type_select_register();
    racing_mode_select_register();
    event_select_register();
    race_select_register();
    credits_register();
    loading_register();

    g_game.mode = NO_MODE;
    set_game_mode( SPLASH );

    g_game.difficulty = DIFFICULTY_LEVEL_NORMAL;

    init_keyboard();
    

    winsys_show_cursor( False );

    /* We use this to "prime" the GLUT loop */
    winsys_set_idle_func( main_loop );

    
    /* 
     * ...and off we go!
     */
    winsys_process_events();

    return 0;
} 
예제 #2
0
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();
	}
}