ref: f5b82c7a8618c716e77568b979057dfe699561d4
parent: c3562071ff239445538c5c9b5a6180067119cda3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 16 07:10:55 EDT 2023
MAX_SFX → MAX_SOUNDS; reclaim sfx from previous maps if no free ones
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -257,6 +257,7 @@
// precache sounds
memset(cl.sound_precache, 0, sizeof cl.sound_precache);
+ sfxbegin();
for (numsounds=1 ; ; numsounds++)
{
str = MSG_ReadString ();
--- a/fns.h
+++ b/fns.h
@@ -15,6 +15,7 @@
void startsfx(int, int, Sfx *, vec3_t, float, float);
void localsfx(char *);
void staticsfx(Sfx *, vec3_t, float, float);
+void sfxbegin(void);
void touchsfx(char *);
Sfx* precachesfx(char *);
void shutcd(void);
--- a/quakedef.h
+++ b/quakedef.h
@@ -6,10 +6,6 @@
#define VID_LockBuffer()
#define VID_UnlockBuffer()
-#ifdef __id386__
-#define UNALIGNED_OK // unset if unaligned accesses are not supported
-#endif
-
enum {
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
CACHE_SIZE = 32, // used to align key data structures
@@ -143,6 +139,7 @@
struct Sfx{
char s[Npath];
+ int map;
mem_user_t cu;
};
--- a/snd.c
+++ b/snd.c
@@ -54,7 +54,7 @@
int speed;
int width;
int stereo;
- int loop;
+ int loop;
byte data[1]; // variable sized
} sfxcache_t;
@@ -72,9 +72,9 @@
static vec3_t listener_forward;
static vec3_t listener_right;
static vec3_t listener_up;
-#define MAX_SFX 512
-static Sfx *known_sfx; // hunk allocated [MAX_SFX]
+static Sfx *known_sfx; // hunk allocated
static int num_sfx;
+static int map;
static cvar_t precache = {"precache", "1"};
static cvar_t loadas8bit = {"loadas8bit", "0"};
@@ -712,10 +712,8 @@
{
Sfx *sfx, *e;
- if(s == nil)
- fatal("findsfx: nil pointer\n");
if(strlen(s) >= Npath)
- fatal("findsfx: path too long %s", s);
+ Host_Error("findsfx: path too long %s", s);
sfx = known_sfx;
e = known_sfx + num_sfx;
while(sfx < e){
@@ -723,10 +721,20 @@
return sfx;
sfx++;
}
- if(num_sfx == MAX_SFX)
- fatal("findsfx: sfx list overflow");
+ if(num_sfx == MAX_SOUNDS){
+ sfx = known_sfx;
+ while(sfx < e){
+ if(sfx->map && sfx->map < map)
+ break;
+ sfx++;
+ }
+ if(sfx == e)
+ Host_Error("findsfx: sfx list overflow: %s", s);
+ if(Cache_Check(&sfx->cu))
+ Cache_Free(&sfx->cu);
+ }else
+ num_sfx++;
strcpy(sfx->s, s);
- num_sfx++;
return sfx;
}
@@ -749,6 +757,7 @@
if(afd < 0)
return nil;
sfx = findsfx(s);
+ sfx->map = map;
if(precache.value)
loadsfx(sfx);
return sfx;
@@ -825,6 +834,12 @@
}
void
+sfxbegin(void)
+{
+ map++;
+}
+
+void
shutsnd(void)
{
if(afd < 0)
@@ -855,8 +870,9 @@
nchan = Nchan;
chans = calloc(nchan, sizeof(*chans));
- known_sfx = Hunk_Alloc(MAX_SFX * sizeof *known_sfx);
+ known_sfx = Hunk_Alloc(MAX_SOUNDS * sizeof *known_sfx);
num_sfx = 0;
+
ambsfx[Ambwater] = precachesfx("ambience/water1.wav");
ambsfx[Ambsky] = precachesfx("ambience/wind2.wav");
stopallsfx();