shithub: choc

Download patch

ref: a44cef97897474df434501daca50a07b50019aa2
parent: 2532daf4e1e8cf58274c0c845ec9b297cde369c7
parent: ed77a8fe11aee07db4aea3fa3c361047944e14cc
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jun 4 16:31:42 EDT 2016

Merge remote-tracking branch 'origin/master' into sdl2-branch

--- a/pkg/osx/GNUmakefile
+++ b/pkg/osx/GNUmakefile
@@ -8,9 +8,7 @@
 
 DOC_FILES += README.Strife NOT-BUGS
 
-# Build so that the package will work on older versions.
-
-export MACOSX_DEPLOYMENT_TARGET=10.4
+export MACOSX_DEPLOYMENT_TARGET=10.7
 
 STAGING_DIR=staging
 DMG=$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).dmg
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -126,6 +126,7 @@
 char		mapdir[1024];           // directory of development maps
 
 int             show_endoom = 1;
+int             show_diskicon = 1;
 
 
 void D_ConnectNetGame(void);
@@ -215,7 +216,7 @@
 	    break;
 	if (automapactive)
 	    AM_Drawer ();
-	if (wipe || (viewheight != SCREENHEIGHT && fullscreen) || disk_indicator == disk_dirty)
+	if (wipe || (viewheight != SCREENHEIGHT && fullscreen))
 	    redrawsbar = true;
 	if (inhelpscreensstate && !inhelpscreens)
 	    redrawsbar = true;              // just put away the help screen
@@ -329,6 +330,27 @@
     } while (!done);
 }
 
+static void EnableLoadingDisk(void)
+{
+    char *disk_lump_name;
+
+    if (show_diskicon)
+    {
+        if (M_CheckParm("-cdrom") > 0)
+        {
+            disk_lump_name = DEH_String("STCDROM");
+        }
+        else
+        {
+            disk_lump_name = DEH_String("STDISK");
+        }
+
+        V_EnableLoadingDisk(disk_lump_name,
+                            SCREENWIDTH - LOADING_DISK_W,
+                            SCREENHEIGHT - LOADING_DISK_H);
+    }
+}
+
 //
 // Add configuration file variable bindings.
 //
@@ -428,7 +450,7 @@
     I_GraphicsCheckCommandLine();
     I_SetGrabMouseCallback(D_GrabMouseCallback);
     I_InitGraphics();
-    V_EnableLoadingDisk(SCREENWIDTH - LOADING_DISK_W, SCREENHEIGHT - LOADING_DISK_H);
+    EnableLoadingDisk();
 
     TryRunTics();
 
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -39,6 +39,7 @@
 #include "m_config.h"
 #include "m_misc.h"
 #include "tables.h"
+#include "v_diskicon.h"
 #include "v_video.h"
 #include "w_wad.h"
 #include "z_zone.h"
@@ -98,15 +99,6 @@
 
 int png_screenshots = 0;
 
-// Display disk activity indicator.
-
-int show_diskicon = 1;
-
-// Only display the disk icon if more then this much bytes have been read
-// during the previous tic.
-
-int diskicon_readbytes = 0;
-
 // Screen width and height, from configuration file.
 
 int window_width = SCREENWIDTH * 2;
@@ -663,6 +655,9 @@
 	    I_VideoBuffer[ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
     }
 
+    // Draw disk icon before blit, if necessary.
+    V_DrawDiskIcon();
+
     if (palette_to_set)
     {
         SDL_SetPaletteColors(screenbuffer->format->palette, palette, 0, 256);
@@ -696,6 +691,9 @@
     // Draw!
 
     SDL_RenderPresent(renderer);
+
+    // Restore background and undo the disk indicator, if it was drawn.
+    V_RestoreDiskBackground();
 }
 
 
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -93,7 +93,4 @@
 extern int fullscreen;
 extern int aspect_ratio_correct;
 
-extern int show_diskicon;
-extern int diskicon_readbytes;
-
 #endif
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -238,13 +238,6 @@
                                       &show_endoom));
     }
 
-    if (gamemission == doom || gamemission == strife)
-    {
-        TXT_AddWidget(window,
-                      TXT_NewCheckBox("Show disk activity indicator",
-                                      &show_diskicon));
-    }
-
     TXT_AddWidget(window,
                   TXT_NewCheckBox("Save screenshots in PNG format",
                                   &png_screenshots));
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -143,6 +143,7 @@
 char		mapdir[1024];           // directory of development maps
 
 int             show_endoom = 1;
+int             show_diskicon = 1;
 int             graphical_startup = 1;
 
 // If true, startup has completed and the main game loop has started.
@@ -302,7 +303,7 @@
     // see if the border needs to be updated to the screen
     if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320)
     {
-        if (menuactive || menuactivestate || !viewactivestate || disk_indicator == disk_dirty)
+        if (menuactive || menuactivestate || !viewactivestate)
         {
             borderdrawcount = 3;
             popupactivestate = false;
@@ -513,7 +514,10 @@
         I_InitGraphics();
     }
 
-    V_EnableLoadingDisk(SCREENWIDTH - LOADING_DISK_W, 0);
+    if (show_diskicon)
+    {
+        V_EnableLoadingDisk("STDISK", SCREENWIDTH - LOADING_DISK_W, 3);
+    }
     I_SetGrabMouseCallback(D_GrabMouseCallback);
 
     V_RestoreBuffer();
--- a/src/v_diskicon.c
+++ b/src/v_diskicon.c
@@ -18,6 +18,8 @@
 
 #include "doomtype.h"
 #include "deh_str.h"
+#include "i_swap.h"
+#include "i_video.h"
 #include "m_argv.h"
 #include "v_video.h"
 #include "w_wad.h"
@@ -25,37 +27,116 @@
 
 #include "v_diskicon.h"
 
-// disk image patch (either STDISK or STCDROM)
+// Only display the disk icon if more then this much bytes have been read
+// during the previous tic.
 
-static patch_t *disk;
+static const int diskicon_threshold = 20*1024;
 
+// Two buffers: disk_data contains the data representing the disk icon
+// (raw, not a patch_t) while saved_background is an equivalently-sized
+// buffer where we save the background data while the disk is on screen.
+static byte *disk_data;
+static byte *saved_background;
+
 static int loading_disk_xoffs = 0;
 static int loading_disk_yoffs = 0;
 
-disk_indicator_e disk_indicator = disk_off;
+// Number of bytes read since the last call to V_DrawDiskIcon().
+static size_t recent_bytes_read = 0;
+static boolean disk_drawn;
 
-void V_EnableLoadingDisk(int xoffs, int yoffs)
+static void CopyRegion(byte *dest, int dest_pitch,
+                       byte *src, int src_pitch,
+                       int w, int h)
 {
-    char *disk_name;
+    byte *s, *d;
+    int y;
 
+    s = src; d = dest;
+    for (y = 0; y < h; ++y)
+    {
+        memcpy(d, s, w);
+        s += src_pitch;
+        d += dest_pitch;
+    }
+}
+
+static void SaveDiskData(char *disk_lump, int xoffs, int yoffs)
+{
+    byte *tmpscreen;
+    patch_t *disk;
+
+    // Allocate a complete temporary screen where we'll draw the patch.
+    tmpscreen = Z_Malloc(SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL);
+    memset(tmpscreen, 0, SCREENWIDTH * SCREENHEIGHT);
+    V_UseBuffer(tmpscreen);
+
+    // Buffer where we'll save the disk data.
+    disk_data = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H, PU_STATIC, NULL);
+
+    // Draw the patch and save the result to disk_data.
+    disk = W_CacheLumpName(disk_lump, PU_STATIC);
+    V_DrawPatch(loading_disk_xoffs, loading_disk_yoffs, disk);
+    CopyRegion(disk_data, LOADING_DISK_W,
+               tmpscreen + yoffs * SCREENWIDTH + xoffs, SCREENWIDTH,
+               LOADING_DISK_W, LOADING_DISK_H);
+    W_ReleaseLumpName(disk_lump);
+
+    V_RestoreBuffer();
+    Z_Free(tmpscreen);
+}
+
+void V_EnableLoadingDisk(char *lump_name, int xoffs, int yoffs)
+{
     loading_disk_xoffs = xoffs;
     loading_disk_yoffs = yoffs;
 
-    if (M_CheckParm("-cdrom") > 0)
-        disk_name = DEH_String("STCDROM");
-    else
-        disk_name = DEH_String("STDISK");
+    saved_background = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H, PU_STATIC,
+                                NULL);
+    SaveDiskData(lump_name, xoffs, yoffs);
+}
 
-    disk = W_CacheLumpName(disk_name, PU_STATIC);
+void V_BeginRead(size_t nbytes)
+{
+    recent_bytes_read += nbytes;
 }
 
-void V_BeginRead(void)
+static byte *DiskRegionPointer(void)
 {
-    if (disk == NULL)
-        return;
+    return I_VideoBuffer
+         + loading_disk_yoffs * SCREENWIDTH
+         + loading_disk_xoffs;
+}
 
-    // Draw the disk to the screen
-    V_DrawPatch(loading_disk_xoffs, loading_disk_yoffs, disk);
+void V_DrawDiskIcon(void)
+{
+    if (disk_data != NULL && recent_bytes_read > diskicon_threshold)
+    {
+        // Save the background behind the disk before we draw it.
+        CopyRegion(saved_background, LOADING_DISK_W,
+                   DiskRegionPointer(), SCREENWIDTH,
+                   LOADING_DISK_W, LOADING_DISK_H);
 
-    disk_indicator = disk_dirty;
+        // Write the disk to the screen buffer.
+        CopyRegion(DiskRegionPointer(), SCREENWIDTH,
+                   disk_data, LOADING_DISK_W,
+                   LOADING_DISK_W, LOADING_DISK_H);
+        disk_drawn = true;
+    }
+
+    recent_bytes_read = 0;
 }
+
+void V_RestoreDiskBackground(void)
+{
+    if (disk_drawn)
+    {
+        // Restore the background.
+        CopyRegion(DiskRegionPointer(), SCREENWIDTH,
+                   saved_background, LOADING_DISK_W,
+                   LOADING_DISK_W, LOADING_DISK_H);
+
+        disk_drawn = false;
+    }
+}
+
--- a/src/v_diskicon.h
+++ b/src/v_diskicon.h
@@ -24,16 +24,9 @@
 #define LOADING_DISK_W 16
 #define LOADING_DISK_H 16
 
-typedef enum
-{
-    disk_off,
-    disk_on,
-    disk_dirty
-} disk_indicator_e;
-
-extern disk_indicator_e disk_indicator;
-
-extern void V_EnableLoadingDisk (int xoffs, int yoffs);
-extern void V_BeginRead (void);
+extern void V_EnableLoadingDisk(char *lump_name, int xoffs, int yoffs);
+extern void V_BeginRead(size_t nbytes);
+extern void V_DrawDiskIcon(void);
+extern void V_RestoreDiskBackground(void);
 
 #endif
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -348,9 +348,7 @@
 
     l = lumpinfo[lump];
 
-    diskicon_readbytes += l->size;
-
-    disk_indicator = disk_on;
+    V_BeginRead(l->size);
 
     c = W_Read(l->wad_file, l->position, dest, l->size);