shithub: qk2

Download patch

ref: a6d435a131bd7d0828a26257d89ef92223ac07eb
parent: 1c9d770ddfc094a0f4d41843cb94d9649fb83544
author: qwx <[email protected]>
date: Tue Jul 20 17:34:50 EDT 2021

cd: fix suspending playback, improper postnote usage, and stop on disconnect

--- a/cd.c
+++ b/cd.c
@@ -10,7 +10,7 @@
 static double cdvol;
 static int ntrk, trk, chtrk;
 static char trtype;
-static int ctid = -1;
+static int cpid = -1;
 static Reprog *pat;
 static cvar_t *ccdvol;
 
@@ -93,7 +93,7 @@
 void
 CDAudio_Play(int nt, qboolean loop)
 {
-	if(ctid < 0)
+	if(cpid < 0)
 		return;
 	nt -= 1;	/* d001 was assumed part of the track list */
 	if(nt < 1 || nt > ntrk){
@@ -103,6 +103,7 @@
 
 	chtrk = nt;
 	cdloop = loop;
+	cdvol = ccdvol->value;
 	if(cdvol > 0)
 		cdread = 1;
 }
@@ -158,8 +159,10 @@
 void
 CDAudio_Update(void)
 {
-	if(ctid < 0)
+	if(cpid < 0)
 		return;
+	if(ccdvol->value <= 0.0 || cdread == 0)
+		return;
 	cdvol = ccdvol->value;
 	cdread = cdvol > 0.0;
 }
@@ -167,12 +170,15 @@
 int
 CDAudio_Init(void)
 {
+	int tid;
+
 	pat = regcomp("[au][0-9][0-9][0-9]");
 	if(cdinfo() < 0)
 		return -1;
 	ccdvol = Cvar_Get("cdvol", "1", CVAR_ARCHIVE);
-	if((ctid = proccreate(cproc, nil, 16384)) < 0)
+	if((tid = proccreate(cproc, nil, 16384)) < 0)
 		sysfatal("proccreate: %r");
+	cpid = threadpid(tid);
 	Cmd_AddCommand("cd", CD_f);
 
 	Com_Printf("CD Audio Initialized\n");
@@ -182,12 +188,13 @@
 void
 CDAudio_Shutdown(void)
 {
-	if(ctid < 0)
+	if(cpid < 0)
 		return;
 
 	CDAudio_Stop();
-	postnote(PNPROC, ctid, "shutdown");
-	ctid = -1;
+	if(postnote(PNPROC, cpid, "die die die") < 0)
+		fprint(2, "CDAudio_Shutdown: postnote: %r\n");
+	cpid = -1;
 	free(pat);
 	pat = nil;
 	cdread = cdloop = 0;
--- a/cl_main.c
+++ b/cl_main.c
@@ -599,6 +599,8 @@
 
 	M_ForceMenuOff(false);
 
+	CDAudio_Stop();
+
 	cls.connect_time = 0;
 
 	SCR_StopCinematic ();