On Windows, auto-determine r_screenaspect on startup.

Consequently, it's not saved as a setting in either the game or editor
config files.  We do this by calling "GetSystemMetrics(SM_CXSCREEN)"
(accordingly for y) and calculating the cvar by dividing common factors,
since it has to be in the form WWHH.  This may fail for _really_ strange
screen dimensions, so a log message is printed at the very beginning.

git-svn-id: https://svn.eduke32.com/eduke32@2601 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-04-09 19:22:00 +00:00
parent 8e0ea2e9c5
commit db6225eb5d
3 changed files with 58 additions and 5 deletions

View file

@ -297,11 +297,18 @@ static int32_t osdcmd_cvar_set_baselayer(const osdfuncparm_t *parm)
int32_t baselayer_init(void) int32_t baselayer_init(void)
{ {
uint32_t i; uint32_t i;
#ifdef _WIN32
// on Windows, don't save the "r_screenaspect" cvar because the physical screen size is
// determined at startup
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT|CVAR_NOSAVE)
#else
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT)
#endif
cvar_t cvars_engine[] = cvar_t cvars_engine[] =
{ {
{ "r_usenewaspect","r_usenewaspect: enable/disable new screen aspect ratio determination code",(void *) &r_usenewaspect, CVAR_BOOL, 0, 1 }, { "r_usenewaspect","r_usenewaspect: enable/disable new screen aspect ratio determination code",(void *) &r_usenewaspect, CVAR_BOOL, 0, 1 },
{ "r_screenaspect","r_screenaspect: if using the new aspect code and in fullscreen, screen aspect ratio in the form XXYY, e.g. 1609 for 16:9",(void *) &r_screenxy, CVAR_UINT, 100, 9999 }, { "r_screenaspect","r_screenaspect: if using the new aspect code and in fullscreen, screen aspect ratio in the form XXYY, e.g. 1609 for 16:9",
(void *) &r_screenxy, SCREENASPECT_CVAR_TYPE, 100, 9999 },
{ "r_novoxmips","r_novoxmips: turn off/on the use of mipmaps when rendering 8-bit voxels",(void *) &novoxmips, CVAR_BOOL, 0, 1 }, { "r_novoxmips","r_novoxmips: turn off/on the use of mipmaps when rendering 8-bit voxels",(void *) &novoxmips, CVAR_BOOL, 0, 1 },
{ "r_voxels","r_voxels: enable/disable automatic sprite->voxel rendering",(void *) &usevoxels, CVAR_BOOL, 0, 1 }, { "r_voxels","r_voxels: enable/disable automatic sprite->voxel rendering",(void *) &usevoxels, CVAR_BOOL, 0, 1 },
#ifdef YAX_ENABLE #ifdef YAX_ENABLE

View file

@ -201,13 +201,14 @@ int32_t loadsetup(const char *fn)
#endif #endif
if (readconfig(fp, "r_usenewaspect", val, VL) > 0) if (readconfig(fp, "r_usenewaspect", val, VL) > 0)
r_usenewaspect = !!atoi_safe(val); r_usenewaspect = !!atoi_safe(val);
#ifndef RENDERTYPEWIN
if (readconfig(fp, "r_screenxy", val, VL) > 0) if (readconfig(fp, "r_screenxy", val, VL) > 0)
{ {
r_screenxy = clamp(atoi_safe(val), 0, 9999); r_screenxy = clamp(atoi_safe(val), 0, 9999);
if (r_screenxy/100==0 || r_screenxy%100==0) if (r_screenxy/100==0 || r_screenxy%100==0)
r_screenxy = 403; r_screenxy = 403;
} }
#endif
if (readconfig(fp, "gameexecutable", val, VL) > 0) if (readconfig(fp, "gameexecutable", val, VL) > 0)
Bstrcpy(game_executable, val); Bstrcpy(game_executable, val);
@ -399,8 +400,10 @@ int32_t writesetup(const char *fn)
#endif #endif
"; Use new aspect determination code? (classic/Polymost)\n" "; Use new aspect determination code? (classic/Polymost)\n"
"r_usenewaspect = %d\n" "r_usenewaspect = %d\n"
#ifndef RENDERTYPEWIN
"; Screen aspect for fullscreen, in the form WWHH (e.g. 1609 for 16:9)\n" "; Screen aspect for fullscreen, in the form WWHH (e.g. 1609 for 16:9)\n"
"r_screenxy = %d\n" "r_screenxy = %d\n"
#endif
"\n" "\n"
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN
@ -569,8 +572,10 @@ int32_t writesetup(const char *fn)
glusetexcache, glusememcache, gltexfiltermode, glanisotropy,r_downsize,glusetexcompr, glusetexcache, glusememcache, gltexfiltermode, glanisotropy,r_downsize,glusetexcompr,
shadescale, shadescale,
#endif #endif
r_usenewaspect, r_screenxy, r_usenewaspect,
#ifdef RENDERTYPEWIN #ifndef RENDERTYPEWIN
r_screenxy,
#else
maxrefreshfreq, windowpos, windowx, windowy, maxrefreshfreq, windowpos, windowx, windowy,
#endif #endif
vid_gamma_3d>=0?vid_gamma_3d:vid_gamma, vid_gamma_3d>=0?vid_gamma_3d:vid_gamma,

View file

@ -28,6 +28,7 @@
#include "compat.h" #include "compat.h"
#include "winlayer.h" #include "winlayer.h"
#include "baselayer.h"
#include "pragmas.h" #include "pragmas.h"
#include "build.h" #include "build.h"
#include "a.h" #include "a.h"
@ -299,6 +300,31 @@ static void SignalHandler(int32_t signum)
} }
} }
static void divcommon(int32_t *ap, int32_t *bp)
{
const int32_t p[] = {2,3,5,7,11,13,17,19};
const int32_t N = (int32_t)(sizeof(p)/sizeof(p[0]));
int32_t a=*ap, b=*bp;
while (1)
{
int32_t i;
for (i=0; i<N; i++)
if (a%p[i] == 0 && b%p[i]==0)
{
a /= p[i];
b /= p[i];
break;
}
if (i == N)
break;
}
*ap = a;
*bp = b;
}
// //
// WinMain() -- main Windows entry point // WinMain() -- main Windows entry point
// //
@ -497,6 +523,21 @@ int32_t WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, in
startwin_open(); startwin_open();
baselayer_init(); baselayer_init();
// determine physical screen size
{
const int32_t oscreenx = GetSystemMetrics(SM_CXSCREEN);
const int32_t oscreeny = GetSystemMetrics(SM_CYSCREEN);
int32_t screenx=oscreenx, screeny=oscreeny, good=0;
divcommon(&screenx, &screeny);
if (screenx >= 1 && screenx <= 99 && screeny >= 1 && screeny <= 99)
r_screenxy = screenx*100 + screeny, good=1;
initprintf("Automatic fullscreen size determination: %d %d -> %d %d%s.\n",
oscreenx, oscreeny, screenx, screeny, good?"":" (failed)");
}
r = app_main(_buildargc, _buildargv); r = app_main(_buildargc, _buildargv);
fclose(stdout); fclose(stdout);