foxygit / doom Log in
commit 3c5aa343cb825f1182f4cc25863cae5a345bc6a3
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Tue May 31 23:03:42 2016 +0100
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Tue May 31 23:03:42 2016 +0100

    video: Rename screen_{width,height} variables.

    These variables no longer mean the same thing they meant in the SDL1
    versions of Chocolate Doom, and they have misleading names. To avoid
    confusion, rename them to window_{width,height}.
---
 src/i_video.c       | 82 ++++++++++++++++++++---------------------------------
 src/m_config.c      | 14 +++------
 src/setup/display.c | 38 ++++++++++++-------------
 3 files changed, 53 insertions(+), 81 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index bb48dc4b..345f775d 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -109,8 +109,8 @@ int diskicon_readbytes = 0;

 // Screen width and height, from configuration file.

-int screen_width = SCREENWIDTH;
-int screen_height = SCREENHEIGHT;
+int window_width = SCREENWIDTH * 2;
+int window_height = SCREENHEIGHT_4_3 * 2;

 // Run in full screen mode?  (int type for config code)

@@ -273,7 +273,7 @@ static int EffectiveScreenHeight(void)
     }
 }

-// Adjust screen_width / screen_height variables to be an an aspect
+// Adjust window_width / window_height variables to be an an aspect
 // ratio consistent with the aspect_ratio_correct variable.
 static void AdjustWindowSize(void)
 {
@@ -281,15 +281,15 @@ static void AdjustWindowSize(void)

     h = EffectiveScreenHeight();

-    if (screen_width * h <= screen_height * SCREENWIDTH)
+    if (window_width * h <= window_height * SCREENWIDTH)
     {
         // The +1 here stops us from repeatedly shrinking the screen size
         // with each call.
-        screen_height = (screen_width + 1) * h / SCREENWIDTH;
+        window_height = (window_width + 1) * h / SCREENWIDTH;
     }
     else
     {
-        screen_width = screen_height * SCREENWIDTH / h;
+        window_width = window_height * SCREENWIDTH / h;
     }
 }

@@ -316,12 +316,12 @@ static void HandleWindowEvent(SDL_WindowEvent *event)
             flags = SDL_GetWindowFlags(screen);
             if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == 0)
             {
-                SDL_GetWindowSize(screen, &screen_width, &screen_height);
+                SDL_GetWindowSize(screen, &window_width, &window_height);

                 // Adjust the window by resizing again so that the window
                 // is the right aspect ratio.
                 AdjustWindowSize();
-                SDL_SetWindowSize(screen, screen_width, screen_height);
+                SDL_SetWindowSize(screen, window_width, window_height);
             }
             break;

@@ -381,7 +381,7 @@ static void I_ToggleFullScreen(void)
     if (!fullscreen)
     {
         AdjustWindowSize();
-        SDL_SetWindowSize(screen, screen_width, screen_height);
+        SDL_SetWindowSize(screen, window_width, window_height);
     }
 }

@@ -787,8 +787,8 @@ static void SetScaleFactor(int factor)
 {
     // Pick 320x200 or 320x240, depending on aspect ratio correct

-    screen_width = factor * SCREENWIDTH;
-    screen_height = factor * EffectiveScreenHeight();
+    window_width = factor * SCREENWIDTH;
+    window_height = factor * EffectiveScreenHeight();
 }

 void I_GraphicsCheckCommandLine(void)
@@ -869,7 +869,7 @@ void I_GraphicsCheckCommandLine(void)

     if (i > 0)
     {
-        screen_width = atoi(myargv[i + 1]);
+        window_width = atoi(myargv[i + 1]);
     }

     //!
@@ -883,7 +883,7 @@ void I_GraphicsCheckCommandLine(void)

     if (i > 0)
     {
-        screen_height = atoi(myargv[i + 1]);
+        window_height = atoi(myargv[i + 1]);
     }

     //!
@@ -904,8 +904,8 @@ void I_GraphicsCheckCommandLine(void)
         s = sscanf(myargv[i + 1], "%ix%i%1c", &w, &h, &f);
         if (s == 2 || s == 3)
         {
-            screen_width = w;
-            screen_height = h;
+            window_width = w;
+            window_height = h;

             if (s == 3 && f == 'f')
             {
@@ -1002,7 +1002,7 @@ static void SetWindowPositionVars(void)
     }
 }

-static void SetVideoMode(int w, int h)
+static void SetVideoMode(void)
 {
     byte *doompal;
     int flags = 0;
@@ -1045,34 +1045,17 @@ static void SetVideoMode(int w, int h)
     // later anyway and leave the window position "undefined". If "flags"
     // contains the fullscreen flag (see above), then w and h are ignored.

-    screen = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
-                                    SDL_WINDOWPOS_UNDEFINED,
-                                    w, h, flags);
+    screen = SDL_CreateWindow(NULL,
+                              SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+                              window_width, window_height, flags);

     if (screen == NULL)
     {
-        I_Error("Error creating window for video mode %ix%i: %s\n",
-                w, h, SDL_GetError());
+        I_Error("Error creating window for video startup: %s", SDL_GetError());
     }

     SDL_SetWindowMinimumSize(screen, SCREENWIDTH, EffectiveScreenHeight());

-    // If we are running fullscreen, the whole screen is our "window".
-
-    if (fullscreen)
-    {
-        SDL_DisplayMode mode;
-
-        // We do not change the video mode to run fullscreen but scale to fill
-        // the desktop that "screen" is assigned to. So, use desktop dimensions
-        // to calculate the size of the upscaled texture.
-
-        SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(screen), &mode);
-
-        h = mode.h;
-        w = mode.w;
-    }
-
     // The SDL_RENDERER_TARGETTEXTURE flag is required to render the
     // intermediate texture into the upscaled texture.

@@ -1080,8 +1063,8 @@ static void SetVideoMode(int w, int h)

     if (renderer == NULL)
     {
-        I_Error("Error creating renderer for video mode %ix%i: %s\n",
-                w, h, SDL_GetError());
+        I_Error("Error creating renderer for screen window: %s",
+                SDL_GetError());
     }

     // Important: Set the "logical size" of the rendering context. At the same
@@ -1165,23 +1148,18 @@ void I_InitGraphics(void)
         I_Error("Failed to initialize video: %s", SDL_GetError());
     }

-    //
-    // Enter into graphics mode.
-    //
     // When in screensaver mode, run full screen and auto detect
     // screen dimensions (don't change video mode)
-    //
-
     if (screensaver_mode)
     {
-        SetVideoMode(0, 0);
-    }
-    else
-    {
-        AdjustWindowSize();
-        SetVideoMode(screen_width, screen_height);
+        fullscreen = true;
     }

+    // Create the game window; this may switch graphic modes depending
+    // on configuration.
+    AdjustWindowSize();
+    SetVideoMode();
+
     // Start with a clear black screen
     // (screen will be flipped after we set the palette)

@@ -1237,8 +1215,8 @@ void I_BindVideoVariables(void)
     M_BindIntVariable("fullscreen",                &fullscreen);
     M_BindIntVariable("aspect_ratio_correct",      &aspect_ratio_correct);
     M_BindIntVariable("startup_delay",             &startup_delay);
-    M_BindIntVariable("screen_width",              &screen_width);
-    M_BindIntVariable("screen_height",             &screen_height);
+    M_BindIntVariable("window_width",              &window_width);
+    M_BindIntVariable("window_height",             &window_height);
     M_BindIntVariable("grabmouse",                 &grabmouse);
     M_BindStringVariable("video_driver",           &video_driver);
     M_BindStringVariable("window_position",        &window_position);
diff --git a/src/m_config.c b/src/m_config.c
index 8f988691..f82f8c50 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -720,22 +720,16 @@ static default_t extra_defaults_list[] =
     CONFIG_VARIABLE_INT(startup_delay),

     //!
-    // Screen width in pixels.  If running in full screen mode, this is
-    // the X dimension of the video mode to use.  If running in
-    // windowed mode, this is the width of the window in which the game
-    // will run.
+    // Window width when running in windowed mode.
     //

-    CONFIG_VARIABLE_INT(screen_width),
+    CONFIG_VARIABLE_INT(window_width),

     //!
-    // Screen height in pixels.  If running in full screen mode, this is
-    // the Y dimension of the video mode to use.  If running in
-    // windowed mode, this is the height of the window in which the game
-    // will run.
+    // Window height when running in windowed mode.
     //

-    CONFIG_VARIABLE_INT(screen_height),
+    CONFIG_VARIABLE_INT(window_height),

     //!
     // If this is non-zero, the mouse will be "grabbed" when running
diff --git a/src/setup/display.c b/src/setup/display.c
index fbd49865..ade4a7da 100644
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -71,8 +71,8 @@ static char *video_driver = "";
 static char *window_position = "";
 static int aspect_ratio_correct = 1;
 static int fullscreen = 1;
-static int screen_width = 320;
-static int screen_height = 200;
+static int window_width = 640;
+static int window_height = 480;
 static int startup_delay = 1000;
 static int usegamma = 0;

@@ -81,12 +81,12 @@ int show_endoom = 1;
 int show_diskicon = 1;
 int png_screenshots = 0;

-// These are the last screen width/height values that were chosen by the
+// These are the last window width/height values that were chosen by the
 // user.  These are used when finding the "nearest" mode, so when
 // changing the fullscreen / aspect ratio options, the setting does not
 // jump around.

-static int selected_screen_width = 0, selected_screen_height;
+static int selected_window_width = 0, selected_window_height;

 static int system_video_env_set;

@@ -126,13 +126,13 @@ static void ModeSelected(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(mode))
 {
     TXT_CAST_ARG(screen_mode_t, mode);

-    screen_width = mode->w;
-    screen_height = mode->h;
+    window_width = mode->w;
+    window_height = mode->h;

     // This is now the most recently selected screen width

-    selected_screen_width = screen_width;
-    selected_screen_height = screen_height;
+    selected_window_width = window_width;
+    selected_window_height = window_height;
 }

 static int FindBestMode(screen_mode_t *modes)
@@ -147,10 +147,10 @@ static int FindBestMode(screen_mode_t *modes)

     for (i=0; modes[i].w != 0; ++i)
     {
-        diff = (selected_screen_width - modes[i].w)
-                  * (selected_screen_width - modes[i].w)
-             + (selected_screen_height - modes[i].h)
-                  * (selected_screen_height - modes[i].h);
+        diff = (selected_window_width - modes[i].w)
+                  * (selected_window_width - modes[i].w)
+             + (selected_window_height - modes[i].h)
+                  * (selected_window_height - modes[i].h);

         if (best_mode == -1 || diff < best_mode_diff)
         {
@@ -202,8 +202,8 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget),

     if (vidmode > 0)
     {
-        screen_width = modes[vidmode].w;
-        screen_height = modes[vidmode].h;
+        window_width = modes[vidmode].w;
+        window_height = modes[vidmode].h;
     }
 }

@@ -264,10 +264,10 @@ void ConfigDisplay(void)

     // First time in? Initialise selected_screen_{width,height}

-    if (selected_screen_width == 0)
+    if (selected_window_width == 0)
     {
-        selected_screen_width = screen_width;
-        selected_screen_height = screen_height;
+        selected_window_width = window_width;
+        selected_window_height = window_height;
     }

     // Open the window
@@ -341,8 +341,8 @@ void BindDisplayVariables(void)
 {
     M_BindIntVariable("aspect_ratio_correct",      &aspect_ratio_correct);
     M_BindIntVariable("fullscreen",                &fullscreen);
-    M_BindIntVariable("screen_width",              &screen_width);
-    M_BindIntVariable("screen_height",             &screen_height);
+    M_BindIntVariable("window_width",              &window_width);
+    M_BindIntVariable("window_height",             &window_height);
     M_BindIntVariable("startup_delay",             &startup_delay);
     M_BindStringVariable("video_driver",           &video_driver);
     M_BindStringVariable("window_position",        &window_position);