shithub: choc

Download patch

ref: c736059090d59a4eda2c15f924c1a4dfbdd9e61d
parent: bfccd6699e16e5287b67621eec3fe7ed33add1d4
author: Simon Howard <[email protected]>
date: Sun Sep 11 16:25:56 EDT 2005

Second configuration file to allow chocolate doom-specific settings.
Adjust some existing command line logic (for graphics settings and
novert) to adjust for this.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 98

--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: d_main.c 94 2005-09-08 22:05:17Z fraggle $
+// $Id: d_main.c 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.14  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.13  2005/09/08 22:05:17  fraggle
 // Allow alt-tab away while running fullscreen
 //
@@ -77,7 +82,7 @@
 //-----------------------------------------------------------------------------
 
 
-static const char rcsid[] = "$Id: d_main.c 94 2005-09-08 22:05:17Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 98 2005-09-11 20:25:56Z fraggle $";
 
 #define	BGCOLOR		7
 #define	FGCOLOR		8
@@ -179,7 +184,6 @@
 
 char		wadfile[1024];		// primary wad file
 char		mapdir[1024];           // directory of development maps
-char		basedefault[1024];      // default file
 
 
 void D_CheckNetGame (void);
@@ -897,24 +901,6 @@
     puts(msg);
 }
 
-// Set the default location for the configuration file
-
-void SetBaseDefault(void)
-{
-    char *homedir;
-
-    homedir = getenv("HOME");
-
-    if (homedir != NULL)
-    {
-        sprintf(basedefault, "%s/.doomrc", homedir);
-    }
-    else
-    {
-        strcpy(basedefault, "default.cfg");
-    }
-}
-
 //
 // D_DoomMain
 //
@@ -939,13 +925,6 @@
     else if (M_CheckParm ("-deathmatch"))
 	deathmatch = 1;
 
-    if (M_CheckParm("-novert"))
-        novert = 1;
-
-    // set the location for default.cfg
-
-    SetBaseDefault();
-
     // print banner
 
     PrintBanner(PACKAGE_STRING);
@@ -953,6 +932,8 @@
     if (devparm)
 	printf(D_DEVSTR);
     
+#if 0
+    // BROKEN: -cdrom option
     if (M_CheckParm("-cdrom"))
     {
 	printf(D_CDROM);
@@ -962,7 +943,8 @@
 	mkdir("c:\\doomdata",0);
 #endif
 	strcpy (basedefault,"c:/doomdata/default.cfg");
-    }	
+    }
+#endif     
     
     // turbo option
     if ( (p=M_CheckParm ("-turbo")) )
@@ -1129,6 +1111,11 @@
 	}
 	autostart = true;
     }
+
+    if (M_CheckParm("-novert"))
+        novert = true;
+    else if (M_CheckParm("-nonovert"))
+        novert = false;
 
     printf ("===========================================================================\n");
 
--- a/src/doomstat.h
+++ b/src/doomstat.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: doomstat.h 69 2005-09-04 15:59:45Z fraggle $
+// $Id: doomstat.h 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -86,7 +86,7 @@
 extern  int		gamemap;
 
 // vertical movement from mouse/joystick disabled
-extern  boolean         novert;
+extern  int             novert;
 
 // Nightmare mode flag, single player.
 extern  boolean         respawnmonsters;
@@ -295,6 +295,11 @@
 //-----------------------------------------------------------------------------
 //
 // $Log$
+// Revision 1.7  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.6  2005/09/04 15:59:45  fraggle
 // 'novert' command line option to disable vertical mouse movement
 //
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: g_game.c 71 2005-09-04 18:44:23Z fraggle $
+// $Id: g_game.c 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.9  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.8  2005/09/04 18:44:23  fraggle
 // shut up compiler warnings
 //
@@ -56,7 +61,7 @@
 
 
 static const char
-rcsid[] = "$Id: g_game.c 71 2005-09-04 18:44:23Z fraggle $";
+rcsid[] = "$Id: g_game.c 98 2005-09-11 20:25:56Z fraggle $";
 
 #include <string.h>
 #include <stdlib.h>
@@ -203,8 +208,9 @@
 
 // fraggle: Disallow mouse and joystick movement to cause forward/backward
 // motion.  Specified with the '-novert' command line parameter.
+// This is an int to allow saving to config file
 
-boolean         novert;
+int             novert;
  
  
  
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_video.c 94 2005-09-08 22:05:17Z fraggle $
+// $Id: i_video.c 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.25  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.24  2005/09/08 22:05:17  fraggle
 // Allow alt-tab away while running fullscreen
 //
@@ -110,7 +115,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_video.c 94 2005-09-08 22:05:17Z fraggle $";
+rcsid[] = "$Id: i_video.c 98 2005-09-11 20:25:56Z fraggle $";
 
 #include <ctype.h>
 #include <SDL.h>
@@ -145,15 +150,21 @@
 
 static boolean native_surface;
 
-boolean fullscreen = true;
-boolean grabmouse = true;
+// Run in full screen mode?  (int type for config code)
+int fullscreen = true;
+
+// Grab the mouse? (int type for config code)
+int grabmouse = true;
+
+// Flag indicating whether the screen is currently visible:
+// when the screen isnt visible, don't render the screen
 boolean screenvisible;
 
 // Blocky mode,
-// replace each 320x200 pixel with multiply*multiply pixels.
+// replace each 320x200 pixel with screenmultiply*screenmultiply pixels.
 // According to Dave Taylor, it still is a bonehead thing
 // to use ....
-static int	multiply=1;
+int screenmultiply = 1;
 
 // disk image data and background overwritten by the disk to be
 // restored by EndRead
@@ -548,7 +559,7 @@
     
     }
 
-    if (multiply == 1 && !native_surface)
+    if (screenmultiply == 1 && !native_surface)
     {
         byte *bufp, *screenp;
         int y;
@@ -572,7 +583,7 @@
 
     // scales the screen size before blitting it
 
-    if (multiply == 2)
+    if (screenmultiply == 2)
     {
         byte *bufp, *screenp, *screenp2;
         int x, y;
@@ -680,14 +691,28 @@
 
     flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF;
 
-    // mouse grabbing, defaults to on
+    // mouse grabbing
 
-    grabmouse = !M_CheckParm("-nograbmouse");
+    if (M_CheckParm("-grabmouse"))
+    {
+        grabmouse = true;
+    }
+    else if (M_CheckParm("-nograbmouse"))
+    {
+        grabmouse = false;
+    }
 
     // default to fullscreen mode, allow override with command line
     // nofullscreen because we love prboom
 
-    fullscreen = !M_CheckParm("-window") && !M_CheckParm("-nofullscreen");
+    if (M_CheckParm("-window") || M_CheckParm("-nofullscreen"))
+    {
+        fullscreen = false;
+    }
+    else if (M_CheckParm("-fullscreen"))
+    {
+        fullscreen = true;
+    }
 
     if (fullscreen)
     {
@@ -696,13 +721,17 @@
 
     // scale-by-2 mode
  
-    if (M_CheckParm("-2"))
+    if (M_CheckParm("-1"))
     {
-        multiply = 2;
+        screenmultiply = 1;
     }
+    else if (M_CheckParm("-2"))
+    {
+        screenmultiply = 2;
+    }
 
-    windowwidth = SCREENWIDTH * multiply;
-    windowheight = SCREENHEIGHT * multiply;
+    windowwidth = SCREENWIDTH * screenmultiply;
+    windowheight = SCREENHEIGHT * screenmultiply;
 
     screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags);
 
@@ -718,7 +747,7 @@
 
     // Check if we have a native surface we can use
 
-    native_surface = multiply == 1 && screen->pitch == SCREENWIDTH;
+    native_surface = screenmultiply == 1 && screen->pitch == SCREENWIDTH;
 
     // If not, allocate a buffer and copy from that buffer to the 
     // screen when we do an update
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_video.h 97 2005-09-11 16:39:29Z fraggle $
+// $Id: i_video.h 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -58,6 +58,7 @@
 void I_EndRead (void);
 
 extern boolean screenvisible;
+extern int screenmultiply;
 extern boolean fullscreen;
 extern boolean grabmouse;
 
@@ -66,6 +67,11 @@
 //-----------------------------------------------------------------------------
 //
 // $Log$
+// Revision 1.6  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.5  2005/09/11 16:39:29  fraggle
 // Fix declaration of I_Sleep (not I_Delay) and move to right header
 //
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: m_misc.c 85 2005-09-07 21:40:11Z fraggle $
+// $Id: m_misc.c 98 2005-09-11 20:25:56Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -23,6 +23,11 @@
 //
 //
 // $Log$
+// Revision 1.9  2005/09/11 20:25:56  fraggle
+// Second configuration file to allow chocolate doom-specific settings.
+// Adjust some existing command line logic (for graphics settings and
+// novert) to adjust for this.
+//
 // Revision 1.8  2005/09/07 21:40:11  fraggle
 // Remove non-ANSI C headers and functions
 //
@@ -60,13 +65,24 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: m_misc.c 85 2005-09-07 21:40:11Z fraggle $";
+rcsid[] = "$Id: m_misc.c 98 2005-09-11 20:25:56Z fraggle $";
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 
+// for mkdir:
 
+#ifdef _WIN32
+#include <io.h>
+#else
+#include <sys/stat.h>
+#include <sys/types.h>
+#endif
+
+
+
+#include "config.h"
 #include "doomdef.h"
 
 #include "z_zone.h"
@@ -136,10 +152,6 @@
 //
 // M_WriteFile
 //
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
 boolean M_WriteFile(char const *name, void *source, int	length)
 {
     FILE *handle;
@@ -195,6 +207,9 @@
 //
 // DEFAULTS
 //
+
+// locations of config files
+
 int		usemouse;
 int		usejoystick;
 
@@ -258,8 +273,15 @@
     int         untranslated;
 } default_t;
 
-default_t	defaults[] =
+typedef struct
 {
+    default_t *defaults;
+    int        numdefaults;
+    char      *filename;
+} default_collection_t;
+
+static default_t	doom_defaults_list[] =
+{
     {"mouse_sensitivity",&mouseSensitivity, 5},
     {"sfx_volume",&snd_SfxVolume, 8},
     {"music_volume",&snd_MusicVolume, 8},
@@ -316,9 +338,26 @@
 
 };
 
-int	numdefaults;
-char*	defaultfile;
+static default_collection_t doom_defaults = 
+{
+    doom_defaults_list,
+    sizeof(doom_defaults_list) / sizeof(*doom_defaults_list),
+};
 
+static default_t extra_defaults_list[] = 
+{
+    {"grabmouse",   &grabmouse,      true},
+    {"fullscreen",  &fullscreen,     true},
+    {"screenmultiply", &screenmultiply, 1},
+    {"novert",      &novert,         false},
+};
+
+static default_collection_t extra_defaults =
+{
+    extra_defaults_list,
+    sizeof(extra_defaults_list) / sizeof(*extra_defaults_list),
+};
+
 static int scantokey[128] =
 {
     0  ,    27,     '1',    '2',    '3',    '4',    '5',    '6',
@@ -340,22 +379,20 @@
 };
 
 
-
-//
-// M_SaveDefaults
-//
-
-void M_SaveDefaults (void)
+static void SaveDefaultCollection(default_collection_t *collection)
 {
-    int		i;
-    int		v;
-    FILE*	f;
+    default_t *defaults;
+    int i;
+    int v;
+    FILE *f;
 	
-    f = fopen (defaultfile, "w");
+    f = fopen (collection->filename, "w");
     if (!f)
 	return; // can't write the file, but don't complain
+
+    defaults = collection->defaults;
 		
-    for (i=0 ; i<numdefaults ; i++)
+    for (i=0 ; i<collection->numdefaults ; i++)
     {
 	if (defaults[i].defaultvalue > -0xfff
 	    && defaults[i].defaultvalue < 0xfff)
@@ -401,13 +438,9 @@
     fclose (f);
 }
 
-
-//
-// M_LoadDefaults
-//
-
-void M_LoadDefaults (void)
+static void LoadDefaultCollection(default_collection_t *collection)
 {
+    default_t  *defaults = collection->defaults;
     int		i;
     int		len;
     FILE*	f;
@@ -416,26 +449,18 @@
     char*	newstring = "";
     int		parm;
     boolean	isstring;
-    
+
     // set everything to base values
-    numdefaults = sizeof(defaults)/sizeof(defaults[0]);
-    for (i=0 ; i<numdefaults ; i++)
+ 
+    for (i=0 ; i<collection->numdefaults ; i++)
     {
 	*((int *) defaults[i].location) = defaults[i].defaultvalue;
         defaults[i].untranslated = 0;
     }
-    // check for a custom default file
-    i = M_CheckParm ("-config");
-    if (i && i<myargc-1)
-    {
-	defaultfile = myargv[i+1];
-	printf ("	default file: %s\n",defaultfile);
-    }
-    else
-	defaultfile = basedefault;
-    
+
     // read the file in, overriding any set defaults
-    f = fopen (defaultfile, "r");
+    f = fopen(collection->filename, "r");
+
     if (f)
     {
 	while (!feof(f))
@@ -456,7 +481,7 @@
 		    sscanf(strparm+2, "%x", &parm);
 		else
 		    sscanf(strparm, "%i", &parm);
-		for (i=0 ; i<numdefaults ; i++)
+		for (i=0 ; i<collection->numdefaults ; i++)
 		    if (!strcmp(def, defaults[i].name))
 		    {
                         if (defaults[i].scantranslate)
@@ -479,6 +504,88 @@
 		
 	fclose (f);
     }
+}
+
+//
+// M_SaveDefaults
+//
+
+void M_SaveDefaults (void)
+{
+    SaveDefaultCollection(&doom_defaults);
+    SaveDefaultCollection(&extra_defaults);
+}
+
+
+//
+// M_LoadDefaults
+//
+
+void M_LoadDefaults (void)
+{
+    char *config_dir;
+    char *homedir;
+    int i;
+
+    homedir = getenv("HOME");
+
+    if (homedir != NULL)
+    {
+        // put all configuration in a config directory off the
+        // homedir
+
+        config_dir = malloc(strlen(homedir) + strlen(PACKAGE_TARNAME) + 5);
+
+        sprintf(config_dir, "%s/.%s/", homedir, PACKAGE_TARNAME);
+
+        // make the directory if it doesnt already exist
+#ifdef _WIN32
+        mkdir(config_dir);
+#else
+        mkdir(config_dir, 0755);
+#endif
+    }
+    else
+    {
+        config_dir = strdup("");
+    }
+
+    // check for a custom default file
+    i = M_CheckParm ("-config");
+
+    if (i && i<myargc-1)
+    {
+	doom_defaults.filename = myargv[i+1];
+	printf ("	default file: %s\n",doom_defaults.filename);
+    }
+    else
+    {
+        doom_defaults.filename = malloc(strlen(config_dir) + 10);
+        sprintf(doom_defaults.filename, "%sdefault.cfg", config_dir);
+    }
+
+    printf("saving config in %s\n", doom_defaults.filename);
+
+    i = M_CheckParm("-extraconfig");
+
+    if (i && i<myargc-1)
+    {
+        extra_defaults.filename = myargv[i+1];
+        printf("        extra configuration file: %s\n", 
+               extra_defaults.filename);
+    }
+    else
+    {
+        extra_defaults.filename 
+            = malloc(strlen(config_dir) + strlen(PACKAGE_TARNAME) + 10);
+        sprintf(extra_defaults.filename, "%s%s.cfg", 
+                config_dir, PACKAGE_TARNAME);
+    }
+
+    LoadDefaultCollection(&doom_defaults);
+    LoadDefaultCollection(&extra_defaults);
+
+    free(config_dir);
 }