shithub: qk1

Download patch

ref: 58db468b6f94b65c20fda728e1707ce8852634f9
parent: 7e09171671af0be6d58bdbb1f9db173bbeeff62c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Dec 24 21:36:06 EST 2023

recycle audio buffers far more often

--- a/cl_parse.c
+++ b/cl_parse.c
@@ -259,6 +259,7 @@
 		strcpy (sound_precache[numsounds], str);
 		touchsfx (str);
 	}
+	sfxend();
 
 	// now we try to load everything else until a cache allocation fails
 	for (i=1 ; i<nummodels ; i++)
@@ -277,7 +278,6 @@
 		cl.sound_precache[i] = precachesfx (sound_precache[i]);
 		CL_KeepaliveMessage ();
 	}
-
 
 	// local state
 	cl_entities[0].model = cl.worldmodel = cl.model_precache[1];
--- a/fns.h
+++ b/fns.h
@@ -16,6 +16,7 @@
 void	localsfx(char *);
 void	staticsfx(Sfx *, vec3_t, float, float);
 void	sfxbegin(void);
+void	sfxend(void);
 void	touchsfx(char *);
 Sfx*	precachesfx(char *);
 void	shutcd(void);
--- a/snd.c
+++ b/snd.c
@@ -643,6 +643,20 @@
 	map++;
 }
 
+void
+sfxend(void)
+{
+	Sfx *sfx;
+	int i;
+
+	for(i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++){
+		if(sfx->map >= map || sfx == ambsfx[Ambsky] || sfx == ambsfx[Ambwater])
+			continue;
+		if(Cache_Check(&sfx->cu) != nil)
+			Cache_Free(&sfx->cu);
+	}
+}
+
 int
 initsnd(void)
 {
--- a/unix/snd_openal.c
+++ b/unix/snd_openal.c
@@ -109,7 +109,7 @@
 			return c;
 		if(stopped == nil){
 			alGetSourcei(c->src, AL_SOURCE_STATE, &state);
-			if(!ALERR() && state == AL_STOPPED)
+			if(!ALERR() && state != AL_PLAYING)
 				stopped = c;
 		}
 	}
@@ -140,7 +140,6 @@
 static void
 delchan(alchan_t *c)
 {
-	alSourceStop(c->src); ALERR();
 	alDeleteSources(1, &c->src); ALERR();
 	free(c);
 }
@@ -174,6 +173,7 @@
 		if((b = Cache_Check(&sfx->cu)) != nil){
 			alDeleteBuffers(1, &b->buf); ALERR();
 			Cache_Free(&sfx->cu);
+			sfx->map = map;
 		}
 	}else
 		num_sfx++;
@@ -595,8 +595,25 @@
 sfxbegin(void)
 {
 	map++;
+}
+
+void
+sfxend(void)
+{
+	Sfx *sfx;
+	alsfx_t *b;
+	int i;
+
 	ambsfx[Ambwater] = precachesfx("ambience/water1.wav");
 	ambsfx[Ambsky] = precachesfx("ambience/wind2.wav");
+	for(i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++){
+		if(sfx->map >= map || sfx == ambsfx[Ambsky] || sfx == ambsfx[Ambwater])
+			continue;
+		if((b = Cache_Check(&sfx->cu)) != nil){
+			alDeleteBuffers(1, &b->buf); ALERR();
+			Cache_Free(&sfx->cu);
+		}
+	}
 }
 
 int