From dc2a5b0cc922f30e74ebb1dae20995d745221972 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 17 Jun 2018 12:30:01 +0200 Subject: [PATCH] - consolidated the 3 identical versions of I_CheckResolution and I_ClosestResolution. --- src/i_video.h | 2 -- src/posix/cocoa/i_video.mm | 61 --------------------------------- src/posix/sdl/hardware.cpp | 50 --------------------------- src/v_video.cpp | 70 +++++++++++++++++++++++++++++++++++--- src/win32/hardware.cpp | 50 --------------------------- src/win32/win32gliface.cpp | 3 +- 6 files changed, 67 insertions(+), 169 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index b1c56c9a6..2de136fd3 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -13,8 +13,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old); // the original DOS version (if the Heretic/Hexen source is any indicator). void I_WaitVBL(int count); -bool I_CheckResolution (int width, int height, int bpp); -void I_ClosestResolution (int *width, int *height, int bits); enum EDisplayType { diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 8593f86e7..cee330336 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -758,67 +758,6 @@ DFrameBuffer* I_SetMode(int &width, int &height, DFrameBuffer* old) return Video->CreateFrameBuffer(width, height, false, fullscreen, old); } -bool I_CheckResolution(const int width, const int height, const int bits) -{ - int twidth, theight; - - Video->StartModeIterator(bits, fullscreen); - - while (Video->NextMode(&twidth, &theight, NULL)) - { - if (width == twidth && height == theight) - { - return true; - } - } - - return false; -} - -void I_ClosestResolution(int *width, int *height, int bits) -{ - int twidth, theight; - int cwidth = 0, cheight = 0; - int iteration; - uint32_t closest = uint32_t(-1); - - for (iteration = 0; iteration < 2; ++iteration) - { - Video->StartModeIterator(bits, fullscreen); - - while (Video->NextMode(&twidth, &theight, NULL)) - { - if (twidth == *width && theight == *height) - { - return; - } - - if (iteration == 0 && (twidth < *width || theight < *height)) - { - continue; - } - - const uint32_t dist = (twidth - *width) * (twidth - *width) - + (theight - *height) * (theight - *height); - - if (dist < closest) - { - closest = dist; - cwidth = twidth; - cheight = theight; - } - } - - if (closest != uint32_t(-1)) - { - *width = cwidth; - *height = cheight; - return; - } - } -} - - // --------------------------------------------------------------------------- diff --git a/src/posix/sdl/hardware.cpp b/src/posix/sdl/hardware.cpp index 3c000cb8e..d1ba32b1c 100644 --- a/src/posix/sdl/hardware.cpp +++ b/src/posix/sdl/hardware.cpp @@ -123,56 +123,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old) return res; } -bool I_CheckResolution (int width, int height, int bits) -{ - int twidth, theight; - - Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen); - while (Video->NextMode (&twidth, &theight, NULL)) - { - if (width == twidth && height == theight) - return true; - } - return false; -} - -void I_ClosestResolution (int *width, int *height, int bits) -{ - int twidth, theight; - int cwidth = 0, cheight = 0; - int iteration; - uint32_t closest = 4294967295u; - - for (iteration = 0; iteration < 2; iteration++) - { - Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen); - while (Video->NextMode (&twidth, &theight, NULL)) - { - if (twidth == *width && theight == *height) - return; - - if (iteration == 0 && (twidth < *width || theight < *height)) - continue; - - uint32_t dist = (twidth - *width) * (twidth - *width) - + (theight - *height) * (theight - *height); - - if (dist < closest) - { - closest = dist; - cwidth = twidth; - cheight = theight; - } - } - if (closest != 4294967295u) - { - *width = cwidth; - *height = cheight; - return; - } - } -} - //========================================================================== // // SetFPSLimit diff --git a/src/v_video.cpp b/src/v_video.cpp index 193cfae2f..ae34f22a3 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1114,6 +1114,66 @@ void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int real if (_cx2 != NULL) *_cx2 = cx2; } +bool V_CheckResolution(const int width, const int height, const int bits) +{ + int twidth, theight; + + Video->StartModeIterator(bits, fullscreen); + + while (Video->NextMode(&twidth, &theight, NULL)) + { + if (width == twidth && height == theight) + { + return true; + } + } + + return false; +} + +void V_ClosestResolution(int *width, int *height, int bits) +{ + int twidth, theight; + int cwidth = 0, cheight = 0; + int iteration; + uint32_t closest = uint32_t(-1); + + for (iteration = 0; iteration < 2; ++iteration) + { + Video->StartModeIterator(bits, fullscreen); + + while (Video->NextMode(&twidth, &theight, NULL)) + { + if (twidth == *width && theight == *height) + { + return; + } + + if (iteration == 0 && (twidth < *width || theight < *height)) + { + continue; + } + + const uint32_t dist = (twidth - *width) * (twidth - *width) + + (theight - *height) * (theight - *height); + + if (dist < closest) + { + closest = dist; + cwidth = twidth; + cheight = theight; + } + } + + if (closest != uint32_t(-1)) + { + *width = cwidth; + *height = cheight; + return; + } + } +} + bool IVideo::SetResolution (int width, int height, int bits) { int oldwidth, oldheight; @@ -1132,10 +1192,10 @@ bool IVideo::SetResolution (int width, int height, int bits) oldbits = bits; } - I_ClosestResolution (&width, &height, bits); - if (!I_CheckResolution (width, height, bits)) + V_ClosestResolution (&width, &height, bits); + if (!V_CheckResolution (width, height, bits)) { // Try specified resolution - if (!I_CheckResolution (oldwidth, oldheight, oldbits)) + if (!V_CheckResolution (oldwidth, oldheight, oldbits)) { // Try previous resolution (if any) return false; } @@ -1168,7 +1228,7 @@ CCMD (vid_setmode) } const bool goodmode = (width > 0 && height > 0) - && (!fullscreen || (Video != nullptr && I_CheckResolution(width, height, bits))); + && (!fullscreen || (Video != nullptr && V_CheckResolution(width, height, bits))); if (goodmode) { @@ -1267,7 +1327,7 @@ void V_Init2() } I_InitGraphics(); - I_ClosestResolution (&width, &height, 8); + V_ClosestResolution (&width, &height, 8); if (!Video->SetResolution (width, height, 8)) I_FatalError ("Could not set resolution to %d x %d x %d", width, height, 8); diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index f79e6276c..97dfa4403 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -185,56 +185,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old) return res; } -bool I_CheckResolution (int width, int height, int bits) -{ - int twidth, theight; - - Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen); - while (Video->NextMode (&twidth, &theight, NULL)) - { - if (width == twidth && height == theight) - return true; - } - return false; -} - -void I_ClosestResolution (int *width, int *height, int bits) -{ - int twidth, theight; - int cwidth = 0, cheight = 0; - int iteration; - DWORD closest = 4294967295u; - - for (iteration = 0; iteration < 2; iteration++) - { - Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen); - while (Video->NextMode (&twidth, &theight, NULL)) - { - if (twidth == *width && theight == *height) - return; - - if (iteration == 0 && (twidth < *width || theight < *height)) - continue; - - DWORD dist = (twidth - *width) * (twidth - *width) - + (theight - *height) * (theight - *height); - - if (dist < closest) - { - closest = dist; - cwidth = twidth; - cheight = theight; - } - } - if (closest != 4294967295u) - { - *width = cwidth; - *height = cheight; - return; - } - } -} - static void GetCenteredPos (int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight) { DEVMODE displaysettings; diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index cb6da5ff9..300d8b4c3 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -453,6 +453,7 @@ bool Win32GLVideo::GoFullscreen(bool yes) // // //========================================================================== +void V_ClosestResolution(int *width, int *height, int bits); DFrameBuffer *Win32GLVideo::CreateFrameBuffer(int width, int height, bool bgra, bool fs, DFrameBuffer *old) @@ -461,7 +462,7 @@ DFrameBuffer *Win32GLVideo::CreateFrameBuffer(int width, int height, bool bgra, if (fs) { - I_ClosestResolution(&width, &height, 32); + V_ClosestResolution(&width, &height, 32); } m_DisplayWidth = width;