ref: 271fd53e105761d0f1825c10b50d202d3530b698
parent: f7dc78022c63b3b696c346edb2fc3abb92035e91
author: qwx <qwx@sciops.net>
date: Wed Aug 9 19:01:21 EDT 2023
games/doom: use wadfs to expose genmidi lump instead of extracting to /tmp to allow using games/dmid + games/opl3 for music playback, the genmidi lump must be exposed; previous attempt was insufficient since patch wads can overwrite iwad contents, which a single wadfs cannot take into account (commit ab59247a52f108ab03ad55f700e14d845c1cb815). subsequent fix was to use the normal mechanisms to extract the lump to /tmp and later the music lumps for playback, but the temp file may not always be properly cleaned up, preventing any music playback due to conflicts. so, spawn one wadfs for the iwad and one for each subsequently added pwad, just making sure that they have sufficient delay to properly initialize and bind in the right order
--- a/rc/bin/dmus
+++ b/rc/bin/dmus
@@ -1,6 +1,6 @@
#!/bin/rc
-if(test -f /tmp/genmidi.*)
- c=(games/dmid -i /tmp/genmidi.* '|' games/opl3)
+if(test -f /mnt/wad/genmidi)
+ c=(games/dmid '|' games/opl3)
if not
c=(games/midi -c)
if(~ `{file -m $1} audio/mus)
--- a/sys/src/games/doom/d_main.c
+++ b/sys/src/games/doom/d_main.c
@@ -539,16 +539,34 @@
//
void D_AddFile (char *file)
{
+ int n, ext;
int numwadfiles;
- char *newfile;
+ char *newfile, mnt[16];
- for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++)
- ;
+ for(numwadfiles=0; wadfiles[numwadfiles]; numwadfiles++)
+ ;
- newfile = malloc (strlen(file)+1);
- strcpy (newfile, file);
-
+ ext = cistrstr(file, ".wad") != nil || cistrstr(file, ".lmp") != nil;
+ n = strlen(file) + 1;
+ if(!ext)
+ n += 4;
+ if((newfile = malloc(n)) == NULL)
+ sysfatal("malloc: %r");
+ snprintf(newfile, n, "%s%s", file, ext ? "" : ".wad");
wadfiles[numwadfiles] = newfile;
+
+ /* all wads are piled on top of each other at /mnt/wad, iwad first;
+ * binds are deferred to later to leave enough time for each wadfs
+ * to properly initialize */
+ snprintf(mnt, sizeof mnt, "/mnt/wad%d", numwadfiles);
+ switch(rfork(RFPROC|RFFDG)){
+ case -1:
+ sysfatal("rfork: %r");
+ case 0:
+ close(2);
+ execl("/bin/games/wadfs", "wadfs", "-m", mnt, newfile, nil);
+ sysfatal("execl: %r");
+ }
}
@@ -722,9 +740,11 @@
//
void D_DoomMain (void)
{
- int p;
- char file[256];
+ int i, p;
+ char file[256], mnt[16];
+ rfork(RFNAMEG);
+
FindResponseFile ();
IdentifyVersion ();
@@ -1054,6 +1074,12 @@
autostart = true;
}
+ for(i=0; wadfiles[i]; i++){
+ snprintf(mnt, sizeof mnt, "/mnt/wad%d", i);
+ if(bind(mnt, "/mnt/wad", MBEFORE) < 0)
+ sysfatal("bind: %r");
+ }
+
p = M_CheckParm ("-playdemo");
if (p && p < myargc-1)
{
--- a/sys/src/games/doom/i_sound.c
+++ b/sys/src/games/doom/i_sound.c
@@ -463,14 +463,7 @@
dup(mpfd[1], 1);
for(n=3; n<20; n++) close(n);
close(0);
- snprint(name, sizeof(name), "/tmp/doom.%d", getpid());
- if(create(name, ORDWR|ORCLOSE, 0666) != 0)
- sysfatal("create: %r");
- n = W_LumpLength(m->lumpnum);
- if(write(0, m->data, n) != n)
- sysfatal("write: %r");
- if(seek(0, 0, 0) != 0)
- sysfatal("seek: %r");
+ snprint(name, sizeof(name), "/mnt/wad/d_%s", m->name);
if(bind("/fd/1", "/dev/audio", MREPL) == -1)
sysfatal("bind: %r");
while(loop && fork() > 0){
--- a/sys/src/games/doom/i_system.c
+++ b/sys/src/games/doom/i_system.c
@@ -7,6 +7,7 @@
#include "i_sound.h"
#include "i_video.h"
+#include "d_main.h"
#include "d_net.h"
#include "g_game.h"
#include "m_misc.h"
--
⑨