foxygit / doom Log in
commit c33d1935292af81142783137e09dec828df298bc
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Sep 27 01:54:19 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Sep 27 01:54:19 2008 +0000

    Save Heretic configuration files on exit.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1294
---
 src/doom/d_main.c     |  1 +
 src/heretic/d_main.c  |  7 +++++--
 src/heretic/d_net.c   |  4 ++--
 src/heretic/doomdef.h |  4 ++--
 src/heretic/g_game.c  |  4 ++--
 src/m_config.c        | 32 +++++++++++++++++++++++---------
 src/m_config.h        |  1 +
 7 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 2da2efa8..67d4489d 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1011,6 +1011,7 @@ void D_DoomMain (void)

     // Load configuration files before initialising other subsystems.
     printf(DEH_String("M_LoadDefaults: Load system defaults.\n"));
+    M_SetConfigFilenames("default.cfg", PROGRAM_PREFIX "doom.cfg");
     D_BindVariables();
     M_LoadDefaults();

diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index aed34a30..3f96a867 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>

+#include "config.h"
 #include "ct_chat.h"
 #include "doomdef.h"
 #include "i_system.h"
@@ -652,7 +653,7 @@ void blitStartup(void)
     _setbkcolor(4);             // Red
     _settextcolor(14);          // Yellow
     _settextposition(3, 47);
-    _outtext(VERSION_TEXT);
+    _outtext(HERETIC_VERSION_TEXT);

     // Hide cursor
     _settextcursor(0x2000);
@@ -914,9 +915,11 @@ void D_DoomMain(void)

     // Load defaults before initing other systems
     printf("M_LoadDefaults: Load system defaults.\n");
+    D_BindVariables();
+    M_SetConfigFilenames("heretic.cfg", PROGRAM_PREFIX "heretic.cfg");
     M_LoadDefaults();

-    //I_AtExit(M_SaveDefaults, false);
+    I_AtExit(M_SaveDefaults, false);

     printf("Z_Init: Init zone memory allocation daemon.\n");
     Z_Init();
diff --git a/src/heretic/d_net.c b/src/heretic/d_net.c
index 4a67ad19..fb4240bc 100644
--- a/src/heretic/d_net.c
+++ b/src/heretic/d_net.c
@@ -521,7 +521,7 @@ void D_ArbitrateNetStart(void)
                 continue;
             if (netbuffer->checksum & NCMD_SETUP)
             {
-                if (netbuffer->player != VERSION)
+                if (netbuffer->player != HERETIC_VERSION)
                     I_Error
                         ("Different DOOM versions cannot play a net game!");
                 startskill = netbuffer->retransmitfrom & 15;
@@ -553,7 +553,7 @@ void D_ArbitrateNetStart(void)
                     netbuffer->retransmitfrom |= 0x10;
                 //netbuffer->starttic = startepisode * 64 + startmap;
                 netbuffer->starttic = (startepisode << 4) + startmap;
-                netbuffer->player = VERSION;
+                netbuffer->player = HERETIC_VERSION;
                 netbuffer->numtics = 0;
                 HSendPacket(i, NCMD_SETUP);
             }
diff --git a/src/heretic/doomdef.h b/src/heretic/doomdef.h
index 4aa4eee2..afadc19f 100644
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -34,8 +34,8 @@
 #endif
 #include <limits.h>

-#define VERSION 130
-#define VERSION_TEXT "v1.3"
+#define HERETIC_VERSION 130
+#define HERETIC_VERSION_TEXT "v1.3"

 // if rangecheck is undefined, most parameter validation debugging code
 // will not be compiled
diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index 70c19761..2e351fb4 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -1487,7 +1487,7 @@ void G_DoLoadGame(void)
     save_p = savebuffer + SAVESTRINGSIZE;
     // Skip the description field
     memset(vcheck, 0, sizeof(vcheck));
-    sprintf(vcheck, "version %i", VERSION);
+    sprintf(vcheck, "version %i", HERETIC_VERSION);
     if (strcmp((char *) save_p, vcheck) != 0)
     {                           // Bad version
         return;
@@ -1861,7 +1861,7 @@ void G_DoSaveGame(void)
     SV_Open(name);
     SV_Write(description, SAVESTRINGSIZE);
     memset(verString, 0, sizeof(verString));
-    sprintf(verString, "version %i", VERSION);
+    sprintf(verString, "version %i", HERETIC_VERSION);
     SV_Write(verString, VERSIONSIZE);
     SV_WriteByte(gameskill);
     SV_WriteByte(gameepisode);
diff --git a/src/m_config.c b/src/m_config.c
index a4451569..b036121c 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -51,6 +51,11 @@

 char *configdir;

+// Default filenames for configuration files.
+
+static char *default_main_config;
+static char *default_extra_config;
+
 typedef enum
 {
     DEFAULT_INT,
@@ -916,6 +921,14 @@ static void LoadDefaultCollection(default_collection_t *collection)
     fclose (f);
 }

+// Set the default filenames to use for configuration files.
+
+void M_SetConfigFilenames(char *main_config, char *extra_config)
+{
+    default_main_config = main_config;
+    default_extra_config = extra_config;
+}
+
 //
 // M_SaveDefaults
 //
@@ -940,8 +953,8 @@ void M_LoadDefaults (void)
     // @arg <file>
     // @vanilla
     //
-    // Load configuration from the specified file, instead of
-    // default.cfg.
+    // Load configuration from the specified file.  The default
+    // configuration file (for Doom) is named default.cfg.
     //

     i = M_CheckParm ("-config");
@@ -953,8 +966,9 @@ void M_LoadDefaults (void)
     }
     else
     {
-        doom_defaults.filename = malloc(strlen(configdir) + 20);
-        sprintf(doom_defaults.filename, "%sdefault.cfg", configdir);
+        doom_defaults.filename
+            = malloc(strlen(configdir) + strlen(default_main_config) + 1);
+        sprintf(doom_defaults.filename, "%s%s", configdir, default_main_config);
     }

     printf("saving config in %s\n", doom_defaults.filename);
@@ -962,8 +976,8 @@ void M_LoadDefaults (void)
     //!
     // @arg <file>
     //
-    // Load extra configuration from the specified file, instead
-    // of chocolate-doom.cfg.
+    // Load extra configuration from the specified file.  The default
+    // configuration file for Doom is named chocolate-doom.cfg.
     //

     i = M_CheckParm("-extraconfig");
@@ -977,9 +991,9 @@ void M_LoadDefaults (void)
     else
     {
         extra_defaults.filename
-            = malloc(strlen(configdir) + strlen(PACKAGE_TARNAME) + 10);
-        sprintf(extra_defaults.filename, "%s%s.cfg",
-                configdir, PACKAGE_TARNAME);
+            = malloc(strlen(configdir) + strlen(default_extra_config) + 1);
+        sprintf(extra_defaults.filename, "%s%s",
+                configdir, default_extra_config);
     }

     LoadDefaultCollection(&doom_defaults);
diff --git a/src/m_config.h b/src/m_config.h
index 252b0aef..16468b5d 100644
--- a/src/m_config.h
+++ b/src/m_config.h
@@ -32,6 +32,7 @@ void M_LoadDefaults(void);
 void M_SaveDefaults(void);
 void M_SetConfigDir(void);
 void M_BindVariable(char *name, void *variable);
+void M_SetConfigFilenames(char *main_config, char *extra_config);

 extern char *configdir;