summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2005-09-04 23:18:30 +0000
committerSimon Howard2005-09-04 23:18:30 +0000
commit7b151f074e26aa398b3cbd4811e4e6edd8a7918c (patch)
treeae764d889c7a22feaf7687e0a255b784b71e385e /src
parentf2ed07417429e1e813761fd005f39af737779fbe (diff)
downloadchocolate-doom-7b151f074e26aa398b3cbd4811e4e6edd8a7918c.tar.gz
chocolate-doom-7b151f074e26aa398b3cbd4811e4e6edd8a7918c.tar.bz2
chocolate-doom-7b151f074e26aa398b3cbd4811e4e6edd8a7918c.zip
Remove dead code. Cope with the screen not having width == pitch. Lock
the SDL screen surface properly. Rewrite 2x scaling code. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 72
Diffstat (limited to 'src')
-rw-r--r--src/i_video.c413
1 files changed, 82 insertions, 331 deletions
diff --git a/src/i_video.c b/src/i_video.c
index 8d226252..f3f24fff 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: i_video.c 64 2005-09-01 00:01:36Z fraggle $
+// $Id: i_video.c 72 2005-09-04 23:18:30Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.22 2005/09/04 23:18:30 fraggle
+// Remove dead code. Cope with the screen not having width == pitch. Lock
+// the SDL screen surface properly. Rewrite 2x scaling code.
+//
// Revision 1.21 2005/09/01 00:01:36 fraggle
// -nograbmouse option
//
@@ -97,7 +101,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: i_video.c 64 2005-09-01 00:01:36Z fraggle $";
+rcsid[] = "$Id: i_video.c 72 2005-09-04 23:18:30Z fraggle $";
#include <ctype.h>
#include <SDL.h>
@@ -122,6 +126,12 @@ static SDL_Surface *screen;
static SDL_Color palette[256];
static boolean palette_to_set;
+static int windowwidth, windowheight;
+
+// if true, screens[0] is screen->pixel
+
+static boolean native_surface;
+
boolean fullscreen = 1;
boolean grabmouse = 1;
@@ -395,71 +405,6 @@ void I_GetEvent(void)
event.data2 = event.data3 = 0;
D_PostEvent(&event);
break;
-
-#if 0
- case ButtonPress:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xbutton.state & Button1Mask)
- | (X_event.xbutton.state & Button2Mask ? 2 : 0)
- | (X_event.xbutton.state & Button3Mask ? 4 : 0)
- | (X_event.xbutton.button == Button1)
- | (X_event.xbutton.button == Button2 ? 2 : 0)
- | (X_event.xbutton.button == Button3 ? 4 : 0);
- event.data2 = event.data3 = 0;
- D_PostEvent(&event);
- // fprintf(stderr, "b");
- break;
- case ButtonRelease:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xbutton.state & Button1Mask)
- | (X_event.xbutton.state & Button2Mask ? 2 : 0)
- | (X_event.xbutton.state & Button3Mask ? 4 : 0);
- // suggest parentheses around arithmetic in operand of |
- event.data1 =
- event.data1
- ^ (X_event.xbutton.button == Button1 ? 1 : 0)
- ^ (X_event.xbutton.button == Button2 ? 2 : 0)
- ^ (X_event.xbutton.button == Button3 ? 4 : 0);
- event.data2 = event.data3 = 0;
- D_PostEvent(&event);
- // fprintf(stderr, "bu");
- break;
- case MotionNotify:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xmotion.state & Button1Mask)
- | (X_event.xmotion.state & Button2Mask ? 2 : 0)
- | (X_event.xmotion.state & Button3Mask ? 4 : 0);
- event.data2 = (X_event.xmotion.x - lastmousex) << 2;
- event.data3 = (lastmousey - X_event.xmotion.y) << 2;
-
- if (event.data2 || event.data3)
- {
- lastmousex = X_event.xmotion.x;
- lastmousey = X_event.xmotion.y;
- if (X_event.xmotion.x != X_width/2 &&
- X_event.xmotion.y != X_height/2)
- {
- D_PostEvent(&event);
- // fprintf(stderr, "m");
- mousemoved = false;
- } else
- {
- mousemoved = true;
- }
- }
- break;
-
- case Expose:
- case ConfigureNotify:
- break;
-
- default:
- if (doShm && X_event.type == X_shmeventtype) shmFinished = true;
- break;
-#endif
}
}
}
@@ -469,34 +414,6 @@ void I_GetEvent(void)
void I_StartTic (void)
{
I_GetEvent();
-#if 0
-
- if (!X_display)
- return;
-
- while (XPending(X_display))
- I_GetEvent();
-
- // Warp the pointer back to the middle of the window
- // or it will wander off - that is, the game will
- // loose input focus within X11.
- if (grabMouse)
- {
- if (!--doPointerWarp)
- {
- XWarpPointer( X_display,
- None,
- X_mainWindow,
- 0, 0,
- 0, 0,
- X_width/2, X_height/2);
-
- doPointerWarp = POINTER_WARP_COUNTDOWN;
- }
- }
-
- mousemoved = false;
-#endif
}
@@ -558,119 +475,68 @@ void I_FinishUpdate (void)
screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
}
- // scales the screen size before blitting it
- if (multiply == 2)
+
+ if (multiply == 1 && !native_surface)
{
- unsigned int *olineptrs[2];
- unsigned int *ilineptr;
- int x, y, i;
- unsigned int twoopixels;
- unsigned int twomoreopixels;
- unsigned int fouripixels;
- unsigned int X_width = screen->pitch;
- Uint8 *screen_pixels = (Uint8 *) screen->pixels;
+ byte *bufp, *screenp;
+ int y;
+ int pitch;
SDL_LockSurface(screen);
- ilineptr = (unsigned int *) (screens[0]);
- for (i=0 ; i<2 ; i++)
- olineptrs[i] = (unsigned int *) &screen_pixels[i*X_width];
-
- y = SCREENHEIGHT;
- while (y--)
- {
- x = SCREENWIDTH;
- do
- {
- fouripixels = *ilineptr++;
- twoopixels = (fouripixels & 0xff000000)
- | ((fouripixels>>8) & 0xffff00)
- | ((fouripixels>>16) & 0xff);
- twomoreopixels = ((fouripixels<<16) & 0xff000000)
- | ((fouripixels<<8) & 0xffff00)
- | (fouripixels & 0xff);
-#ifdef __BIG_ENDIAN__
- *olineptrs[0]++ = twoopixels;
- *olineptrs[1]++ = twoopixels;
- *olineptrs[0]++ = twomoreopixels;
- *olineptrs[1]++ = twomoreopixels;
-#else
- *olineptrs[0]++ = twomoreopixels;
- *olineptrs[1]++ = twomoreopixels;
- *olineptrs[0]++ = twoopixels;
- *olineptrs[1]++ = twoopixels;
-#endif
- } while (x-=4);
- olineptrs[0] += X_width/4;
- olineptrs[1] += X_width/4;
- }
+ bufp = screens[0];
+ screenp = (byte *) screen->pixels;
+ pitch = screen->pitch;
+
+ for (y=0; y<SCREENHEIGHT; ++y)
+ {
+ memcpy(screenp, bufp, SCREENWIDTH);
+ screenp += pitch;
+ bufp += SCREENWIDTH;
+ }
SDL_UnlockSurface(screen);
}
-#if 0
- else if (multiply == 3)
- {
- unsigned int *olineptrs[3];
- unsigned int *ilineptr;
- int x, y, i;
- unsigned int fouropixels[3];
- unsigned int fouripixels;
-
- ilineptr = (unsigned int *) (screens[0]);
- for (i=0 ; i<3 ; i++)
- olineptrs[i] = (unsigned int *) &image->data[i*X_width];
-
- y = SCREENHEIGHT;
- while (y--)
- {
- x = SCREENWIDTH;
- do
- {
- fouripixels = *ilineptr++;
- fouropixels[0] = (fouripixels & 0xff000000)
- | ((fouripixels>>8) & 0xff0000)
- | ((fouripixels>>16) & 0xffff);
- fouropixels[1] = ((fouripixels<<8) & 0xff000000)
- | (fouripixels & 0xffff00)
- | ((fouripixels>>8) & 0xff);
- fouropixels[2] = ((fouripixels<<16) & 0xffff0000)
- | ((fouripixels<<8) & 0xff00)
- | (fouripixels & 0xff);
-#ifdef __BIG_ENDIAN__
- *olineptrs[0]++ = fouropixels[0];
- *olineptrs[1]++ = fouropixels[0];
- *olineptrs[2]++ = fouropixels[0];
- *olineptrs[0]++ = fouropixels[1];
- *olineptrs[1]++ = fouropixels[1];
- *olineptrs[2]++ = fouropixels[1];
- *olineptrs[0]++ = fouropixels[2];
- *olineptrs[1]++ = fouropixels[2];
- *olineptrs[2]++ = fouropixels[2];
-#else
- *olineptrs[0]++ = fouropixels[2];
- *olineptrs[1]++ = fouropixels[2];
- *olineptrs[2]++ = fouropixels[2];
- *olineptrs[0]++ = fouropixels[1];
- *olineptrs[1]++ = fouropixels[1];
- *olineptrs[2]++ = fouropixels[1];
- *olineptrs[0]++ = fouropixels[0];
- *olineptrs[1]++ = fouropixels[0];
- *olineptrs[2]++ = fouropixels[0];
-#endif
- } while (x-=4);
- olineptrs[0] += 2*X_width/4;
- olineptrs[1] += 2*X_width/4;
- olineptrs[2] += 2*X_width/4;
- }
- }
- else if (multiply == 4)
+ // scales the screen size before blitting it
+
+ if (multiply == 2)
{
- // Broken. Gotta fix this some day.
- void Expand4(unsigned *, double *);
- Expand4 ((unsigned *)(screens[0]), (double *) (image->data));
+ byte *bufp, *screenp, *screenp2;
+ int x, y;
+ int pitch;
+
+ SDL_LockSurface(screen);
+
+ bufp = screens[0];
+ screenp = (byte *) screen->pixels;
+ screenp2 = ((byte *) screen->pixels) + screen->pitch;
+ pitch = screen->pitch * 2;
+
+ for (y=0; y<SCREENHEIGHT; ++y)
+ {
+ byte *sp, *sp2, *bp;
+ sp = screenp;
+ sp2 = screenp2;
+ bp = bufp;
+
+ for (x=0; x<SCREENWIDTH; ++x)
+ {
+ *sp2++ = *bp;
+ *sp2++ = *bp;
+ *sp++ = *bp;
+ *sp++ = *bp++;
+ }
+ screenp += pitch;
+ screenp2 += pitch;
+ bufp += SCREENWIDTH;
+ }
+
+ SDL_UnlockSurface(screen);
}
-#endif
+
+ if (native_surface)
+ SDL_UnlockSurface(screen);
// draw to screen
@@ -683,6 +549,9 @@ void I_FinishUpdate (void)
{
SDL_Flip(screen);
}
+
+ if (native_surface)
+ SDL_LockSurface(screen);
}
@@ -760,7 +629,10 @@ void I_InitGraphics(void)
multiply = 2;
}
- screen = SDL_SetVideoMode(SCREENWIDTH*multiply, SCREENHEIGHT*multiply, 8, flags);
+ windowwidth = SCREENWIDTH * multiply;
+ windowheight = SCREENHEIGHT * multiply;
+
+ screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags);
if (screen == NULL)
{
@@ -769,11 +641,21 @@ void I_InitGraphics(void)
SetCaption();
- if (multiply == 1)
+ // Check if we have a native surface we can use
+
+ native_surface = multiply == 1 && screen->pitch == SCREENWIDTH;
+
+ // If not, allocate a buffer and copy from that buffer to the
+ // screen when we do an update
+
+ if (native_surface)
screens[0] = (unsigned char *) (screen->pixels);
else
screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL);
+ if (native_surface)
+ SDL_LockSurface(screen);
+
LoadDiskImage();
SDL_EnableUNICODE(1);
@@ -787,134 +669,3 @@ void I_InitGraphics(void)
while (SDL_PollEvent(&dummy));
}
-unsigned exptable[256];
-
-void InitExpand (void)
-{
- int i;
-
- for (i=0 ; i<256 ; i++)
- exptable[i] = i | (i<<8) | (i<<16) | (i<<24);
-}
-
-double exptable2[256*256];
-
-void InitExpand2 (void)
-{
- int i;
- int j;
- // UNUSED unsigned iexp, jexp;
- double* exp;
- union
- {
- double d;
- unsigned u[2];
- } pixel;
-
- exp = exptable2;
- for (i=0 ; i<256 ; i++)
- {
- pixel.u[0] = i | (i<<8) | (i<<16) | (i<<24);
- for (j=0 ; j<256 ; j++)
- {
- pixel.u[1] = j | (j<<8) | (j<<16) | (j<<24);
- *exp++ = pixel.d;
- }
- }
-}
-
-int inited;
-
-void
-Expand4
-( unsigned* lineptr,
- double* xline )
-{
- double dpixel;
- unsigned x;
- unsigned y;
- unsigned fourpixels;
- unsigned step;
- double* exp;
-
- exp = exptable2;
- if (!inited)
- {
- inited = 1;
- InitExpand2 ();
- }
-
-
- step = 3*SCREENWIDTH/2;
-
- y = SCREENHEIGHT-1;
- do
- {
- x = SCREENWIDTH;
-
- do
- {
- fourpixels = lineptr[0];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[0] = dpixel;
- xline[160] = dpixel;
- xline[320] = dpixel;
- xline[480] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[1] = dpixel;
- xline[161] = dpixel;
- xline[321] = dpixel;
- xline[481] = dpixel;
-
- fourpixels = lineptr[1];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[2] = dpixel;
- xline[162] = dpixel;
- xline[322] = dpixel;
- xline[482] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[3] = dpixel;
- xline[163] = dpixel;
- xline[323] = dpixel;
- xline[483] = dpixel;
-
- fourpixels = lineptr[2];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[4] = dpixel;
- xline[164] = dpixel;
- xline[324] = dpixel;
- xline[484] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[5] = dpixel;
- xline[165] = dpixel;
- xline[325] = dpixel;
- xline[485] = dpixel;
-
- fourpixels = lineptr[3];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[6] = dpixel;
- xline[166] = dpixel;
- xline[326] = dpixel;
- xline[486] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[7] = dpixel;
- xline[167] = dpixel;
- xline[327] = dpixel;
- xline[487] = dpixel;
-
- lineptr+=4;
- xline+=8;
- } while (x-=16);
- xline += step;
- } while (y--);
-}
-
-