ref: 1c9458bd4fb64dcc74c08041c59a5088ccee9dd8
parent: 54bb991f273c0f4daff122226eec8a11e3f894be
author: Jacob Moody <[email protected]>
date: Mon Jan 23 21:24:26 EST 2023
simplify process management and bring in better clip check from heretic
--- a/i_main.c
+++ b/i_main.c
@@ -9,5 +9,6 @@
{
myargc = argc;
myargv = argv;
+ rfork(RFNOTEG);
H2_Main ();
}
--- a/i_sound.c
+++ b/i_sound.c
@@ -77,7 +77,6 @@
#define BUF_LEN (256 * 2 * 4)
static int audiofd;
-static int audiopid = -1;
static QLock audiolk;
@@ -93,13 +92,14 @@
SAMPLE_TYPE *begin;
SAMPLE_TYPE *end;
unsigned int sample;
- register int dl;
- register int dr;
+ register int dl, ml;
+ register int dr, mr;
int i;
end = (SAMPLE_TYPE *) (buf + BUF_LEN);
cend = channel + CHAN_COUNT;
+ procsetname("hexen audioproc");
for(;;){
memset(buf, 0, sizeof buf);
if(mpfd[0]>=0 && !mus_paused && readn(mpfd[0], buf, sizeof buf) < 0){
@@ -138,16 +138,19 @@
}
qunlock(&audiolk);
for(i=0; i < TARGET_RATE/SAMPLE_RATE; i++){
- if (dl > 0x7fff)
- dl = 0x7fff;
- else if (dl < -0x8000)
- dl = -0x8000;
- if (dr > 0x7fff)
- dr = 0x7fff;
- else if (dr < -0x8000)
- dr = -0x8000;
- *begin++ += dl;
- *begin++ += dr;
+ ml = dl + *begin;
+ if (ml > 0x7fff)
+ ml = 0x7fff;
+ else if (ml < -0x8000)
+ ml = -0x8000;
+ *begin++ = ml;
+
+ mr = dr + *begin;
+ if (mr > 0x7fff)
+ mr = 0x7fff;
+ else if (mr < -0x8000)
+ mr = -0x8000;
+ *begin++ = mr;
}
}
write(audiofd, buf, BUF_LEN);
@@ -318,7 +321,7 @@
snd_SfxAvail = true;
- if((audiopid = rfork(RFPROC|RFMEM)) == 0){
+ if(rfork(RFPROC|RFMEM) == 0){
audioproc();
exits(nil);
}
@@ -329,10 +332,6 @@
{
snd_SfxAvail = false;
- if(audiopid != -1){
- postnote(PNPROC, audiopid, "shutdown");
- audiopid = -1;
- }
I_ShutdownMusic();
}
--- a/i_system.c
+++ b/i_system.c
@@ -44,6 +44,7 @@
I_ShutdownSound();
M_SaveDefaults ();
I_ShutdownGraphics();
+ postnote(PNGROUP, getpid(), "I_Quit");
exits(nil);
}
--- a/i_video.c
+++ b/i_video.c
@@ -25,9 +25,6 @@
static uchar cmap[3*256];
-static int kbdpid = -1;
-static int mousepid = -1;
-
static void
catch(void *, char *msg)
{
@@ -39,7 +36,6 @@
void I_InitGraphics(void)
{
- int pid;
notify(catch);
@@ -51,17 +47,15 @@
center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
grabout = insetrect(screen->r, Dx(screen->r)/8);
- if((pid = rfork(RFPROC|RFMEM)) == 0){
+ if(rfork(RFPROC|RFMEM) == 0){
kbdproc();
exits(nil);
}
- kbdpid = pid;
- if((pid = rfork(RFPROC|RFMEM)) == 0){
+ if(rfork(RFPROC|RFMEM) == 0){
mouseproc();
exits(nil);
}
- mousepid = pid;
I_SetPalette ((byte *)W_CacheLumpName("PLAYPAL", PU_CACHE));
}
@@ -68,14 +62,7 @@
void I_ShutdownGraphics(void)
{
- if(kbdpid != -1){
- postnote(PNPROC, kbdpid, "shutdown");
- kbdpid = -1;
- }
- if(mousepid != -1){
- postnote(PNPROC, mousepid, "shutdown");
- mousepid = -1;
- }
+ closedisplay(display);
}
void I_SetPalette(byte *palette)
@@ -309,6 +296,7 @@
buf2[0] = 0;
buf2[1] = 0;
buf[0] = 0;
+ procsetname("hexen kbdproc");
for(;;){
if(buf[0] != 0){
n = strlen(buf)+1;
@@ -380,6 +368,7 @@
memset(&m, 0, sizeof m);
memset(&om, 0, sizeof om);
nerr = 0;
+ procsetname("hexen mouseproc");
for(;;){
n = read(fd, buf, sizeof buf);
if(n != 1+4*12){