From 66e6bbff0de3be590c657a826fb94bb7ebf16a96 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 13 Feb 2016 21:06:12 +0000 Subject: [PATCH] Add support for changing the refresh rate in SDL builds. Should also fix non-SDL builds. git-svn-id: https://svn.eduke32.com/eduke32@5621 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/sdlayer.h | 2 ++ polymer/eduke32/build/include/winlayer.h | 1 + polymer/eduke32/build/src/sdlayer.c | 25 +++++++++++++++++++++++- polymer/eduke32/source/cmdline.c | 1 + polymer/eduke32/source/config.c | 5 +---- polymer/eduke32/source/screens.c | 4 ++++ polymer/eduke32/source/screens.h | 2 +- 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/polymer/eduke32/build/include/sdlayer.h b/polymer/eduke32/build/include/sdlayer.h index 1c458fee8..31f1b5330 100644 --- a/polymer/eduke32/build/include/sdlayer.h +++ b/polymer/eduke32/build/include/sdlayer.h @@ -9,6 +9,8 @@ #include "compat.h" #include "baselayer.h" +extern int32_t maxrefreshfreq; + #ifdef _WIN32 HWND win_gethwnd(void); HINSTANCE win_gethinstance(void); diff --git a/polymer/eduke32/build/include/winlayer.h b/polymer/eduke32/build/include/winlayer.h index 4994a0d47..1abc30250 100644 --- a/polymer/eduke32/build/include/winlayer.h +++ b/polymer/eduke32/build/include/winlayer.h @@ -12,6 +12,7 @@ extern uint32_t maxrefreshfreq; extern int32_t glusecds; extern char di_disabled; +extern char forcegl; HWND win_gethwnd(void); HINSTANCE win_gethinstance(void); diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 0136ee704..43a3f553a 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -101,6 +101,7 @@ extern int32_t curbrightness, gammabrightness; char nogl=0; static int32_t vsync_render=0; #endif +int32_t maxrefreshfreq=0; // last gamma, contrast, brightness static float lastvidgcb[3]; @@ -1113,7 +1114,8 @@ void getvalidmodes(void) for (i = 0; i < SDL_GetNumDisplayModes(0); i++) { SDL_GetDisplayMode(0, i, &dispmode); - if ((dispmode.w > MAXXDIM) || (dispmode.h > MAXYDIM)) + if ((dispmode.w > MAXXDIM) || (dispmode.h > MAXYDIM) || + (maxrefreshfreq && (dispmode.refresh_rate > maxrefreshfreq))) continue; // HACK: 8-bit == Software, 32-bit == OpenGL @@ -1436,6 +1438,23 @@ void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int } #if SDL_MAJOR_VERSION!=1 +void setrefreshrate(void) +{ + SDL_DisplayMode dispmode; + SDL_GetCurrentDisplayMode(0, &dispmode); + + dispmode.refresh_rate = maxrefreshfreq; + + SDL_DisplayMode newmode; + SDL_GetClosestDisplayMode(0, &dispmode, &newmode); + + if (dispmode.refresh_rate != newmode.refresh_rate) + { + initprintf("Refresh rate: %dHz\n", newmode.refresh_rate); + SDL_SetWindowDisplayMode(sdl_window, &newmode); + } +} + int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) { int32_t regrab = 0, ret; @@ -1505,6 +1524,8 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) SDL_GL_SetSwapInterval(vsync_render); + setrefreshrate(); + #ifdef _WIN32 loadglextensions(); #endif @@ -1520,6 +1541,8 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) if (!sdl_window) SDL2_VIDEO_ERR("SDL_CreateWindow"); + setrefreshrate(); + sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0); if (!sdl_renderer) SDL2_VIDEO_FALLBACK("SDL_CreateRenderer") diff --git a/polymer/eduke32/source/cmdline.c b/polymer/eduke32/source/cmdline.c index 843a5639f..d06c30c51 100644 --- a/polymer/eduke32/source/cmdline.c +++ b/polymer/eduke32/source/cmdline.c @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "demo.h" #include "screens.h" +#include "renderlayer.h" #ifdef LUNATIC char const * const * g_argv; diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 6b7479a52..6bdf48f12 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "scriplib.h" #include "osdcmds.h" +#include "renderlayer.h" #ifdef __ANDROID__ #include "android.h" @@ -607,9 +608,7 @@ int32_t CONFIG_ReadSetup(void) windowy = -1; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy); -#ifdef RENDERTYPEWIN SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); -#endif SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP); if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32; @@ -734,9 +733,7 @@ void CONFIG_WriteSetup(uint32_t flags) SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE); -#ifdef RENDERTYPEWIN SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE); -#endif if (!NAM_WW2GI) { diff --git a/polymer/eduke32/source/screens.c b/polymer/eduke32/source/screens.c index 696e1f6ae..b72ee180e 100644 --- a/polymer/eduke32/source/screens.c +++ b/polymer/eduke32/source/screens.c @@ -604,6 +604,10 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 printext256(20, y+=9, COLOR_WHITE, -1, tempbuf, 0); \ } while (0) +#ifdef DEBUGGINGAIDS +sprstat_t g_spriteStat; +#endif + static void G_PrintCoords(int32_t snum) { const int32_t x = 250; diff --git a/polymer/eduke32/source/screens.h b/polymer/eduke32/source/screens.h index e3291e84a..7e8868d75 100644 --- a/polymer/eduke32/source/screens.h +++ b/polymer/eduke32/source/screens.h @@ -37,7 +37,7 @@ typedef struct { int32_t numonscreen; } sprstat_t; -sprstat_t g_spriteStat; +extern sprstat_t g_spriteStat; #endif extern int32_t dr_yxaspect, dr_viewingrange;