shithub: choc

Download patch

ref: cb4c334c162601fa2e2675e293e2e4c7a6ae57e4
parent: e2e44080a665c68dffdf1863fd1902be395adb10
author: Simon Howard <[email protected]>
date: Sat Sep 20 15:46:11 EDT 2008

Add I_VideoBuffer variable for pointer to screen buffer used by
i_video.c code. Make V_CopyRect always blit to the screen.

Subversion-branch: /branches/raven-branch
Subversion-revision: 1245

--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -416,6 +416,7 @@
     I_SetGrabMouseCallback(D_GrabMouseCallback);
     I_SetWindowTitle(gamedescription);
 
+    V_RestoreBuffer();
     R_ExecuteSetViewSize();
 
     D_StartGameLoop();
--- a/src/doom/st_lib.c
+++ b/src/doom/st_lib.c
@@ -123,7 +123,7 @@
     if (n->y - ST_Y < 0)
 	I_Error("drawNum: n->y - ST_Y < 0");
 
-    V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
+    V_CopyRect(x, n->y - ST_Y, screens[BG], w*numdigits, h, x, n->y);
 
     // if non-number, do not draw it
     if (num == 1994)
@@ -233,7 +233,7 @@
 	    if (y - ST_Y < 0)
 		I_Error("updateMultIcon: y - ST_Y < 0");
 
-	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
+	    V_CopyRect(x, y-ST_Y, screens[BG], w, h, x, y);
 	}
 	V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
 	mi->oldinum = *mi->inum;
@@ -285,7 +285,7 @@
 	if (*bi->val)
 	    V_DrawPatch(bi->x, bi->y, FG, bi->p);
 	else
-	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
+	    V_CopyRect(x, y-ST_Y, screens[BG], w, h, x, y);
 
 	bi->oldval = *bi->val;
     }
--- a/src/doom/st_stuff.c
+++ b/src/doom/st_stuff.c
@@ -438,7 +438,7 @@
 	if (netgame)
 	    V_DrawPatch(ST_FX, 0, BG, faceback);
 
-	V_CopyRect(ST_X, 0, BG, ST_WIDTH, ST_HEIGHT, ST_X, ST_Y, FG);
+	V_CopyRect(ST_X, 0, screens[BG], ST_WIDTH, ST_HEIGHT, ST_X, ST_Y);
     }
 
 }
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -101,7 +101,7 @@
 static boolean nomouse = false;
 int usemouse = 1;
 
-// if true, screens[0] is screen->pixel
+// if true, I_VideoBuffer is screen->pixels
 
 static boolean native_surface;
 
@@ -132,6 +132,10 @@
 
 static int grabmouse = true;
 
+// The screen buffer; this is modified to draw things to the screen
+
+byte *I_VideoBuffer = NULL;
+
 // If true, game is running as a screensaver
 
 boolean screensaver_mode = false;
@@ -304,9 +308,9 @@
     for (y=0; y<disk_image_h; ++y) 
     {
         memcpy(disk_image + disk_image_w * y,
-               screens[0] + SCREENWIDTH * y,
+               I_VideoBuffer + SCREENWIDTH * y,
                disk_image_w);
-        memset(screens[0] + SCREENWIDTH * y, 0, disk_image_w);
+        memset(I_VideoBuffer + SCREENWIDTH * y, 0, disk_image_w);
     }
 
     W_ReleaseLumpName(disk_name);
@@ -689,7 +693,7 @@
 
     if (SDL_LockSurface(screen) >= 0)
     {
-        I_InitScale(screens[0], 
+        I_InitScale(I_VideoBuffer,
                     (byte *) screen->pixels + (y_offset * screen->pitch)
                                             + x_offset, 
                     screen->pitch);
@@ -738,7 +742,7 @@
     for (y=0; y<disk_image_h; ++y)
     {
         byte *screenloc = 
-               screens[0] 
+               I_VideoBuffer
                  + (SCREENHEIGHT - 1 - disk_image_h + y) * SCREENWIDTH
                  + (SCREENWIDTH - 1 - disk_image_w);
 
@@ -764,7 +768,7 @@
     for (y=0; y<disk_image_h; ++y)
     {
         byte *screenloc = 
-               screens[0] 
+               I_VideoBuffer
                  + (SCREENHEIGHT - 1 - disk_image_h + y) * SCREENWIDTH
                  + (SCREENWIDTH - 1 - disk_image_w);
 
@@ -810,9 +814,9 @@
 	if (tics > 20) tics = 20;
 
 	for (i=0 ; i<tics*2 ; i+=4)
-	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
+	    I_VideoBuffer[ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
 	for ( ; i<20*4 ; i+=4)
-	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
+	    I_VideoBuffer[ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
     }
 
     // draw to screen
@@ -839,7 +843,7 @@
 //
 void I_ReadScreen (byte* scr)
 {
-    memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
+    memcpy(scr, I_VideoBuffer, SCREENWIDTH*SCREENHEIGHT);
 }
 
 
@@ -1603,16 +1607,18 @@
 
     if (native_surface)
     {
-	screens[0] = (unsigned char *) screen->pixels;
+	I_VideoBuffer = (unsigned char *) screen->pixels;
 
-        screens[0] += (screen->h - SCREENHEIGHT) / 2;
+        I_VideoBuffer += (screen->h - SCREENHEIGHT) / 2;
     }
     else
     {
-	screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, 
-                                                 PU_STATIC, NULL);
+	I_VideoBuffer = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, 
+                                                    PU_STATIC, NULL);
     }
 
+    V_RestoreBuffer();
+
     // "Loading from disk" icon
 
     LoadDiskImage();
@@ -1619,7 +1625,7 @@
 
     // Clear the screen to black.
 
-    memset(screens[0], 0, SCREENWIDTH * SCREENHEIGHT);
+    memset(I_VideoBuffer, 0, SCREENWIDTH * SCREENHEIGHT);
 
     // We need SDL to give us translated versions of keys as well
 
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -109,6 +109,7 @@
 extern int vanilla_keyboard_mapping;
 extern boolean screensaver_mode;
 extern int usegamma;
+extern byte *I_VideoBuffer;
 
 #endif
 
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -146,7 +146,7 @@
   int		height ) 
 { 
     M_AddToBox (dirtybox, x, y); 
-    M_AddToBox (dirtybox, x+width-1, y+height-1); 
+    M_AddToBox (dirtybox, x + width-1, y + height-1); 
 } 
  
 
@@ -153,44 +153,37 @@
 //
 // V_CopyRect 
 // 
-void
-V_CopyRect
-( int		srcx,
-  int		srcy,
-  int		srcscrn,
-  int		width,
-  int		height,
-  int		destx,
-  int		desty,
-  int		destscrn ) 
+void V_CopyRect(int srcx, int srcy, byte *source,
+                int width, int height,
+                int destx, int desty)
 { 
-    byte*	src;
-    byte*	dest; 
-	 
+    byte *src;
+    byte *dest; 
+ 
 #ifdef RANGECHECK 
-    if (srcx<0
-	||srcx+width >SCREENWIDTH
-	|| srcy<0
-	|| srcy+height>SCREENHEIGHT 
-	||destx<0||destx+width >SCREENWIDTH
-	|| desty<0
-	|| desty+height>SCREENHEIGHT 
-	|| (unsigned)srcscrn>4
-	|| (unsigned)destscrn>4)
+    if (srcx < 0
+     || srcx + width > SCREENWIDTH
+     || srcy < 0
+     || srcy + height > SCREENHEIGHT 
+     || destx < 0
+     || destx + width > SCREENWIDTH
+     || desty < 0
+     || desty + height > SCREENHEIGHT)
     {
-	I_Error ("Bad V_CopyRect");
+        I_Error ("Bad V_CopyRect");
     }
 #endif 
-    V_MarkRect (destx, desty, width, height); 
-	 
-    src = screens[srcscrn]+SCREENWIDTH*srcy+srcx; 
-    dest = screens[destscrn]+SCREENWIDTH*desty+destx; 
 
+    V_MarkRect(destx, desty, width, height); 
+ 
+    src = source + SCREENWIDTH * srcy + srcx; 
+    dest = I_VideoBuffer + SCREENWIDTH * desty + destx; 
+
     for ( ; height>0 ; height--) 
     { 
-	memcpy (dest, src, width); 
-	src += SCREENWIDTH; 
-	dest += SCREENWIDTH; 
+        memcpy(dest, src, width); 
+        src += SCREENWIDTH; 
+        dest += SCREENWIDTH; 
     } 
 } 
  
@@ -431,62 +424,29 @@
 } 
  
 
-
 //
-// V_GetBlock
-// Gets a linear block of pixels from the view buffer.
-//
-void
-V_GetBlock
-( int		x,
-  int		y,
-  int		scrn,
-  int		width,
-  int		height,
-  byte*		dest ) 
-{ 
-    byte*	src; 
-	 
-#ifdef RANGECHECK 
-    if (x<0
-	||x+width >SCREENWIDTH
-	|| y<0
-	|| y+height>SCREENHEIGHT 
-	|| (unsigned)scrn>4 )
-    {
-	I_Error ("Bad V_DrawBlock");
-    }
-#endif 
- 
-    src = screens[scrn] + y*SCREENWIDTH+x; 
-
-    while (height--) 
-    { 
-	memcpy (dest, src, width); 
-	src += SCREENWIDTH; 
-	dest += width; 
-    } 
-} 
-
-
-
-
-//
 // V_Init
 // 
 void V_Init (void) 
 { 
-    int		i;
-    byte*	base;
+    int i;
+    byte *base;
 		
     // stick these in low dos memory on PCs
 
-    base = Z_Malloc(SCREENWIDTH * SCREENHEIGHT * 4, PU_STATIC, NULL);
+    base = Z_Malloc(SCREENWIDTH * SCREENHEIGHT * 3, PU_STATIC, NULL);
 
     for (i=0 ; i<4 ; i++)
     {
-	screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
+	screens[i + 1] = base + i*SCREENWIDTH*SCREENHEIGHT;
     }
+}
+
+// Restore screen buffer to the i_video screen buffer.
+
+void V_RestoreBuffer(void)
+{
+    screens[0] = I_VideoBuffer;
 }
 
 //
--- a/src/v_video.h
+++ b/src/v_video.h
@@ -54,17 +54,11 @@
 // Allocates buffer screens, call before R_Init.
 void V_Init (void);
 
+// Draw a block from the specified source screen to the screen.
 
-void
-V_CopyRect
-( int		srcx,
-  int		srcy,
-  int		srcscrn,
-  int		width,
-  int		height,
-  int		destx,
-  int		desty,
-  int		destscrn );
+void V_CopyRect(int srcx, int srcy, byte *source,
+                int width, int height,
+                int destx, int desty);
 
 void
 V_DrawPatch
@@ -110,5 +104,7 @@
   int		height );
 
 void V_ScreenShot(void);
+
+void V_RestoreBuffer(void);
 
 #endif