summaryrefslogtreecommitdiff
path: root/src/i_video.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/i_video.c')
-rw-r--r--src/i_video.c171
1 files changed, 118 insertions, 53 deletions
diff --git a/src/i_video.c b/src/i_video.c
index 0fe25736..30938eb9 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -20,7 +20,7 @@
// 02111-1307, USA.
//
// DESCRIPTION:
-// DOOM graphics stuff for X11, UNIX.
+// Low level graphics code using SDL.
//
//-----------------------------------------------------------------------------
@@ -33,10 +33,9 @@
#include "icon.c"
#include "config.h"
-#include "deh_main.h"
-#include "doomdef.h"
-#include "doomstat.h"
-#include "d_main.h"
+#include "deh_str.h"
+#include "doomtype.h"
+#include "doomkeys.h"
#include "i_joystick.h"
#include "i_system.h"
#include "i_swap.h"
@@ -44,8 +43,7 @@
#include "i_video.h"
#include "i_scale.h"
#include "m_argv.h"
-#include "s_sound.h"
-#include "sounds.h"
+#include "m_config.h"
#include "v_video.h"
#include "w_wad.h"
#include "z_zone.h"
@@ -81,8 +79,6 @@ static screen_mode_t *screen_modes_corrected[] = {
&mode_squash_5x,
};
-extern void M_QuitDOOM();
-
// SDL video driver name
char *video_driver = "";
@@ -103,44 +99,67 @@ static boolean initialised = false;
// disable mouse?
static boolean nomouse = false;
-extern int usemouse;
+int usemouse = 1;
-// if true, screens[0] is screen->pixel
+// if true, I_VideoBuffer is screen->pixels
static boolean native_surface;
// Screen width and height, from configuration file.
-int screen_width = SCREENWIDTH;
-int screen_height = SCREENHEIGHT;
+static int screen_width = SCREENWIDTH;
+static int screen_height = SCREENHEIGHT;
// Automatically adjust video settings if the selected mode is
// not a valid video mode.
-int autoadjust_video_settings = 1;
+static int autoadjust_video_settings = 1;
// Run in full screen mode? (int type for config code)
-int fullscreen = true;
+static int fullscreen = true;
// Aspect ratio correction mode
-int aspect_ratio_correct = true;
+static int aspect_ratio_correct = true;
// Time to wait for the screen to settle on startup before starting the
// game (ms)
-int startup_delay = 1000;
+static int startup_delay = 1000;
// Grab the mouse? (int type for config code)
-int grabmouse = true;
+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;
// Flag indicating whether the screen is currently visible:
// when the screen isnt visible, don't render the screen
boolean screenvisible;
+// If true, we display dots at the bottom of the screen to
+// indicate FPS.
+
+static boolean display_fps_dots;
+
+// If this is true, the screen is rendered but not blitted to the
+// video buffer.
+
+static boolean noblit;
+
+// Callback function to invoke to determine whether to grab the
+// mouse pointer.
+
+static grabmouse_callback_t grabmouse_callback = NULL;
+
// disk image data and background overwritten by the disk to be
// restored by EndRead
@@ -175,6 +194,10 @@ int vanilla_keyboard_mapping = true;
float mouse_acceleration = 2.0;
int mouse_threshold = 10;
+// Gamma correction level to use
+
+int usegamma = 0;
+
static boolean MouseShouldBeGrabbed()
{
// never grab the mouse when in screensaver mode
@@ -198,24 +221,34 @@ static boolean MouseShouldBeGrabbed()
if (!usemouse || nomouse)
return false;
- // Drone players don't need mouse focus
-
- if (drone)
- return false;
-
// if we specify not to grab the mouse, never grab
if (!grabmouse)
return false;
- // when menu is active or game is paused, release the mouse
-
- if (menuactive || paused)
- return false;
+ // Invoke the grabmouse callback function to determine whether
+ // the mouse should be grabbed
- // only grab mouse when playing levels (but not demos)
+ if (grabmouse_callback != NULL)
+ {
+ return grabmouse_callback();
+ }
+ else
+ {
+ return true;
+ }
+}
+
+void I_SetGrabMouseCallback(grabmouse_callback_t func)
+{
+ grabmouse_callback = func;
+}
+
+// Set the variable controlling FPS dots.
- return (gamestate == GS_LEVEL) && !demoplayback;
+void I_DisplayFPSDots(boolean dots_on)
+{
+ display_fps_dots = dots_on;
}
// Update the value of window_focused when we get a focus event
@@ -265,7 +298,7 @@ static void LoadDiskImage(void)
disk = W_CacheLumpName(disk_name, PU_STATIC);
- V_DrawPatch(0, 0, 0, disk);
+ V_DrawPatch(0, 0, disk);
disk_image_w = SHORT(disk->width);
disk_image_h = SHORT(disk->height);
@@ -275,9 +308,9 @@ static void LoadDiskImage(void)
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);
@@ -519,11 +552,13 @@ void I_GetEvent(void)
}
break;
+/* TODO
case SDL_QUIT:
// bring up the "quit doom?" prompt
S_StartSound(NULL,sfx_swtchn);
M_QuitDOOM(0);
break;
+ */
case SDL_ACTIVEEVENT:
// need to update our focus state
@@ -658,7 +693,7 @@ static boolean BlitArea(int x1, int y1, int x2, int y2)
if (SDL_LockSurface(screen) >= 0)
{
- I_InitScale(screens[0],
+ I_InitScale(I_VideoBuffer,
(byte *) screen->pixels + (y_offset * screen->pitch)
+ x_offset,
screen->pitch);
@@ -707,7 +742,7 @@ void I_BeginRead(void)
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);
@@ -733,7 +768,7 @@ void I_EndRead(void)
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);
@@ -770,19 +805,18 @@ void I_FinishUpdate (void)
return;
// draws little dots on the bottom of the screen
- if (devparm)
- {
+ if (display_fps_dots)
+ {
i = I_GetTime();
tics = i - lasttic;
lasttic = i;
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
@@ -809,7 +843,7 @@ void I_FinishUpdate (void)
//
void I_ReadScreen (byte* scr)
{
- memcpy (scr, screens[0], SCREENWIDTH*SCREENHEIGHT);
+ memcpy(scr, I_VideoBuffer, SCREENWIDTH*SCREENHEIGHT);
}
@@ -831,16 +865,16 @@ void I_SetPalette (byte *doompalette)
}
//
-// Set the window caption
+// Set the window title
//
-void I_SetWindowCaption(void)
+void I_SetWindowTitle(char *title)
{
char *buf;
- buf = Z_Malloc(strlen(gamedescription) + strlen(PACKAGE_STRING) + 10,
+ buf = Z_Malloc(strlen(title) + strlen(PACKAGE_STRING) + 5,
PU_STATIC, NULL);
- sprintf(buf, "%s - %s", gamedescription, PACKAGE_STRING);
+ sprintf(buf, "%s - %s", title, PACKAGE_STRING);
SDL_WM_SetCaption(buf, NULL);
@@ -1168,6 +1202,14 @@ static void CheckCommandLine(void)
int i;
//!
+ // @vanilla
+ //
+ // Disable blitting the screen.
+ //
+
+ noblit = M_CheckParm ("-noblit");
+
+ //!
// @category video
//
// Grab the mouse when running in windowed mode.
@@ -1513,9 +1555,6 @@ void I_InitGraphics(void)
I_SetPalette(doompal);
SDL_SetColors(screen, palette, 0, 256);
- // Setup title and icon
-
- I_SetWindowCaption();
I_SetWindowIcon();
CreateCursors();
@@ -1568,23 +1607,25 @@ void I_InitGraphics(void)
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();
// 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
@@ -1606,5 +1647,29 @@ void I_InitGraphics(void)
}
initialised = true;
+
+ // Call I_ShutdownGraphics on quit
+
+ I_AtExit(I_ShutdownGraphics, true);
+}
+
+// Bind all variables controlling video options into the configuration
+// file system.
+
+void I_BindVideoVariables(void)
+{
+ M_BindVariable("use_mouse", &usemouse);
+ M_BindVariable("autoadjust_video_settings", &autoadjust_video_settings);
+ M_BindVariable("fullscreen", &fullscreen);
+ M_BindVariable("aspect_ratio_correct", &aspect_ratio_correct);
+ M_BindVariable("startup_delay", &startup_delay);
+ M_BindVariable("screen_width", &screen_width);
+ M_BindVariable("screen_height", &screen_height);
+ M_BindVariable("grabmouse", &grabmouse);
+ M_BindVariable("mouse_acceleration", &mouse_acceleration);
+ M_BindVariable("mouse_threshold", &mouse_threshold);
+ M_BindVariable("video_driver", &video_driver);
+ M_BindVariable("usegamma", &usegamma);
+ M_BindVariable("vanilla_keyboard_mapping", &vanilla_keyboard_mapping);
}