dxx-rebirth/main/config.c

188 lines
5.7 KiB
C
Raw Normal View History

2006-03-20 17:12:09 +00:00
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* contains routine(s) to read in the configuration file which contains
* game configuration stuff like detail level, sound card, etc
*
*/
#ifdef HAVE_CONFIG_H
#include <conf.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#if !(defined(__APPLE__) && defined(__MACH__))
2006-03-20 17:12:09 +00:00
#include <physfs.h>
#else
#include <physfs/physfs.h>
#endif
#include "config.h"
2006-03-20 17:12:09 +00:00
#include "pstypes.h"
#include "game.h"
#include "menu.h"
#include "movie.h"
#include "digi.h"
#include "kconfig.h"
#include "palette.h"
#include "joy.h"
#include "songs.h"
#include "args.h"
#include "player.h"
#include "mission.h"
#include "physfsx.h"
struct Cfg GameCfg;
2006-03-20 17:12:09 +00:00
ubyte Config_joystick_sensitivity = 8;
static char *DigiVolumeStr = "DigiVolume";
static char *MidiVolumeStr = "MidiVolume";
static char *RedbookVolumeStr = "RedbookVolume";
static char *ReverseStereoStr = "ReverseStereo";
static char *GammaLevelStr = "GammaLevel";
static char *LastPlayerStr = "LastPlayer";
static char *LastMissionStr = "LastMission";
static char *ResolutionXStr="ResolutionX";
static char *ResolutionYStr="ResolutionY";
static char *AspectXStr="AspectX";
static char *AspectYStr="AspectY";
static char *WindowModeStr="WindowMode";
static char *TexFiltStr="TexFilt";
2006-03-20 17:12:09 +00:00
int ReadConfigFile()
{
PHYSFS_file *infile;
char line[80], *token, *value, *ptr;
// set defaults
GameCfg.DigiVolume = 8;
GameCfg.MidiVolume = 8;
GameCfg.RedbookVolume = 8;
GameCfg.ReverseStereo = 0;
GameCfg.GammaLevel = 0;
memset(GameCfg.LastPlayer,0,CALLSIGN_LEN+1);
memset(GameCfg.LastMission,0,MISSION_NAME_LEN+1);
GameCfg.ResolutionX = 640;
GameCfg.ResolutionY = 480;
GameCfg.AspectX = 3;
GameCfg.AspectY = 4;
GameCfg.WindowMode = 0;
GameCfg.TexFilt = 0;
2006-03-20 17:12:09 +00:00
infile = PHYSFSX_openReadBuffered("descent.cfg");
2006-03-20 17:12:09 +00:00
if (infile == NULL) {
return 1;
}
2006-03-20 17:12:09 +00:00
while (!PHYSFS_eof(infile))
{
memset(line, 0, 80);
PHYSFSX_gets(infile, line);
ptr = &(line[0]);
while (isspace(*ptr))
ptr++;
if (*ptr != '\0') {
token = strtok(ptr, "=");
value = strtok(NULL, "=");
if (!value)
value = "";
if (!strcmp(token, DigiVolumeStr))
GameCfg.DigiVolume = strtol(value, NULL, 10);
else if (!strcmp(token, MidiVolumeStr))
GameCfg.MidiVolume = strtol(value, NULL, 10);
else if (!strcmp(token, RedbookVolumeStr))
GameCfg.RedbookVolume = strtol(value, NULL, 10);
else if (!strcmp(token, ReverseStereoStr))
GameCfg.ReverseStereo = strtol(value, NULL, 10);
else if (!strcmp(token, GammaLevelStr)) {
GameCfg.GammaLevel = strtol(value, NULL, 10);
gr_palette_set_gamma( GameCfg.GammaLevel );
2006-03-20 17:12:09 +00:00
}
else if (!strcmp(token, LastPlayerStr)) {
2006-03-20 17:12:09 +00:00
char * p;
strncpy( GameCfg.LastPlayer, value, CALLSIGN_LEN );
p = strchr( GameCfg.LastPlayer, '\n');
2006-03-20 17:12:09 +00:00
if ( p ) *p = 0;
}
else if (!strcmp(token, LastMissionStr)) {
2006-03-20 17:12:09 +00:00
char * p;
strncpy( GameCfg.LastMission, value, MISSION_NAME_LEN );
p = strchr( GameCfg.LastMission, '\n');
2006-03-20 17:12:09 +00:00
if ( p ) *p = 0;
}
else if (!strcmp(token, ResolutionXStr))
GameCfg.ResolutionX = strtol(value, NULL, 10);
else if (!strcmp(token, ResolutionYStr))
GameCfg.ResolutionY = strtol(value, NULL, 10);
else if (!strcmp(token, AspectXStr))
GameCfg.AspectX = strtol(value, NULL, 10);
else if (!strcmp(token, AspectYStr))
GameCfg.AspectY = strtol(value, NULL, 10);
else if (!strcmp(token, WindowModeStr))
GameCfg.WindowMode = strtol(value, NULL, 10);
else if (!strcmp(token, TexFiltStr))
GameCfg.TexFilt = strtol(value, NULL, 10);
2006-03-20 17:12:09 +00:00
}
}
PHYSFS_close(infile);
if ( GameCfg.DigiVolume > 8 ) GameCfg.DigiVolume = 8;
if ( GameCfg.MidiVolume > 8 ) GameCfg.MidiVolume = 8;
if ( GameCfg.RedbookVolume > 8 ) GameCfg.RedbookVolume = 8;
2006-03-20 17:12:09 +00:00
digi_set_volume( (GameCfg.DigiVolume*32768)/8, (GameCfg.MidiVolume*128)/8 );
2006-03-20 17:12:09 +00:00
if (GameCfg.ResolutionX >= 320 && GameCfg.ResolutionY >= 200)
Game_screen_mode = SM(GameCfg.ResolutionX,GameCfg.ResolutionY);
2006-03-20 17:12:09 +00:00
return 0;
}
int WriteConfigFile()
{
PHYSFS_file *infile;
GameCfg.GammaLevel = gr_palette_get_gamma();
2006-03-20 17:12:09 +00:00
infile = PHYSFSX_openWriteBuffered("descent.cfg");
2006-03-20 17:12:09 +00:00
if (infile == NULL) {
return 1;
}
PHYSFSX_printf(infile, "%s=%d\n", DigiVolumeStr, GameCfg.DigiVolume);
PHYSFSX_printf(infile, "%s=%d\n", MidiVolumeStr, GameCfg.MidiVolume);
PHYSFSX_printf(infile, "%s=%d\n", RedbookVolumeStr, GameCfg.RedbookVolume);
PHYSFSX_printf(infile, "%s=%d\n", ReverseStereoStr, GameCfg.ReverseStereo);
PHYSFSX_printf(infile, "%s=%d\n", GammaLevelStr, GameCfg.GammaLevel);
PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, Players[Player_num].callsign );
PHYSFSX_printf(infile, "%s=%s\n", LastMissionStr, GameCfg.LastMission );
PHYSFSX_printf(infile, "%s=%i\n", ResolutionXStr, SM_W(Game_screen_mode));
PHYSFSX_printf(infile, "%s=%i\n", ResolutionYStr, SM_H(Game_screen_mode));
PHYSFSX_printf(infile, "%s=%i\n", AspectXStr, GameCfg.AspectX);
PHYSFSX_printf(infile, "%s=%i\n", AspectYStr, GameCfg.AspectY);
PHYSFSX_printf(infile, "%s=%i\n", WindowModeStr, GameCfg.WindowMode);
PHYSFSX_printf(infile, "%s=%i\n", TexFiltStr, GameCfg.TexFilt);
2006-03-20 17:12:09 +00:00
PHYSFS_close(infile);
return 0;
}