From d738fb7ad5994f7850d85bc8a8eab525ea5b12ec Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 8 Oct 2013 10:00:25 +0000 Subject: [PATCH] Fix the vsync menu option so that it actually works. Variables at global scope which share a name tend to actually be the same variable. Not good when you pass such a variable to function that immediately returns if the passed parameter (the variable) equals said variable (itself). git-svn-id: https://svn.eduke32.com/eduke32@4090 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/baselayer.h | 1 + polymer/eduke32/build/src/build.c | 4 ++++ polymer/eduke32/build/src/engine.c | 2 ++ polymer/eduke32/build/src/polymost.c | 1 + polymer/eduke32/build/src/sdlayer.c | 28 +++++++++++++++++------ polymer/eduke32/build/src/winlayer.c | 16 +++++++++---- polymer/eduke32/source/game.c | 2 ++ 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 8d0c21144..8efd3e612 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -102,6 +102,7 @@ extern int32_t qsetmode; int32_t initsystem(void); void uninitsystem(void); +void system_getcvars(void); extern int32_t flushlogwindow; void initprintf(const char *, ...) ATTRIBUTE((format(printf,1,2))); diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 31cc90c82..4980fdb6e 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -686,6 +686,8 @@ int32_t app_main(int32_t argc, const char **argv) // executed once per init, but after setgamemode so that OSD has the right width OSD_Exec("m32_autoexec.cfg"); + system_getcvars(); + overheadeditor(); keystatus[buildkeys[BK_MODE2D_3D]] = 0; @@ -710,6 +712,8 @@ int32_t app_main(int32_t argc, const char **argv) // executed once per init, but after setgamemode so that OSD has the right width OSD_Exec("m32_autoexec.cfg"); + system_getcvars(); + setbrightness(GAMMA_CALC,0,0); } diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 2801bcb4b..3c9fd7ea1 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -10036,6 +10036,8 @@ skip_reading_mapbin: append_ext_UNSAFE(fn, ".cfg"); OSD_Exec(fn); + + system_getcvars(); } return finish_loadboard(dapos, dacursectnum, numsprites, myflags); diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 2ea33f428..46b55b80a 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -91,6 +91,7 @@ extern char textfont[2048], smalltextfont[2048]; int32_t rendmode=0; int32_t usemodels=1, usehightile=1; +int32_t vsync=0; #include //<-important! typedef struct { float x, cy[2], fy[2]; int32_t tag; int16_t n, p, ctag, ftag; } vsptyp; diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index a38f1fa2a..4d5932f28 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -89,7 +89,7 @@ extern int32_t curbrightness, gammabrightness; // OpenGL stuff char nogl=0; #endif -int32_t vsync=0; +static int32_t vsync_render=0; // last gamma, contrast, brightness static float lastvidgcb[3]; @@ -273,11 +273,16 @@ int32_t main(int32_t argc, char *argv[]) #ifdef USE_OPENGL void setvsync(int32_t sync) { - if (vsync == sync) return; - vsync = sync; + if (vsync_render == sync) return; + vsync_render = sync; +# if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) resetvideomode(); if (setgamemode(fullscreen,xdim,ydim,bpp)) OSD_Printf("restartvid: Reset failed...\n"); +# else + if (sdl_context) + SDL_GL_SetSwapInterval(vsync_render); +# endif } #endif @@ -472,6 +477,15 @@ void uninitsystem(void) } +// +// system_getcvars() -- propagate any cvars that are read post-initialization +// +void system_getcvars(void) +{ + setvsync(vsync); +} + + // // initprintf() -- prints a string to the intitialization window // @@ -1337,7 +1351,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) { SDL_GL_MULTISAMPLESAMPLES, glmultisample }, { SDL_GL_STENCIL_SIZE, 1 }, # if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) - { SDL_GL_SWAP_CONTROL, vsync }, + { SDL_GL_SWAP_CONTROL, vsync_render }, # endif }; @@ -1368,7 +1382,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) so we have to create a new surface in a different format first to force the surface we WANT to be recreated instead of reused. */ # if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) - if (vsync != ovsync) + if (vsync_render != ovsync) { if (sdl_surface) { @@ -1376,7 +1390,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) sdl_surface = SDL_SetVideoMode(1, 1, 8, SDL_NOFRAME | SURFACE_FLAGS | ((fs&1)?SDL_FULLSCREEN:0)); SDL_FreeSurface(sdl_surface); } - ovsync = vsync; + ovsync = vsync_render; } # endif @@ -1411,7 +1425,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) destroy_window_resources(); return -1; } - SDL_GL_SetSwapInterval(vsync); + SDL_GL_SetSwapInterval(vsync_render); #endif #ifdef _WIN32 diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index 731803ad2..522c7bfde 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -144,7 +144,7 @@ int32_t bpp=0; int32_t bytesperline=0; int32_t lockcount=0; int32_t glcolourdepth=32; -int32_t vsync=0; +static int32_t vsync_render=0; uint32_t maxrefreshfreq=60; intptr_t frameplace=0; char modechange=1; @@ -615,6 +615,14 @@ void uninitsystem(void) } +// +// system_getcvars() -- propagate any cvars that are read post-initialization +// +void system_getcvars(void) +{ + setvsync(vsync); +} + // // initprintf() -- prints a string to the intitialization window // @@ -1703,7 +1711,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) } #ifdef USE_OPENGL - if (hGLWindow && glinfo.vsync) bwglSwapIntervalEXT(vsync); + if (hGLWindow && glinfo.vsync) bwglSwapIntervalEXT(vsync_render); #endif if (inp) AcquireInputDevices(1); modechange=1; @@ -1735,10 +1743,10 @@ void setvsync(int32_t sync) { if (!glinfo.vsync) { - vsync = 0; + vsync_render = 0; return; } - vsync = sync; + vsync_render = sync; bwglSwapIntervalEXT(sync); } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 022dd3ef3..eea455763 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -11643,6 +11643,8 @@ int32_t app_main(int32_t argc, const char **argv) OSD_Exec("autoexec.cfg"); + system_getcvars(); + if (g_networkMode != NET_DEDICATED_SERVER) { if (setgamemode(ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP) < 0)