shithub: choc

Download patch

ref: 4a81379a448a58feed9668c24be115748d3229db
parent: bd41935ec4bbd8aa287a870cca8cfd33064665fc
author: Simon Howard <[email protected]>
date: Sat Oct 14 10:05:51 EDT 2006

Refactor I_InitGraphics.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 701

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_video.c 700 2006-10-14 13:59:28Z fraggle $
+// $Id: i_video.c 701 2006-10-14 14:05:51Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -175,7 +175,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_video.c 700 2006-10-14 13:59:28Z fraggle $";
+rcsid[] = "$Id: i_video.c 701 2006-10-14 14:05:51Z fraggle $";
 
 #include <SDL.h>
 #include <ctype.h>
@@ -265,7 +265,6 @@
 // disk image data and background overwritten by the disk to be
 // restored by EndRead
 
-static boolean use_loading_disk;
 static byte *disk_image = NULL;
 static int disk_image_w, disk_image_h;
 static byte *saved_background;
@@ -337,7 +336,19 @@
 {
     patch_t *disk;
     int y;
+    char buf[20];
 
+    SDL_VideoDriverName(buf, 15);
+
+    if (!strcmp(buf, "Quartz"))
+    {
+        // MacOS Quartz gives us pageflipped graphics that screw up the 
+        // display when we use the loading disk.  Disable it.
+        // This is a gross hack.
+
+        return;
+    }
+
     if (M_CheckParm("-cdrom") > 0)
         disk = (patch_t *) W_CacheLumpName(DEH_String("STCDROM"), PU_STATIC);
     else
@@ -1051,14 +1062,8 @@
     return false;
 }
 
-void I_InitGraphics(void)
+static void CheckCommandLine(void)
 {
-    SDL_Event dummy;
-    char buf[20];
-    int flags = 0;
-
-    SDL_Init(SDL_INIT_VIDEO);
-
     // mouse grabbing
 
     if (M_CheckParm("-grabmouse"))
@@ -1107,74 +1112,94 @@
         screenmultiply = 1;
     if (screenmultiply > 4)
         screenmultiply = 4;
+}
 
-    if (fullscreen && autoadjust_video_settings)
-    {
-        int oldw, oldh;
-        int old_fullscreen, old_screenmultiply;
+static void AutoAdjustSettings(void)
+{
+    int oldw, oldh;
+    int old_fullscreen, old_screenmultiply;
 
-        GetWindowDimensions(&oldw, &oldh);
-        old_screenmultiply = screenmultiply;
-        old_fullscreen = fullscreen;
+    GetWindowDimensions(&oldw, &oldh);
+    old_screenmultiply = screenmultiply;
+    old_fullscreen = fullscreen;
 
-        if (!CheckValidFSMode() && screenmultiply == 1 
-         && fullscreen == FULLSCREEN_ON)
-        {
-            // 320x200 is not valid.
+    if (!CheckValidFSMode() && screenmultiply == 1 
+     && fullscreen == FULLSCREEN_ON)
+    {
+        // 320x200 is not valid.
 
-            // Try turning on letterbox mode - avoid doubling up
-            // the screen if possible
+        // Try turning on letterbox mode - avoid doubling up
+        // the screen if possible
 
-            fullscreen = FULLSCREEN_LETTERBOX;
+        fullscreen = FULLSCREEN_LETTERBOX;
 
-            if (!CheckValidFSMode())
-            {
-                // That doesn't work. Change it back.
+        if (!CheckValidFSMode())
+        {
+            // That doesn't work. Change it back.
 
-                fullscreen = FULLSCREEN_ON;
-            }
+            fullscreen = FULLSCREEN_ON;
         }
+    }
 
-        if (!CheckValidFSMode() && screenmultiply == 1)
-        {
-            // Try doubling up the screen to 640x400
+    if (!CheckValidFSMode() && screenmultiply == 1)
+    {
+        // Try doubling up the screen to 640x400
 
-            screenmultiply = 2;
-        }
+        screenmultiply = 2;
+    }
 
-        if (!CheckValidFSMode() && fullscreen == FULLSCREEN_ON)
-        {
-            // This is not a valid mode.  Try turning on letterbox mode
+    if (!CheckValidFSMode() && fullscreen == FULLSCREEN_ON)
+    {
+        // This is not a valid mode.  Try turning on letterbox mode
 
-            fullscreen = FULLSCREEN_LETTERBOX;
-        }
+        fullscreen = FULLSCREEN_LETTERBOX;
+    }
 
-        if (old_fullscreen != fullscreen 
-         || old_screenmultiply != screenmultiply)
-        {
-            printf("I_InitGraphics: %ix%i resolution is not supported "
-                   "on this machine. \n", oldw, oldh);
-            printf("I_InitGraphics: Video settings adjusted to "
-                   "compensate:\n");
-            
-            if (fullscreen != old_fullscreen)
-                printf("\tletterbox mode on (fullscreen=2)\n");
-            if (screenmultiply != old_screenmultiply)
-                printf("\tscreenmultiply=%i\n", screenmultiply);
-            
-            printf("NOTE: Your video settings have been adjusted.  "
-                   "To disable this behavior,\n"
-                   "set autoadjust_video_settings to 0 in your "
-                   "configuration file.\n");
-        }
+    if (old_fullscreen != fullscreen 
+     || old_screenmultiply != screenmultiply)
+    {
+        printf("I_InitGraphics: %ix%i resolution is not supported "
+               "on this machine. \n", oldw, oldh);
+        printf("I_InitGraphics: Video settings adjusted to "
+               "compensate:\n");
         
-        if (!CheckValidFSMode())
-        {
-            printf("I_InitGraphics: WARNING: Unable to find a valid "
-                   "fullscreen video mode to run in.\n");
-        }
+        if (fullscreen != old_fullscreen)
+            printf("\tletterbox mode on (fullscreen=2)\n");
+        if (screenmultiply != old_screenmultiply)
+            printf("\tscreenmultiply=%i\n", screenmultiply);
+        
+        printf("NOTE: Your video settings have been adjusted.  "
+               "To disable this behavior,\n"
+               "set autoadjust_video_settings to 0 in your "
+               "configuration file.\n");
     }
+    
+    if (!CheckValidFSMode())
+    {
+        printf("I_InitGraphics: WARNING: Unable to find a valid "
+               "fullscreen video mode to run in.\n");
+    }
+}
 
+void I_InitGraphics(void)
+{
+    SDL_Event dummy;
+    int flags = 0;
+
+    SDL_Init(SDL_INIT_VIDEO);
+
+    // Check for command-line video-related parameters.
+
+    CheckCommandLine();
+
+    if (fullscreen && autoadjust_video_settings)
+    {
+        // Check that the fullscreen mode we are trying to use is valid;
+        // if not, try to automatically select a more appropriate one.
+
+        AutoAdjustSettings();
+    }
+
     GetWindowDimensions(&windowwidth, &windowheight);
 
     flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF;
@@ -1256,25 +1281,11 @@
 	screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL);
     }
 
-    use_loading_disk = true;
-
-    SDL_VideoDriverName(buf, 15);
-
-    if (!strcmp(buf, "Quartz"))
-    {
-        // MacOS Quartz gives us pageflipped graphics that screw up the 
-        // display when we use the loading disk.  Disable it.
-        // This is a gross hack.
-
-        use_loading_disk = false;
-    }
-
     // "Loading from disk" icon
 
-    if (use_loading_disk)
-    {
-        LoadDiskImage();
-    }
+    LoadDiskImage();
+
+    // Clear the screen to black.
 
     memset(screens[0], 0, SCREENWIDTH * SCREENHEIGHT);