From e5c7fe6305977d4135d56d2fa6b5b37c8f275679 Mon Sep 17 00:00:00 2001 From: qwx Date: Wed, 9 Aug 2023 23:01:21 +0000 Subject: [PATCH] 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 e7b1c1aad896c131fb30b6b0836ff65a63a6eae3). 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 --- rc/bin/dmus | 4 ++-- sys/src/games/doom/d_main.c | 42 ++++++++++++++++++++++++++++------- sys/src/games/doom/i_sound.c | 9 +------- sys/src/games/doom/i_system.c | 1 + 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/rc/bin/dmus b/rc/bin/dmus index c0c7f4a66..51950d033 100755 --- 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) diff --git a/sys/src/games/doom/d_main.c b/sys/src/games/doom/d_main.c index 6f1e86215..4b551892f 100644 --- a/sys/src/games/doom/d_main.c +++ b/sys/src/games/doom/d_main.c @@ -539,16 +539,34 @@ char title[128]; // 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,8 +740,10 @@ void FindResponseFile (void) // void D_DoomMain (void) { - int p; - char file[256]; + int i, p; + char file[256], mnt[16]; + + rfork(RFNAMEG); FindResponseFile (); @@ -1054,6 +1074,12 @@ void D_DoomMain (void) 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) { diff --git a/sys/src/games/doom/i_sound.c b/sys/src/games/doom/i_sound.c index ef9939df2..eb29a8633 100644 --- a/sys/src/games/doom/i_sound.c +++ b/sys/src/games/doom/i_sound.c @@ -463,14 +463,7 @@ void I_PlaySong(musicinfo_t *m, int loop) 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){ diff --git a/sys/src/games/doom/i_system.c b/sys/src/games/doom/i_system.c index 638d2dcd3..aeadc6523 100644 --- 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"