git: 9front

Download patch

ref: cf289710355d8fc0f8e2527355a00d9000e08607
parent: e64067a73ac9ae2154e01368f47924253a9b42c8
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Fri Jul 27 10:42:43 EDT 2012

doom: cleanup

--- a/sys/src/games/doom/d_main.c
+++ b/sys/src/games/doom/d_main.c
@@ -398,11 +398,8 @@
 	// Sound mixing for the buffer is snychronous.
 	I_UpdateSound();
 
-	// Synchronous sound output is explicitly called.
-#ifndef SNDINTR
 	// Update sound output.
 	I_SubmitSound();
-#endif
     }
 }
 
@@ -725,8 +722,8 @@
 //
 void D_DoomMain (void)
 {
-    int             p;
-    char                    file[256];
+    int		p;
+    char	file[256];
 
     FindResponseFile ();
 	
@@ -804,16 +801,6 @@
     if (devparm)
 	printf(D_DEVSTR);
     
-    if (M_CheckParm("-cdrom"))
-    {
-	I_Error("PORTME d_main.c M_CheckParm -cdrom");
-/*
-	printf(D_CDROM);
-	mkdir("c:\\doomdata",0);
-	strcpy (basedefault,"c:/doomdata/default.cfg");
-*/
-    }	
-    
     // turbo option
     if ( (p=M_CheckParm ("-turbo")) )
     {
@@ -1083,10 +1070,7 @@
     p = M_CheckParm ("-loadgame");
     if (p && p < myargc-1)
     {
-	if (M_CheckParm("-cdrom"))
-	    sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
-	else
-	    sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
+	sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
 	G_LoadGame (file);
     }
 	
--- a/sys/src/games/doom/doomdef.h
+++ b/sys/src/games/doom/doomdef.h
@@ -75,22 +75,10 @@
 // most parameter validation debugging code will not be compiled
 #define RANGECHECK
 
-// Do or do not use external soundserver.
-// The sndserver binary to be run separately
-//  has been introduced by Dave Taylor.
-// The integrated sound support is experimental,
-//  and unfinished. Default is synchronous.
-// Experimental asynchronous timer based is
-//  handled by SNDINTR. 
-//#define SNDSERV  1
-//#define SNDINTR  1
-
-
 // This one switches between MIT SHM (no proper mouse)
 // and XFree86 DGA (mickey sampling). The original
 // linuxdoom used SHM, which is default.
 //#define X11_DGA		1
-
 
 //
 // For resize of screen, at start of game.
--- a/sys/src/games/doom/g_game.c
+++ b/sys/src/games/doom/g_game.c
@@ -1252,16 +1252,13 @@
  
 void G_DoSaveGame (void) 
 { 
-    char	name[100]; 
+    char	name[256]; 
     char	name2[VERSIONSIZE]; 
     char*	description; 
     int		length; 
     int		i; 
 	
-    if (M_CheckParm("-cdrom"))
-	sprintf(name,"c:\\doomdata\\"SAVEGAMENAME"%d.dsg",savegameslot);
-    else
-	sprintf (name,SAVEGAMENAME"%d.dsg",savegameslot); 
+    sprintf (name,SAVEGAMENAME"%d.dsg",savegameslot); 
     description = savedescription; 
 	 
     save_p = savebuffer = screens[1]+0x4000; 
--- a/sys/src/games/doom/i_system.c
+++ b/sys/src/games/doom/i_system.c
@@ -113,7 +113,7 @@
 
 int I_FileExists (char *filepath)
 {
-	return (0 == access(filepath, AREAD));
+	return access(filepath, AEXIST) == 0;
 }
 
 int I_Open (char *filepath)
@@ -138,17 +138,26 @@
 
 char* I_IdentifyWAD(char *wadname)
 {
-	char path[1024];
+	static char path[1024];
+	char *home;
 
-	snprintf(path, sizeof path, "/sys/lib/doom/%s", wadname);
+	snprint(path, sizeof path, wadname);
 	if (I_FileExists (path))
 		return path;
 
-	snprintf(path, sizeof path, "/sys/games/lib/doom/%s", wadname);
+	if(home = getenv("home")){
+		snprintf(path, sizeof path, "%s/lib/doom/%s", home, wadname);
+		free(home);
+
+		if (I_FileExists (path))
+			return path;
+	}
+
+	snprintf(path, sizeof path, "/sys/lib/doom/%s", wadname);
 	if (I_FileExists (path))
 		return path;
 
-	snprintf(path, sizeof path, "%s/lib/doom/%s", getenv("home"), wadname);
+	snprintf(path, sizeof path, "/sys/games/lib/doom/%s", wadname);
 	if (I_FileExists (path))
 		return path;
 
--- a/sys/src/games/doom/m_menu.c
+++ b/sys/src/games/doom/m_menu.c
@@ -153,7 +153,7 @@
     short		numitems;	// # of menu items
     struct menu_s*	prevMenu;	// previous menu
     menuitem_t*		menuitems;	// menu items
-    void		(*routine)();	// draw routine
+    void		(*routine)(void);	// draw routine
     short		x;
     short		y;		// x,y of menu
     short		lastOn;		// last item user was on in menu
@@ -509,10 +509,7 @@
 	
     for (i = 0;i < load_end;i++)
     {
-	if (M_CheckParm("-cdrom"))
-	    sprintf(name,"c:\\doomdata\\"SAVEGAMENAME"%d.dsg",i);
-	else
-	    sprintf(name,SAVEGAMENAME"%d.dsg",i);
+        sprintf(name,SAVEGAMENAME"%d.dsg",i);
 
 	handle = I_Open (name);
 	if (handle == -1)
@@ -572,10 +569,7 @@
 {
     char    name[256];
 	
-    if (M_CheckParm("-cdrom"))
-	sprintf(name,"c:\\doomdata\\"SAVEGAMENAME"%d.dsg",choice);
-    else
-	sprintf(name,SAVEGAMENAME"%d.dsg",choice);
+    sprintf(name,SAVEGAMENAME"%d.dsg",choice);
     G_LoadGame (name);
     M_ClearMenus ();
 }
--- a/sys/src/games/doom/m_misc.c
+++ b/sys/src/games/doom/m_misc.c
@@ -97,10 +97,6 @@
 //
 // M_WriteFile
 //
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
 boolean
 M_WriteFile
 ( char const*	name,
@@ -109,7 +105,7 @@
 {
 	int fd, n;
 
-	if((fd = create(name, OWRITE | OTRUNC, 0666)) < 0)
+	if((fd = create(name, OWRITE, 0644)) < 0)
 		return false;
 	n = write(fd, source, length);
 	close(fd);
@@ -188,29 +184,14 @@
 // machine-independent sound params
 extern	int	numChannels;
 
-
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-extern char*	sndserver_filename;
-extern int	mb_used;
-#endif
-
-#ifdef LINUX
-char*		mousetype;
-char*		mousedev;
-#endif
-
 extern char*	chat_macros[];
 
-
-
 typedef struct
 {
     char*	name;
-    int*	location;
+    void*	location;
     int		defaultvalue;
-    int		scantranslate;		// PC scan code hack
-    int		untranslated;		// lousy hack
+    char*	defaultstring;
 } default_t;
 
 default_t	defaults[] =
@@ -233,17 +214,6 @@
     {"key_strafe",&key_strafe, KEY_RALT},
     {"key_speed",&key_speed, KEY_RSHIFT},
 
-// UNIX hack, to be removed. 
-#ifdef SNDSERV
-    {"sndserver", (int *) &sndserver_filename, (int) "sndserver"},
-    {"mb_used", &mb_used, 2},
-#endif
-
-#ifdef LINUX
-    {"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"},
-    {"mousetype", (int*)&mousetype, (int)"microsoft"},
-#endif
-
     {"use_mouse",&usemouse, 1},
     {"mouseb_fire",&mousebfire,0},
     {"mouseb_strafe",&mousebstrafe,1},
@@ -260,20 +230,18 @@
 
     {"snd_channels",&numChannels, 3},
 
-
-
     {"usegamma",&usegamma, 0},
 
-    {"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 },
-    {"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 },
-    {"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 },
-    {"chatmacro3", (int *) &chat_macros[3], (int) HUSTR_CHATMACRO3 },
-    {"chatmacro4", (int *) &chat_macros[4], (int) HUSTR_CHATMACRO4 },
-    {"chatmacro5", (int *) &chat_macros[5], (int) HUSTR_CHATMACRO5 },
-    {"chatmacro6", (int *) &chat_macros[6], (int) HUSTR_CHATMACRO6 },
-    {"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 },
-    {"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 },
-    {"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 }
+    {"chatmacro0",&chat_macros[0], 0, HUSTR_CHATMACRO0 },
+    {"chatmacro1",&chat_macros[1], 0, HUSTR_CHATMACRO1 },
+    {"chatmacro2",&chat_macros[2], 0, HUSTR_CHATMACRO2 },
+    {"chatmacro3",&chat_macros[3], 0, HUSTR_CHATMACRO3 },
+    {"chatmacro4",&chat_macros[4], 0, HUSTR_CHATMACRO4 },
+    {"chatmacro5",&chat_macros[5], 0, HUSTR_CHATMACRO5 },
+    {"chatmacro6",&chat_macros[6], 0, HUSTR_CHATMACRO6 },
+    {"chatmacro7",&chat_macros[7], 0, HUSTR_CHATMACRO7 },
+    {"chatmacro8",&chat_macros[8], 0, HUSTR_CHATMACRO8 },
+    {"chatmacro9",&chat_macros[9], 0, HUSTR_CHATMACRO9 }
 
 };
 
@@ -280,7 +248,6 @@
 int	numdefaults;
 char*	defaultfile;
 
-
 //
 // M_SaveDefaults
 //
@@ -287,7 +254,6 @@
 void M_SaveDefaults (void)
 {
     int		i;
-    int		v;
     FILE*	f;
 	
     f = fopen (defaultfile, "w");
@@ -296,14 +262,13 @@
 		
     for (i=0 ; i<numdefaults ; i++)
     {
-	if (defaults[i].defaultvalue > -0xfff
-	    && defaults[i].defaultvalue < 0xfff)
+	if (defaults[i].defaultstring == 0)
 	{
-	    v = *defaults[i].location;
-	    fprintf (f,"%s\t\t%i\n",defaults[i].name,v);
+	    fprintf (f,"%s\t\t%i\n",defaults[i].name,
+                *((int*)defaults[i].location));
 	} else {
 	    fprintf (f,"%s\t\t\"%s\"\n",defaults[i].name,
-		     * (char **) (defaults[i].location));
+                *((char**)defaults[i].location));
 	}
     }
 	
@@ -314,8 +279,6 @@
 //
 // M_LoadDefaults
 //
-extern byte	scantokey[128];
-
 void M_LoadDefaults (void)
 {
     int		i;
@@ -323,14 +286,16 @@
     FILE*	f;
     char	def[80];
     char	strparm[100];
-    char*	newstring = (char *)0;
+    char*	newstring;
     int		parm;
-    boolean	isstring;
     
     // set everything to base values
     numdefaults = sizeof(defaults)/sizeof(defaults[0]);
     for (i=0 ; i<numdefaults ; i++)
-	*defaults[i].location = defaults[i].defaultvalue;
+        if(defaults[i].defaultstring == 0)
+            *((int*)defaults[i].location) = defaults[i].defaultvalue;
+        else
+            *((char**)defaults[i].location) = defaults[i].defaultstring;
     
     // check for a custom default file
     i = M_CheckParm ("-config");
@@ -348,13 +313,13 @@
     {
 	while (!feof(f))
 	{
-	    isstring = false;
 	    if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
 	    {
+                parm = 0;
+                newstring = 0;
 		if (strparm[0] == '"')
 		{
 		    // get a string default
-		    isstring = true;
 		    len = strlen(strparm);
 		    newstring = (char *) malloc(len);
 		    strparm[len-1] = 0;
@@ -367,11 +332,10 @@
 		for (i=0 ; i<numdefaults ; i++)
 		    if (!strcmp(def, defaults[i].name))
 		    {
-			if (!isstring)
-			    *defaults[i].location = parm;
-			else
-			    *defaults[i].location =
-				(int) newstring;
+			if (defaults[i].defaultstring == 0)
+			    *((int*)defaults[i].location) = parm;
+			else if(newstring)
+			    *((char**)defaults[i].location) = newstring;
 			break;
 		    }
 	    }
@@ -496,8 +460,8 @@
     {
 	lbmname[4] = i/10 + '0';
 	lbmname[5] = i%10 + '0';
-	if (access(lbmname,0) == -1)
-	    break;	// file doesn't exist
+	if (!I_FileExists (lbmname))
+	    break;
     }
     if (i==100)
 	I_Error ("M_ScreenShot: Couldn't create a PCX");
--- a/sys/src/games/doom/s_sound.c
+++ b/sys/src/games/doom/s_sound.c
@@ -123,10 +123,6 @@
 // number of channels available
 int			numChannels;	
 
-static int		nextcleanup;
-
-
-
 //
 // Internals.
 //
@@ -180,10 +176,6 @@
   
   // no sounds are playing, and they are not mus_paused
   mus_paused = 0;
-
-  // Note that sounds have not been cached (yet).
-  for (i=1 ; i<NUMSFX ; i++)
-    S_sfx[i].lumpnum = S_sfx[i].usefulness = -1;
 }
 
 
@@ -238,8 +230,6 @@
   //      mnum -= mus_e3m9;
   
   S_ChangeMusic(mnum, true);
-  
-  nextcleanup = 15;
 }	
 
 
@@ -263,11 +253,6 @@
   mobj_t*	origin = (mobj_t *) origin_p;
   
   
-  // Debug.
-  /*fprintf( stderr,
-  	   "S_StartSoundAtVolume: playing sound %d (%s)\n",
-  	   sfx_id, S_sfx[sfx_id].name );*/
-  
   // check for bogus sound #
   if (sfx_id < 1 || sfx_id > NUMSFX)
     I_Error("Bad sfx #: %d", sfx_id);
@@ -307,7 +292,7 @@
     if ( origin->x == players[consoleplayer].mo->x
 	 && origin->y == players[consoleplayer].mo->y)
     {	
-      sep 	= NORM_SEP;
+      sep = NORM_SEP;
     }
     
     if (!rc)
@@ -349,42 +334,9 @@
   if (cnum<0)
     return;
 
-  //
-  // This is supposed to handle the loading/caching.
-  // For some odd reason, the caching is done nearly
-  //  each time the sound is needed?
-  //
-  
-  // get lumpnum if necessary
-  if (sfx->lumpnum < 0)
-    sfx->lumpnum = I_GetSfxLumpNum(sfx);
-
-#ifndef SNDSRV
-  // cache data if necessary
-  if (!sfx->data)
-  {
-/* PORTME 9DOOM uncomment this back in later
-    fprintf( stderr,
-	     "S_StartSoundAtVolume: 16bit and not pre-cached - wtf?\n");
-*/
-
-    // DOS remains, 8bit handling
-    //sfx->data = (void *) W_CacheLumpNum(sfx->lumpnum, PU_MUSIC);
-    // fprintf( stderr,
-    //	     "S_StartSoundAtVolume: loading %d (lump %d) : 0x%x\n",
-    //       sfx_id, sfx->lumpnum, (int)sfx->data );
-    
-  }
-#endif
-  
-  // increase the usefulness
-  if (sfx->usefulness++ < 0)
-    sfx->usefulness = 1;
-  
   // Assigns the handle to one of the channels in the
   //  mix/output buffer.
   channels[cnum].handle = I_StartSound(sfx_id,
-				       /*sfx->data,*/
 				       volume,
 				       sep,
 				       pitch,
@@ -524,29 +476,7 @@
     channel_t*	c;
     
     mobj_t*	listener = (mobj_t*)listener_p;
-
-
     
-    // Clean up unused data.
-    // This is currently not done for 16bit (sounds cached static).
-    // DOS 8bit remains. 
-    /*if (gametic > nextcleanup)
-    {
-	for (i=1 ; i<NUMSFX ; i++)
-	{
-	    if (S_sfx[i].usefulness < 1
-		&& S_sfx[i].usefulness > -1)
-	    {
-		if (--S_sfx[i].usefulness == -1)
-		{
-		    Z_ChangeTag(S_sfx[i].data, PU_CACHE);
-		    S_sfx[i].data = 0;
-		}
-	    }
-	}
-	nextcleanup = gametic + 15;
-    }*/
-    
     for (cnum=0 ; cnum<numChannels ; cnum++)
     {
 	c = &channels[cnum];
@@ -731,9 +661,6 @@
 		break;
 	    }
 	}
-	
-	// degrade usefulness of sound data
-	c->sfxinfo->usefulness--;
 
 	c->sfxinfo = 0;
     }
--- a/sys/src/games/doom/sounds.h
+++ b/sys/src/games/doom/sounds.h
@@ -51,14 +51,6 @@
 
     // sound data
     void*	data;
-
-    // this is checked every second to see if sound
-    // can be thrown out (if 0, then decrement, if -1,
-    // then throw out, if > 0, then it is in use)
-    int		usefulness;
-
-    // lump number of sfx
-    int		lumpnum;		
 };
 
 
--