ref: 3a41ade9fab0556d0d025c0b0e81834436a4f2e8
parent: 0a5d1795ce8fe46e20627f8a7b4ba348f2ec400e
author: Simon Howard <fraggle@gmail.com>
date: Mon Sep 8 13:55:12 EDT 2008
Remove i_system.c dependency on doom/ code and add a generic I_AtExit() API for scheduling functions to call on quit. Subversion-branch: /branches/raven-branch Subversion-revision: 1216
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -950,6 +950,9 @@
printf (DEH_String("M_LoadDefaults: Load system defaults.\n"));
M_LoadDefaults (); // load before initing other systems
+ // Save configuration at exit.
+ I_AtExit(M_SaveDefaults, false);
+
printf (DEH_String("W_Init: Init WADfiles.\n"));
D_AddFile(iwadfile);
@@ -1192,6 +1195,8 @@
}
}
+
+ I_AtExit((atexit_func_t) G_CheckDemoStatus, true);
// Generate the WAD hash table. Speed things up a bit.
--- a/src/doom/d_net.c
+++ b/src/doom/d_net.c
@@ -237,6 +237,10 @@
int i;
int num_players;
+ // Call D_QuitNetGame on exit
+
+ I_AtExit(D_QuitNetGame, true);
+
// default values for single player
consoleplayer = 0;
--- a/src/doom/s_sound.c
+++ b/src/doom/s_sound.c
@@ -147,6 +147,8 @@
{
S_sfx[i].lumpnum = S_sfx[i].usefulness = -1;
}
+
+ I_AtExit(S_Shutdown, true);
}
void S_Shutdown(void)
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -40,7 +40,6 @@
#include "deh_str.h"
#include "doomtype.h"
-#include "doomstat.h"
#include "m_argv.h"
#include "m_config.h"
#include "m_misc.h"
@@ -47,15 +46,10 @@
#include "i_joystick.h"
#include "i_timer.h"
#include "i_video.h"
-#include "s_sound.h"
-#include "d_net.h"
-#include "g_game.h"
-
#include "i_system.h"
#include "txt_main.h"
-
#include "w_wad.h"
#include "z_zone.h"
@@ -62,6 +56,29 @@
int mb_used = 16;
int show_endoom = 1;
+typedef struct atexit_listentry_s atexit_listentry_t;
+
+struct atexit_listentry_s
+{
+ atexit_func_t func;
+ boolean run_on_error;
+ atexit_listentry_t *next;
+};
+
+static atexit_listentry_t *exit_funcs = NULL;
+
+void I_AtExit(atexit_func_t func, boolean run_on_error)
+{
+ atexit_listentry_t *entry;
+
+ entry = malloc(sizeof(*entry));
+
+ entry->func = func;
+ entry->run_on_error = run_on_error;
+ entry->next = exit_funcs;
+ exit_funcs = entry;
+}
+
// Tactile feedback function, probably used for the Logitech Cyberman
void I_Tactile(int on, int off, int total)
@@ -178,6 +195,19 @@
void I_Quit (void)
{
+ atexit_listentry_t *entry;
+
+ // Run through all exit functions
+
+ entry = exit_funcs;
+
+ while (entry != NULL)
+ {
+ entry->func();
+ entry = entry->next;
+ }
+
+/*
D_QuitNetGame ();
G_CheckDemoStatus();
S_Shutdown();
@@ -188,8 +218,9 @@
}
I_ShutdownGraphics();
+ */
- if (show_endoom && !testcontrols && !screensaver_mode)
+ if (show_endoom && !screensaver_mode && !M_CheckParm("-testcontrols"))
{
I_Endoom();
}
@@ -211,7 +242,8 @@
void I_Error (char *error, ...)
{
- va_list argptr;
+ va_list argptr;
+ atexit_listentry_t *entry;
if (already_quitting)
{
@@ -233,6 +265,19 @@
// Shutdown. Here might be other errors.
+ entry = exit_funcs;
+
+ while (entry != NULL)
+ {
+ if (entry->run_on_error)
+ {
+ entry->func();
+ }
+
+ entry = entry->next;
+ }
+
+ /*
if (demorecording)
{
G_CheckDemoStatus();
@@ -241,6 +286,7 @@
D_QuitNetGame ();
I_ShutdownGraphics();
S_Shutdown();
+ */
#ifdef _WIN32
// On Windows, pop up a dialog box with the error message.
--- a/src/i_system.h
+++ b/src/i_system.h
@@ -32,6 +32,7 @@
#include "d_event.h"
+typedef void (*atexit_func_t)(void);
// Called by DoomMain.
void I_Init (void);
@@ -86,6 +87,11 @@
void I_Error (char *error, ...);
+// Schedule a function to be called when the program exits.
+// If run_if_error is true, the function is called if the exit
+// is due to an error (I_Error)
+
+void I_AtExit(atexit_func_t func, boolean run_if_error);
#endif
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1638,5 +1638,9 @@
}
initialised = true;
+
+ // Call I_ShutdownGraphics on quit
+
+ I_AtExit(I_ShutdownGraphics, true);
}