/*
 ==================
 iphoneShutdown
 
 Write out configs and save the game at this position
 ==================
 */
void iphoneShutdown() {
	FILE	*fp;
	char	path[1024];
	cvar_t	*var;
	char	buffer[1024];
	
	// write the ascii config file
	snprintf( path, sizeof( path ), "%s/config.cfg", SysIphoneGetDocDir() );
	fp = fopen( path, "w" );
	if( ! fp ) {
		Com_Printf( "Could not write config.cfg.\n" );
		return;
	}
	
	// write out commands to set the archived cvars
	for( var = cvar_vars ; var ; var = var->next ) {
		if( var->flags & CVAR_ARCHIVE ) {
			snprintf( buffer, sizeof( buffer ), "%s %s\n", var->name, var->string );
			fprintf( fp, "%s", buffer );
			Com_Printf( "%s", buffer );
		}
	}
	
	fclose( fp );
	

	// write the binary config file
	FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "wb" );
	if ( !f ) {
		Com_Printf( "Could not write binaryConfig.cfg.\n" );
		return;
	}
	
	int version = VERSION_BCONFIG;
	
	fwrite( &version, 1, sizeof( version ), f );
	
	fwrite( &playState, 1, sizeof( playState ), f );
	fwrite( &huds, 1, sizeof( huds ), f );
	
	fwrite( &version, 1, sizeof( version ), f );
	fclose( f );

	// write the Doom savegame, unless no game level
	// was actually started on this app invokation, or we
	// are at an intermission / finale, or we are dead
	if ( levelHasBeenLoaded && !netgame && gamestate == GS_LEVEL 
		&& players[consoleplayer].playerstate != PST_DEAD ) {
		// let the game thread perform a savegame, since it
		// would be unsafe to do it in this thread
		saveOnExitState = 1;
		while( saveOnExitState != 2 ) {
			sem_post( ticSemaphore );
			usleep( 10000 );
		}
	}
	
	// not sure if we should do this, or let UIKit exit...
	exit( 0 );
}
Example #2
0
/*
 ==================
 iphoneShutdown
 
 Write out configs and save the game at this position
 ==================
 */
void iphoneShutdown() {
	FILE	*fp;
	char	path[1024];
	cvar_t	*var;
	char	buffer[1024];
    
    if( lastState == IPM_GAME && gamestate != GS_INTERMISSION && !demoplayback ) {
      G_DoSaveGame( false );
    }
    
	// write the ascii config file
	snprintf( path, sizeof( path ), "%s/config.cfg", SysIphoneGetDocDir() );
	fp = fopen( path, "w" );
	if( ! fp ) {
		Com_Printf( "Could not write config.cfg.\n" );
		return;
	}
	
	// write out commands to set the archived cvars
	for( var = cvar_vars ; var ; var = var->next ) {
		if( var->flags & CVAR_ARCHIVE ) {
			snprintf( buffer, sizeof( buffer ), "%s %s\n", var->name, var->string );
			fprintf( fp, "%s", buffer );
			Com_Printf( "%s", buffer );
		}
	}
	
	fclose( fp );
	

	// write the binary config file
	FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "wb" );
	if ( !f ) {
		Com_Printf( "Could not write binaryConfig.cfg.\n" );
		return;
	}
	
	int version = VERSION_BCONFIG;
	
	fwrite( &version, 1, sizeof( version ), f );
	
	fwrite( &playState, 1, sizeof( playState ), f );
	fwrite( &huds, 1, sizeof( huds ), f );
	
	fwrite( &version, 1, sizeof( version ), f );
	fclose( f );
	
}
Example #3
0
/*
 ==================
 iphoneDoomSetup
 
 Run the Doom game setup functions. This was made seperate from iphoneStartup so that the user
 could select a mission pack first.
 ==================
 */
void iphoneDoomStartup( const char * iwad, const char * pwad ) {
	Com_Printf( "---------- D_DoomMain ----------\n" );
	D_DoomMainSetup( iwad, pwad );
	
	// put savegames here
    strcpy( basesavegame, SysIphoneGetDocDir() );
	
}
Example #4
0
void iphoneStartup() {
	int		start = SysIphoneMilliseconds();
	
	// microseconds will be plenty random for playerID and localGameID
	playerID = localGameID = SysIphoneMicroseconds();
	
	InitImmediateModeGL();

	// init OpenAL before pak file, so the pak file can
	// make all the al static buffers
	Sound_Init();
	
	char buffer[1028];
	sprintf( buffer, "%s/base.iPack", SysIphoneGetAppDir() );
	// get our new-style pak file
	PK_Init( buffer );

	// register console commands
	Cmd_AddCommand( "listcvars", Cvar_List_f );
	Cmd_AddCommand( "resetcvars", Cvar_Reset_f );
	Cmd_AddCommand( "resetmaps", ResetMaps_f );
	Cmd_AddCommand( "listcmds", Cmd_ListCommands_f );
	Cmd_AddCommand( "give", Give_f );
	Cmd_AddCommand( "god", God_f );
	Cmd_AddCommand( "mail", EmailConsole );  //gsh, mails the console to id

	// register console variables
	Cvar_Get( "version", va( "%3.1f %s %s", DOOM_IPHONE_VERSION, __DATE__, __TIME__ ), 0 );
    
    freeLevelOfWeek = Cvar_Get("freeLevelOfWeek", "0", 0 );
	skill = Cvar_Get( "skill", "1", CVAR_ARCHIVE );
	episode = Cvar_Get( "episode", "0", CVAR_ARCHIVE );

	controlScheme = Cvar_Get( "controlScheme", "0", CVAR_ARCHIVE );
	stickTurn = Cvar_Get( "stickTurn", "128", CVAR_ARCHIVE );
	stickMove = Cvar_Get( "stickMove", "128", CVAR_ARCHIVE );
	stickDeadBand = Cvar_Get( "stickDeadBand", "0.05", CVAR_ARCHIVE );
	rotorTurn = Cvar_Get( "rotorTurn", "50000", CVAR_ARCHIVE );
	tiltTurn = Cvar_Get( "tiltTurn", "0", CVAR_ARCHIVE );
	tiltMove = Cvar_Get( "tiltMove", "0", CVAR_ARCHIVE );
	tiltDeadBand = Cvar_Get( "tiltDeadBand", "0.08", CVAR_ARCHIVE );
	tiltAverages = Cvar_Get( "tiltAverages", "3", CVAR_ARCHIVE );
	centerSticks = Cvar_Get( "centerSticks", "1", CVAR_ARCHIVE );
	rampTurn = Cvar_Get( "rampTurn", "1", CVAR_ARCHIVE );

	music = Cvar_Get( "music", "1", CVAR_ARCHIVE );
	cropSprites = Cvar_Get( "cropSprites", "1", 0 );
	mapScale = Cvar_Get( "mapScale", "10", CVAR_ARCHIVE );
	drawControls = Cvar_Get( "drawControls", "1", CVAR_ARCHIVE );
	autoUse = Cvar_Get( "autoUse", "1", CVAR_ARCHIVE );
	statusBar = Cvar_Get( "statusBar", "1", CVAR_ARCHIVE );
	touchClick = Cvar_Get( "touchClick", "1", CVAR_ARCHIVE );
	messages = Cvar_Get( "messages", "1", CVAR_ARCHIVE );
	mapSelectY = Cvar_Get( "mapSelectY", "0", CVAR_ARCHIVE );
	miniNet = Cvar_Get( "miniNet", "1", CVAR_ARCHIVE );

	// multiplayer setup
	timeLimit = Cvar_Get( "timeLimit", "0", CVAR_ARCHIVE );
	fragLimit = Cvar_Get( "fragLimit", "5", CVAR_ARCHIVE );
	mpDeathmatch = Cvar_Get( "mpDeathmatch", "0", CVAR_ARCHIVE );
	mpDataset = Cvar_Get( "mpDataset", "0", CVAR_ARCHIVE );
	mpEpisode = Cvar_Get( "mpEpisode", "1", CVAR_ARCHIVE );
	mpSkill = Cvar_Get( "mpSkill", "1", CVAR_ARCHIVE );
	mpMap = Cvar_Get( "mpMap", "1", CVAR_ARCHIVE );
	mpExpansion = Cvar_Get( "mpExpansion", "0", CVAR_ARCHIVE | CVAR_NOSET );
	
	// debug tools
	showTilt = Cvar_Get( "showTilt", "-1", 0 );
	showTime = Cvar_Get( "showTime", "0", 0 );
	showNet = Cvar_Get( "showNet", "0", 0 );
	showSound = Cvar_Get( "showSound", "0", 0 );
	noBlend = Cvar_Get( "noBlend", "0", 0 );	// disable the damae blends for screenshots
	glfinish = Cvar_Get( "glfinish", "0", 0 );
	throttle = Cvar_Get( "throttle", "0", 0 );	// network packet throttle enable
	
	// Was origiinally 4. Trying different values to help internet play.
	netBuffer = Cvar_Get( "netBuffer", "12", 0 );	// max tics to buffer ahead
	
	// load the archived cvars
	Cmd_ExecuteFile( va( "%s/config.cfg", SysIphoneGetDocDir() ) );
	
	// start the intro music if it wasn't disabled with the music cvar
	iphonePlayMusic( "intro" );
//	iphonePlayMusic( "e1m1" );
	
	// these should get overwritten by the config loading
	memset( &playState, 0, sizeof( playState ) );
	playState.map.skill = 1;
	playState.map.episode = 1;
	playState.map.map = 1;
	HudSetForScheme( 0 );
	
	// load the binary config file
	FILE *f = fopen( va( "%s/binaryConfig.bin", SysIphoneGetDocDir() ), "rb" );
	if ( f ) {
		int version;
		
		version = 0;
		fread( &version, 1, sizeof( version ), f );
		if ( version != VERSION_BCONFIG ) {
			Com_Printf( "Binary config file bad version.\n" );
		} else {
			fread( &playState, 1, sizeof( playState ), f );
			fread( &huds, 1, sizeof( huds ), f );

			version = 0;
			fread( &version, 1, sizeof( version ), f );
			if ( version != VERSION_BCONFIG ) {
				Com_Error( "Binary config file bad trailing version.\n" );
			}
		}
		fclose( f );
	}

	
	Com_Printf( "startup time: %i msec\n", SysIphoneMilliseconds() - start );

	start = SysIphoneMilliseconds();
	
	// the texnums might have been different in the savegame
	HudSetTexnums();
	
	arialFontTexture = PK_FindTexture( "iphone/arialImageLAL.tga" );
	
	Com_Printf( "preloadBeforePlay(): %i msec\n", SysIphoneMilliseconds() - start );	

	// prBoom seems to draw the static pic screens without setting up 2D, causing
	// a bad first frame
	iphoneSet2D();	
	
	menuState = IPM_MAIN;
    lastState = IPM_MAIN;
	
#if 0
	// jump right to the save spot for debugging
	ResumeGame();
#endif
}