]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/games/doom/d_main.c
doom: fix music for patch wads
[plan9front.git] / sys / src / games / doom / d_main.c
index 490b659bce4e607407403ee89183e58e815c7804..6f1e8621545e224ade980acf47397386b62749b1 100644 (file)
@@ -90,6 +90,9 @@ boolean         drone;
 
 boolean                singletics = false; // debug flag to cancel adaptiveness
 
+/* bug compatibility with various versions of doom */
+boolean                noztele;
+boolean                nobounce;
 
 
 //extern int soundVolume;
@@ -130,6 +133,7 @@ void D_DoAdvanceDemo (void);
 event_t         events[MAXEVENTS];
 int             eventhead;
 int            eventtail;
+QLock          eventlock;
 
 
 //
@@ -138,8 +142,21 @@ int                eventtail;
 //
 void D_PostEvent (event_t* ev)
 {
+    int next;
+
+retry:
+    qlock(&eventlock);
+    next = (eventhead+1)&(MAXEVENTS-1);
+    if(next == eventtail){
+        qunlock(&eventlock);
+        if(ev->type != ev_keydown && ev->type != ev_keyup)
+            return;
+        sleep(1);
+        goto retry;
+    }
     events[eventhead] = *ev;
-    eventhead = (++eventhead)&(MAXEVENTS-1);
+    eventhead = next;
+    qunlock(&eventlock);
 }
 
 
@@ -156,7 +173,7 @@ void D_ProcessEvents (void)
         && (W_CheckNumForName("map01")<0) )
       return;
        
-    for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) )
+    for ( ; eventtail != eventhead ; eventtail = (eventtail+1)&(MAXEVENTS-1))
     {
        ev = &events[eventtail];
        if (M_Responder (ev))
@@ -309,6 +326,7 @@ void D_Display (void)
     if (!wipe)
     {
        I_FinishUpdate ();              // page flip or blit buffer
+       I_UpdateSound ();
        return;
     }
     
@@ -330,6 +348,8 @@ void D_Display (void)
        I_UpdateNoBlit ();
        M_Drawer ();                            // menu is drawn even on top of wipes
        I_FinishUpdate ();                      // page flip or blit buffer
+       if (!done)
+               I_UpdateSound ();
     } while (!done);
 }
 
@@ -380,15 +400,6 @@ void D_DoomLoop (void)
 
        // Update display, next frame, with current state.
        D_Display ();
-
-       // Sound mixing for the buffer is snychronous.
-       I_UpdateSound();
-
-       // Synchronous sound output is explicitly called.
-#ifndef SNDINTR
-       // Update sound output.
-       I_SubmitSound();
-#endif
     }
 }
 
@@ -549,7 +560,7 @@ void D_AddFile (char *file)
 //
 void IdentifyVersion (void)
 {
-       char *wadfile;
+       char *wadfile, *slash;
 
        if (M_CheckParm ("-shdev"))
        {
@@ -601,35 +612,35 @@ void IdentifyVersion (void)
                language = french;
                printf("French version\n");
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("doom2.wad")) ) {
                gamemode = commercial;
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("plutonia.wad")) ) {
                gamemode = commercial;
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("tnt.wad")) ) {
                gamemode = commercial;
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("doomu.wad")) ) {
                gamemode = retail;
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("doom.wad")) ) {
                gamemode = registered;
                D_AddFile (wadfile);
-               return;
        } else if ( (wadfile = I_IdentifyWAD("doom1.wad")) ) {
                gamemode = shareware;
                D_AddFile (wadfile);
-               return;
        } else {
                printf("Game mode indeterminate.\n");
                gamemode = indetermined;
+               return;
        }
+       strncpy(basedefault, wadfile, sizeof(basedefault)-5);
+       basedefault[sizeof(basedefault)-5] = '\0';
+       slash = strrchr(basedefault, '/');
+       if (slash++ == 0)
+               slash = basedefault;
+       strcpy(slash, "cfg");
 }
 
 //
@@ -711,8 +722,8 @@ void FindResponseFile (void)
 //
 void D_DoomMain (void)
 {
-    int             p;
-    char                    file[256];
+    int                p;
+    char       file[256];
 
     FindResponseFile ();
        
@@ -725,6 +736,10 @@ void D_DoomMain (void)
     respawnparm = M_CheckParm ("-respawn");
     fastparm = M_CheckParm ("-fast");
     devparm = M_CheckParm ("-devparm");
+    if (M_CheckParm ("-noztele") && gamemode == commercial)
+       noztele = 1;
+    if (M_CheckParm ("-nobounce") && (gamemode == commercial || gamemode == registered))
+       nobounce = 1;
     if (M_CheckParm ("-altdeath"))
        deathmatch = 2;
     else if (M_CheckParm ("-deathmatch"))
@@ -790,16 +805,6 @@ void D_DoomMain (void)
     if (devparm)
        printf(D_DEVSTR);
     
-    if (M_CheckParm("-cdrom"))
-    {
-       I_Error("PORTME d_main.c M_CheckParm -cdrom");
-/*
-       printf(D_CDROM);
-       mkdir("c:\\doomdata",0);
-       strcpy (basedefault,"c:/doomdata/default.cfg");
-*/
-    }  
-    
     // turbo option
     if ( (p=M_CheckParm ("-turbo")) )
     {
@@ -916,13 +921,11 @@ void D_DoomMain (void)
     p = M_CheckParm ("-warp");
     if (p && p < myargc-1)
     {
-       if (gamemode == commercial)
-           startmap = atoi (myargv[p+1]);
-       else
-       {
-           startepisode = myargv[p+1][0]-'0';
-           startmap = myargv[p+2][0]-'0';
-       }
+       startmap = atoi (myargv[p+1]);
+       if (gamemode != commercial){
+            startepisode = startmap / 10;
+            startmap %= 10;
+        }
        autostart = true;
     }
     
@@ -1069,10 +1072,7 @@ void D_DoomMain (void)
     p = M_CheckParm ("-loadgame");
     if (p && p < myargc-1)
     {
-       if (M_CheckParm("-cdrom"))
-           sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
-       else
-           sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
+       sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
        G_LoadGame (file);
     }