ref: a0e7f7500b6b252fa15b28d0d0810a881e4766e2
parent: 2e939eac354f07bd26437ccce0fb446c6bbc3b7e
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sat Dec 30 19:53:53 EST 2023
add -N to disable optional modules (only "cd" and "snd" for now)
--- a/cd.c
+++ b/cd.c
@@ -3,7 +3,7 @@
cvar_t bgmvolume = {"bgmvolume", "0.5", true};
int cdtrk = 0, cdntrk = 0;
-bool cdloop = false;
+bool cdloop = false, cdenabled;
void
cdcmd(void)
@@ -10,6 +10,11 @@
{
char *c;
bool loop;
+
+ if(!cdenabled){
+ Con_Printf("cd disabled\n");
+ return;
+ }
if(Cmd_Argc() < 2){
usage:
--- a/cd_plan9.c
+++ b/cd_plan9.c
@@ -85,7 +85,7 @@
void
stepcd(void)
{
- if(bgmvolume.value <= 0.0 || cdread == 0)
+ if(!cdenabled || bgmvolume.value <= 0.0 || cdread == 0)
return;
cdread = bgmvolume.value > 0.0;
}
@@ -138,6 +138,12 @@
int
initcd(void)
{
+ Cvar_RegisterVariable(&bgmvolume);
+ Cmd_AddCommand("cd", cdcmd);
+
+ if(!(cdenabled = !isdisabled("cd")))
+ return 0;
+
if(cdinfo() < 0){
Con_DPrintf("cdinfo: %r\n");
return -1;
@@ -144,7 +150,5 @@
}
if(proccreate(cproc, nil, 16384) < 0)
sysfatal("proccreate: %r");
- Cvar_RegisterVariable(&bgmvolume);
- Cmd_AddCommand("cd", cdcmd);
return 0;
}
--- a/dat.h
+++ b/dat.h
@@ -59,7 +59,6 @@
extern cvar_t bgmvolume;
extern int cdtrk, cdntrk;
-extern bool cdloop;
-
+extern bool cdloop, cdenabled;
extern int debug;
--- a/quakedef.h
+++ b/quakedef.h
@@ -181,6 +181,8 @@
extern double realtime; // not bounded in any way, changed at
// start of every frame, never reset
+bool isdisabled(char *s);
+
#define opaque(p) ((p) != 0)
extern pixel_t q1pal[256];
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -657,12 +657,6 @@
{
int i, j, *p;
- if(sndopen() != 0)
- return -1;
- ainit = 1;
- for(p=scalt[1], i=8; i<8*nelem(scalt); i+=8)
- for(j=0; j<256; j++)
- *p++ = (char)j * i;
Cmd_AddCommand("play", playsfx);
Cmd_AddCommand("playvol", playvolsfx);
Cmd_AddCommand("stopsound", stopallsfx);
@@ -673,12 +667,23 @@
Cvar_RegisterVariable(&ambient_level);
Cvar_RegisterVariable(&ambient_fade);
- chans = calloc(Nchan, sizeof(*chans));
- known_sfx = Hunk_Alloc(MAX_SOUNDS * sizeof *known_sfx);
- num_sfx = 0;
+ if(!isdisabled("snd")){
+ if(sndopen() != 0)
+ return -1;
+ ainit = 1;
- ambsfx[Ambwater] = precachesfx("ambience/water1.wav");
- ambsfx[Ambsky] = precachesfx("ambience/wind2.wav");
- stopallsfx();
+ for(p=scalt[1], i=8; i<8*nelem(scalt); i+=8){
+ for(j=0; j<256; j++)
+ *p++ = (char)j * i;
+ }
+
+ chans = calloc(Nchan, sizeof(*chans));
+ 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();
+ }
return 0;
}
--- a/snd_openal.c
+++ b/snd_openal.c
@@ -663,6 +663,9 @@
Sfx *sfx;
int i;
+ if(dev == nil)
+ return;
+
ambsfx[Ambwater] = precachesfx("ambience/water1.wav");
ambsfx[Ambsky] = precachesfx("ambience/wind2.wav");
for(i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++){
@@ -678,6 +681,9 @@
void
stepcd(void)
{
+ if(dev == nil || !cdenabled)
+ return;
+
if(track.stop)
stopcd();
else if(track.playing){
@@ -748,6 +754,9 @@
pid_t pid;
FILE *f;
+ if(dev == nil || !cdenabled)
+ return;
+
stopcd();
if(qalBufferCallbackSOFT == nil)
return;
@@ -823,13 +832,19 @@
void
resumecd(void)
{
- alSourcePlay(track.src); ALERR();
+ if(track.playing){
+ alSourcePlay(track.src);
+ ALERR();
+ }
}
void
pausecd(void)
{
- alSourcePause(track.src); ALERR();
+ if(track.playing){
+ alSourcePause(track.src);
+ ALERR();
+ }
}
int
@@ -865,9 +880,6 @@
int
initsnd(void)
{
- s_al_dev.cb = s_al_hrtf.cb = alvarcb;
- s_al_doppler_factor.cb = aldopplercb;
-
Cvar_RegisterVariable(&volume);
Cvar_RegisterVariable(&bgmvolume);
Cvar_RegisterVariable(&ambient_level);
@@ -881,9 +893,14 @@
Cmd_AddCommand("soundlist", sfxlist);
Cmd_AddCommand("cd", cdcmd);
- alinit(nil);
- known_sfx = Hunk_Alloc(MAX_SOUNDS * sizeof *known_sfx);
- num_sfx = 0;
+ if(!isdisabled("snd")){
+ s_al_dev.cb = s_al_hrtf.cb = alvarcb;
+ s_al_doppler_factor.cb = aldopplercb;
+ alinit(nil);
+ known_sfx = Hunk_Alloc(MAX_SOUNDS * sizeof *known_sfx);
+ num_sfx = 0;
+ cdenabled = !isdisabled("cd");
+ }
return 0;
}
--- a/sys_plan9.c
+++ b/sys_plan9.c
@@ -5,7 +5,21 @@
char *netmtpt = "/net";
char *game;
int debug;
+static const char *disabled[32];
+static int ndisabled;
+bool
+isdisabled(char *s)
+{
+ int i;
+
+ for(i = 0; i < ndisabled; i++){
+ if(strcmp(disabled[i], s) == 0)
+ return true;
+ }
+ return false;
+}
+
int
sys_mkdir(char *path)
{
@@ -110,7 +124,7 @@
static void
usage(void)
{
- fprint(2, "usage: %s [-d] [-g game] [-m kB] [-x netmtpt]\n", argv0);
+ fprint(2, "usage: %s [-d] [-g game] [-m kB] [-x netmtpt] [-N cd|snd]\n", argv0);
exits("usage");
}
@@ -137,6 +151,10 @@
break;
case 'x':
netmtpt = EARGF(usage());
+ break;
+ case 'N':
+ if(ndisabled < nelem(disabled))
+ disabled[ndisabled++] = EARGF(usage());
break;
default: usage();
}ARGEND
--- a/sys_unix.c
+++ b/sys_unix.c
@@ -8,7 +8,21 @@
char *game;
int debug;
char lasterr[256] = {0};
+static const char *disabled[32];
+static int ndisabled;
+bool
+isdisabled(char *s)
+{
+ int i;
+
+ for(i = 0; i < ndisabled; i++){
+ if(strcmp(disabled[i], s) == 0)
+ return true;
+ }
+ return false;
+}
+
char *
lerr(void)
{
@@ -113,10 +127,14 @@
parg_init(&ps);
nargs = 0;
- while((c = parg_getopt(&ps, argc, argv, "Ddg:")) >= 0){
+ while((c = parg_getopt(&ps, argc, argv, "Ddg:N:")) >= 0){
switch(c){
case 1:
argv[nargs++] = (char*)ps.optarg;
+ break;
+ case 'N':
+ if(ndisabled < nelem(disabled))
+ disabled[ndisabled++] = ps.optarg;
break;
case 'D':
debug++;