From 7a9e9fada4c43a176aad0c3003ad0e05c8dc9320 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 12 Aug 2013 15:18:19 +0000 Subject: [PATCH] When issuing "setrendmode" OSD command with mismatched vidmode, auto-switch. git-svn-id: https://svn.eduke32.com/eduke32@4015 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/baselayer.h | 2 ++ polymer/eduke32/build/src/baselayer.c | 36 +++++++++++++++++++++-- polymer/eduke32/build/src/build.c | 2 ++ polymer/eduke32/source/osdcmds.c | 6 ++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index f4c91c4da..518b74e05 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -38,6 +38,8 @@ extern char offscreenrendering; void calc_ylookup(int32_t bpl, int32_t lastyidx); #ifdef USE_OPENGL +int32_t (*baselayer_osdcmd_vidmode_func)(const osdfuncparm_t *parm); + void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f); extern int32_t osdcmd_glinfo(const osdfuncparm_t *parm); diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index 449d23cde..de0b6b32f 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -207,19 +207,49 @@ struct glinfo_t glinfo = int32_t flushlogwindow = 1; #ifdef USE_OPENGL +// Used to register the game's / editor's osdcmd_vidmode() functions here. +int32_t (*baselayer_osdcmd_vidmode_func)(const osdfuncparm_t *parm); + static int32_t osdfunc_setrendermode(const osdfuncparm_t *parm) { int32_t m; char *p; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; + m = Bstrtol(parm->parms[0], &p, 10); - if (m < REND_CLASSIC || m > REND_POLYMER) return OSDCMD_SHOWHELP; + if (m != REND_CLASSIC && m != REND_POLYMOST && m != REND_POLYMER) + return OSDCMD_SHOWHELP; + + if ((m==REND_CLASSIC) != (bpp==8) && baselayer_osdcmd_vidmode_func) + { + // Mismatch between video mode and requested renderer, do auto switch. + osdfuncparm_t parm; + char arg[4]; + + const char *ptrptr[1]; + ptrptr[0] = arg; + + Bmemset(&parm, 0, sizeof(parm)); + + if (m==REND_CLASSIC) + Bmemcpy(&arg, "8", 2); + else + Bmemcpy(&arg, "32", 3); + + // CAUTION: we assume that the osdcmd_vidmode function doesn't use any + // other member! + parm.numparms = 1; + parm.parms = ptrptr; + + baselayer_osdcmd_vidmode_func(&parm); + } setrendermode(m); - switch(getrendermode()) + switch (getrendermode()) { case REND_CLASSIC: p = "classic software"; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 8331ac677..134442bd1 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -512,9 +512,11 @@ int32_t app_main(int32_t argc, const char **argv) #ifdef USE_OPENGL OSD_RegisterFunction("restartvid","restartvid: reinitialize the video mode",osdcmd_restartvid); OSD_RegisterFunction("vidmode","vidmode : immediately change the video mode",osdcmd_vidmode); + baselayer_osdcmd_vidmode_func = osdcmd_vidmode; #else OSD_RegisterFunction("vidmode","vidmode : immediately change the video mode",osdcmd_vidmode); #endif + wm_setapptitle("Mapster32"); editstatus = 1; diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 09dbb2cee..d1fafdaa1 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -1604,11 +1604,9 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("unbindall","unbindall: unbinds all keys", osdcmd_unbindall); OSD_RegisterFunction("vidmode","vidmode : change the video mode",osdcmd_vidmode); -#if 0 - OSD_RegisterFunction("savestate","",osdcmd_savestate); - OSD_RegisterFunction("restorestate","",osdcmd_restorestate); +#ifdef USE_OPENGL + baselayer_osdcmd_vidmode_func = osdcmd_vidmode; #endif - return 0; }