From 2e5a488d5fbab4ec6109654385ae0284e69052ef Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 4 Dec 2021 17:53:00 +0100 Subject: [PATCH] Add OptionEntry for graphics --- Source/dx.cpp | 4 +-- Source/engine/demomode.cpp | 8 ++++-- Source/options.cpp | 54 ++++++++++++++++++++++---------------- Source/options.h | 16 ++++++----- Source/utils/display.cpp | 28 ++++++++++---------- 5 files changed, 64 insertions(+), 46 deletions(-) diff --git a/Source/dx.cpp b/Source/dx.cpp index f0562998f..ee46febb7 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -190,7 +190,7 @@ void dx_cleanup() RendererTextureSurface = nullptr; #ifndef USE_SDL1 texture = nullptr; - if (sgOptions.Graphics.bUpscale) + if (*sgOptions.Graphics.upscale) SDL_DestroyRenderer(renderer); #endif SDL_DestroyWindow(ghMainWnd); @@ -312,7 +312,7 @@ void RenderPresent() #endif SDL_RenderPresent(renderer); - if (!sgOptions.Graphics.bVSync) { + if (!*sgOptions.Graphics.vSync) { LimitFrameRate(); } } else { diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 3b286d9c2..02ae7746c 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -146,12 +146,16 @@ void OverrideOptions() { sgOptions.Graphics.nWidth = DemoGraphicsWidth; sgOptions.Graphics.nHeight = DemoGraphicsHeight; - sgOptions.Graphics.bFitToScreen = false; +#ifndef USE_SDL1 + sgOptions.Graphics.fitToScreen.SetValue(false); +#endif #if SDL_VERSION_ATLEAST(2, 0, 0) sgOptions.Graphics.bHardwareCursor = false; #endif if (Timedemo) { - sgOptions.Graphics.bVSync = false; +#ifndef USE_SDL1 + sgOptions.Graphics.vSync.SetValue(false); +#endif sgOptions.Graphics.limitFPS.SetValue(false); } } diff --git a/Source/options.cpp b/Source/options.cpp index bb6be7def..4843b79c3 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -301,19 +301,6 @@ void LoadOptions() sgOptions.Graphics.nWidth = GetIniInt("Graphics", "Width", DEFAULT_WIDTH); sgOptions.Graphics.nHeight = GetIniInt("Graphics", "Height", DEFAULT_HEIGHT); -#ifndef __vita__ - sgOptions.Graphics.bFullscreen = GetIniBool("Graphics", "Fullscreen", true); -#else - sgOptions.Graphics.bFullscreen = true; -#endif -#if !defined(USE_SDL1) - sgOptions.Graphics.bUpscale = GetIniBool("Graphics", "Upscale", true); -#else - sgOptions.Graphics.bUpscale = false; -#endif - sgOptions.Graphics.bFitToScreen = GetIniBool("Graphics", "Fit to Screen", true); - sgOptions.Graphics.bIntegerScaling = GetIniBool("Graphics", "Integer Scaling", false); - sgOptions.Graphics.bVSync = GetIniBool("Graphics", "Vertical Sync", true); sgOptions.Graphics.nGammaCorrection = GetIniInt("Graphics", "Gamma Correction", 100); #if SDL_VERSION_ATLEAST(2, 0, 0) sgOptions.Graphics.bHardwareCursor = GetIniBool("Graphics", "Hardware Cursor", HardwareCursorDefault()); @@ -369,15 +356,6 @@ void SaveOptions() SetIniValue("Audio", "Resampling Quality", sgOptions.Audio.nResamplingQuality); SetIniValue("Graphics", "Width", sgOptions.Graphics.nWidth); SetIniValue("Graphics", "Height", sgOptions.Graphics.nHeight); -#ifndef __vita__ - SetIniValue("Graphics", "Fullscreen", sgOptions.Graphics.bFullscreen); -#endif -#if !defined(USE_SDL1) - SetIniValue("Graphics", "Upscale", sgOptions.Graphics.bUpscale); -#endif - SetIniValue("Graphics", "Fit to Screen", sgOptions.Graphics.bFitToScreen); - SetIniValue("Graphics", "Integer Scaling", sgOptions.Graphics.bIntegerScaling); - SetIniValue("Graphics", "Vertical Sync", sgOptions.Graphics.bVSync); SetIniValue("Graphics", "Gamma Correction", sgOptions.Graphics.nGammaCorrection); #if SDL_VERSION_ATLEAST(2, 0, 0) SetIniValue("Graphics", "Hardware Cursor", sgOptions.Graphics.bHardwareCursor); @@ -596,28 +574,60 @@ std::vector AudioOptions::GetEntries() GraphicsOptions::GraphicsOptions() : OptionCategoryBase("Graphics", N_("Graphics"), N_("Graphics Settings")) + , fullscreen("Fullscreen", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Fullscreen"), N_("Display the game in windowed or fullscreen mode."), true) +#if !defined(USE_SDL1) || defined(__3DS__) + , fitToScreen("Fit to Screen", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Fit to Screen"), N_("Automatically adjust the game window to your current desktop screen aspect ratio and resolution."), true) +#endif +#ifndef USE_SDL1 + , upscale("Upscale", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Upscale"), N_("Enables image scaling from the game resolution to your monitor resolution. Prevents changing the monitor resolution and allows window resizing."), true) , scaleQuality("Scaling Quality", OptionEntryFlags::None, N_("Scaling Quality"), N_("Enables optional filters to the output image when upscaling."), ScalingQuality::AnisotropicFiltering, { { ScalingQuality::NearestPixel, N_("Nearest Pixel") }, { ScalingQuality::BilinearFiltering, N_("Bilinear") }, { ScalingQuality::AnisotropicFiltering, N_("Anisotropic") }, }) + , integerScaling("Integer Scaling", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Integer Scaling"), N_("Scales the image using whole number pixel ratio."), false) + , vSync("Vertical Sync", OptionEntryFlags::RecreateUI, N_("Vertical Sync"), N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."), true) +#endif , blendedTransparancy("Blended Transparency", OptionEntryFlags::CantChangeInGame, N_("Blended Transparency"), N_("Enables uniform transparency mode. This setting affects the transparency on walls, game text menus, and boxes. If disabled will default to old checkerboard transparency."), true) , colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true) , limitFPS("FPS Limiter", OptionEntryFlags::None, N_("FPS Limiter"), N_("FPS is limited to avoid high CPU load. Limit considers refresh rate."), true) , showFPS("Show FPS", OptionEntryFlags::None, N_("Show FPS"), N_("Displays the FPS in the upper left corner of the screen."), true) { + fullscreen.SetValueChangedCallback(ResizeWindow); +#if !defined(USE_SDL1) || defined(__3DS__) + fitToScreen.SetValueChangedCallback(ResizeWindow); +#endif +#ifndef USE_SDL1 + upscale.SetValueChangedCallback(ResizeWindow); + scaleQuality.SetValueChangedCallback(ReinitializeRenderer); + integerScaling.SetValueChangedCallback(ResizeWindow); + vSync.SetValueChangedCallback(ReinitializeRenderer); +#endif showFPS.SetValueChangedCallback(OptionShowFPSChanged); } std::vector GraphicsOptions::GetEntries() { + // clang-format off return { +#ifndef __vita__ + &fullscreen, +#endif +#if !defined(USE_SDL1) || defined(__3DS__) + &fitToScreen, +#endif +#ifndef USE_SDL1 + &upscale, &scaleQuality, + &integerScaling, + &vSync, +#endif &blendedTransparancy, &colorCycling, &limitFPS, &showFPS, }; + // clang-format on } GameplayOptions::GameplayOptions() diff --git a/Source/options.h b/Source/options.h index 7efe000b8..57afe6aaf 100644 --- a/Source/options.h +++ b/Source/options.h @@ -300,17 +300,21 @@ struct GraphicsOptions : OptionCategoryBase { /** @brief Render height. */ int nHeight; /** @brief Run in fullscreen or windowed mode. */ - bool bFullscreen; - /** @brief Scale the image after rendering. */ - bool bUpscale; + OptionEntryBoolean fullscreen; +#if !defined(USE_SDL1) || defined(__3DS__) /** @brief Expand the aspect ratio to match the screen. */ - bool bFitToScreen; + OptionEntryBoolean fitToScreen; +#endif +#ifndef USE_SDL1 + /** @brief Scale the image after rendering. */ + OptionEntryBoolean upscale; /** @brief See SDL_HINT_RENDER_SCALE_QUALITY. */ OptionEntryEnum scaleQuality; /** @brief Only scale by values divisible by the width and height. */ - bool bIntegerScaling; + OptionEntryBoolean integerScaling; /** @brief Enable vsync on the output. */ - bool bVSync; + OptionEntryBoolean vSync; +#endif /** @brief Use blended transparency rather than stippled. */ OptionEntryBoolean blendedTransparancy; /** @brief Gamma correction level. */ diff --git a/Source/utils/display.cpp b/Source/utils/display.cpp index 291194e35..f74a76336 100644 --- a/Source/utils/display.cpp +++ b/Source/utils/display.cpp @@ -61,7 +61,7 @@ void CalculatePreferdWindowSize(int &width, int &height) ErrSdl(); } - if (!sgOptions.Graphics.bIntegerScaling) { + if (!*sgOptions.Graphics.integerScaling) { float wFactor = (float)mode.w / width; float hFactor = (float)mode.h / height; @@ -103,7 +103,7 @@ Size GetPreferedWindowSize() Size windowSize = { sgOptions.Graphics.nWidth, sgOptions.Graphics.nHeight }; #ifndef USE_SDL1 - if (sgOptions.Graphics.bUpscale && sgOptions.Graphics.bFitToScreen) { + if (*sgOptions.Graphics.upscale && *sgOptions.Graphics.fitToScreen) { CalculatePreferdWindowSize(windowSize.width, windowSize.height); } #endif @@ -132,7 +132,7 @@ void SetVideoModeToPrimary(bool fullscreen, int width, int height) flags |= SDL_FULLSCREEN; #ifdef __3DS__ flags &= ~SDL_FULLSCREEN; - flags |= Get3DSScalingFlag(sgOptions.Graphics.bFitToScreen, width, height); + flags |= Get3DSScalingFlag(*sgOptions.Graphics.fitToScreen, width, height); #endif SetVideoMode(width, height, SDL1_VIDEO_MODE_BPP, flags); if (OutputRequiresScaling()) @@ -201,18 +201,18 @@ bool SpawnWindow(const char *lpWindowName) #ifdef USE_SDL1 SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); - SetVideoModeToPrimary(!gbForceWindowed && sgOptions.Graphics.bFullscreen, windowSize.width, windowSize.height); + SetVideoModeToPrimary(!gbForceWindowed && *sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height); if (*sgOptions.Gameplay.grabInput) SDL_WM_GrabInput(SDL_GRAB_ON); atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen. #else int flags = 0; - if (sgOptions.Graphics.bUpscale) { - if (!gbForceWindowed && sgOptions.Graphics.bFullscreen) { + if (*sgOptions.Graphics.upscale) { + if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } flags |= SDL_WINDOW_RESIZABLE; - } else if (!gbForceWindowed && sgOptions.Graphics.bFullscreen) { + } else if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { flags |= SDL_WINDOW_FULLSCREEN; } @@ -259,10 +259,10 @@ void ReinitializeRenderer() renderer = nullptr; } - if (sgOptions.Graphics.bUpscale) { + if (*sgOptions.Graphics.upscale) { Uint32 rendererFlags = SDL_RENDERER_ACCELERATED; - if (sgOptions.Graphics.bVSync) { + if (*sgOptions.Graphics.vSync) { rendererFlags |= SDL_RENDERER_PRESENTVSYNC; } @@ -276,7 +276,7 @@ void ReinitializeRenderer() texture = SDLWrap::CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight); - if (sgOptions.Graphics.bIntegerScaling && SDL_RenderSetIntegerScale(renderer, SDL_TRUE) < 0) { + if (*sgOptions.Graphics.integerScaling && SDL_RenderSetIntegerScale(renderer, SDL_TRUE) < 0) { ErrSdl(); } @@ -304,15 +304,15 @@ void ResizeWindow() Size windowSize = GetPreferedWindowSize(); #ifdef USE_SDL1 - SetVideoModeToPrimary(!gbForceWindowed && sgOptions.Graphics.bFullscreen, windowSize.width, windowSize.height); + SetVideoModeToPrimary(!gbForceWindowed && *sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height); #else int flags = 0; - if (sgOptions.Graphics.bUpscale) { - if (!gbForceWindowed && sgOptions.Graphics.bFullscreen) { + if (*sgOptions.Graphics.upscale) { + if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } SDL_SetWindowResizable(ghMainWnd, SDL_TRUE); - } else if (!gbForceWindowed && sgOptions.Graphics.bFullscreen) { + } else if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { flags |= SDL_WINDOW_FULLSCREEN; SDL_SetWindowResizable(ghMainWnd, SDL_FALSE); }