From 21958bc1106a847408cc20e65e579fc1df6621e9 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 18 Nov 2018 18:13:02 +0000 Subject: [PATCH] Minor start window cleanup. This ended up touching a bunch of other files due to variable renaming, but there are zero functional changes to anything but the startup window in this commit. git-svn-id: https://svn.eduke32.com/eduke32@7219 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/sdlayer.h | 4 +- source/duke3d/src/config.cpp | 59 ++--- source/duke3d/src/game.cpp | 32 +-- source/duke3d/src/game.h | 42 ++-- source/duke3d/src/gamedef.cpp | 35 ++- source/duke3d/src/menus.cpp | 14 +- source/duke3d/src/osdcmds.cpp | 28 +-- source/duke3d/src/premap.cpp | 2 +- source/duke3d/src/startgtk.game.cpp | 118 ++++----- source/duke3d/src/startwin.game.cpp | 373 ++++++++++++---------------- 10 files changed, 312 insertions(+), 395 deletions(-) diff --git a/source/build/include/sdlayer.h b/source/build/include/sdlayer.h index 15e6141b6..041ec8209 100644 --- a/source/build/include/sdlayer.h +++ b/source/build/include/sdlayer.h @@ -5,9 +5,9 @@ #ifndef build_interface_layer_ #define build_interface_layer_ SDL -#include "sdl_inc.h" -#include "compat.h" #include "baselayer.h" +#include "compat.h" +#include "sdl_inc.h" #define EDUKE32_SDL_LINKED_PREREQ(x, a, b, c) ((x).major > (a) || ((x).major == (a) && ((x).minor > (b) || ((x).minor == (b) && (x).patch >= (c))))) diff --git a/source/duke3d/src/config.cpp b/source/duke3d/src/config.cpp index 5314d83a7..286bb811f 100644 --- a/source/duke3d/src/config.cpp +++ b/source/duke3d/src/config.cpp @@ -170,8 +170,8 @@ void CONFIG_SetDefaults(void) droidinput.toggleCrouch = 1; droidinput.yaw_sens = 5.f; - ud.config.ScreenWidth = droidinfo.screen_width; - ud.config.ScreenHeight = droidinfo.screen_height; + ud.setup.xdim = droidinfo.screen_width; + ud.setup.ydim = droidinfo.screen_height; #else # if defined RENDERTYPESDL && SDL_MAJOR_VERSION > 1 uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO); @@ -183,21 +183,21 @@ void CONFIG_SetDefaults(void) SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(0, &dm) == 0) { - ud.config.ScreenWidth = dm.w; - ud.config.ScreenHeight = dm.h; + ud.setup.xdim = dm.w; + ud.setup.ydim = dm.h; } else # endif { - ud.config.ScreenWidth = 1024; - ud.config.ScreenHeight = 768; + ud.setup.xdim = 1024; + ud.setup.ydim = 768; } #endif #ifdef USE_OPENGL - ud.config.ScreenBPP = 32; + ud.setup.bpp = 32; #else - ud.config.ScreenBPP = 8; + ud.setup.bpp = 8; #endif #if defined(_WIN32) @@ -217,14 +217,19 @@ void CONFIG_SetDefaults(void) #endif #ifdef GEKKO - ud.config.UseJoystick = 1; + ud.setup.usejoystick = 1; #else - ud.config.UseJoystick = 0; + ud.setup.usejoystick = 0; #endif g_myAimMode = 1; g_player[0].ps->aim_mode = 1; + ud.setup.forcesetup = 1; + ud.setup.noautoload = 1; + ud.setup.fullscreen = 1; + ud.setup.usemouse = 1; + ud.althud = 1; ud.angleinterpolation = 0; ud.auto_run = 1; @@ -239,20 +244,16 @@ void CONFIG_SetDefaults(void) ud.config.AutoAim = 1; ud.config.CheckForUpdates = 1; ud.config.FXVolume = 255; - ud.config.ForceSetup = 1; ud.config.MouseBias = 0; ud.config.MouseDeadZone = 0; ud.config.MusicToggle = 1; ud.config.MusicVolume = 195; - ud.config.NoAutoLoad = 1; ud.config.NumBits = 16; ud.config.NumChannels = 2; ud.config.ReverseStereo = 0; - ud.config.ScreenMode = 1; ud.config.ShowWeapons = 0; ud.config.SmoothInput = 1; ud.config.SoundToggle = 1; - ud.config.UseMouse = 1; ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM ud.config.useprecache = 1; ud.configversion = 0; @@ -615,8 +616,8 @@ int CONFIG_ReadSetup(void) SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ConfigVersion", &ud.configversion); - SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.config.ForceSetup); - SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.config.NoAutoLoad); + SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup", &ud.setup.forcesetup); + SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", &ud.setup.noautoload); int32_t cachesize; SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &cachesize); @@ -656,15 +657,15 @@ int CONFIG_ReadSetup(void) windowy = -1; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.config.ScreenHeight); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.config.ScreenMode); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.config.ScreenWidth); + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp); + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", &ud.setup.ydim); + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", &ud.setup.fullscreen); + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", &ud.setup.xdim); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos); - if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32; + if (ud.setup.bpp < 8) ud.setup.bpp = 32; #ifdef POLYMER int32_t rendmode = 0; @@ -742,17 +743,17 @@ void CONFIG_WriteSetup(uint32_t flags) SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE); SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ConfigVersion", BYTEVERSION_EDUKE32, FALSE, FALSE); - SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.config.ForceSetup, FALSE, FALSE); - SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.config.NoAutoLoad, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup", ud.setup.forcesetup, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad", ud.setup.noautoload, FALSE, FALSE); #ifdef POLYMER SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer", videoGetRenderMode() == REND_POLYMER, FALSE, FALSE); #endif - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.config.ScreenBPP, FALSE, FALSE); - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.config.ScreenHeight, FALSE, FALSE); - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.config.ScreenMode, FALSE, FALSE); - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.config.ScreenWidth, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", ud.setup.bpp, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight", ud.setup.ydim, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode", ud.setup.fullscreen, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth", ud.setup.xdim, FALSE, FALSE); if (g_grpNamePtr && !g_addonNum) SCRIPT_PutString(ud.config.scripthandle, "Setup", "SelectedGRP", g_grpNamePtr); @@ -785,7 +786,7 @@ void CONFIG_WriteSetup(uint32_t flags) SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE); #endif - if (ud.config.UseMouse) + if (ud.setup.usemouse) { for (int i=0; i 1 && g_player[myconnectindex].ps->gm & MODE_GAME && GTFLAGS(GAMETYPE_SCORESHEET) && *msg == ' ') { G_BonusScreen(1); - videoSetGameMode(ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP,ud.detail); + videoSetGameMode(ud.setup.fullscreen,ud.setup.xdim,ud.setup.ydim,ud.setup.bpp,ud.detail); } // shareware and TEN screens @@ -5288,7 +5288,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass) else { initprintf("Using file \"%s\" as game data.\n", fileName); - if (!g_noAutoLoad && !ud.config.NoAutoLoad) + if (!g_noAutoLoad && !ud.setup.noautoload) G_DoAutoload(fileName); } } @@ -6320,7 +6320,7 @@ int app_main(int argc, char const * const * argv) G_ScanGroups(); #ifdef STARTUP_SETUP_WINDOW - if (readSetup < 0 || (!g_noSetup && (ud.configversion != BYTEVERSION_EDUKE32 || ud.config.ForceSetup)) || g_commandSetup) + if (readSetup < 0 || (!g_noSetup && (ud.configversion != BYTEVERSION_EDUKE32 || ud.setup.forcesetup)) || g_commandSetup) { if (quitevent || !startwin_run()) { @@ -6331,7 +6331,7 @@ int app_main(int argc, char const * const * argv) #endif g_logFlushWindow = 0; - G_LoadGroups(!g_noAutoLoad && !ud.config.NoAutoLoad); + G_LoadGroups(!g_noAutoLoad && !ud.setup.noautoload); // flushlogwindow = 1; if (!g_useCwd) @@ -6488,8 +6488,8 @@ int app_main(int argc, char const * const * argv) CONFIG_SetupMouse(); CONFIG_SetupJoystick(); - CONTROL_JoystickEnabled = (ud.config.UseJoystick && CONTROL_JoyPresent); - CONTROL_MouseEnabled = (ud.config.UseMouse && CONTROL_MousePresent); + CONTROL_JoystickEnabled = (ud.setup.usejoystick && CONTROL_JoyPresent); + CONTROL_MouseEnabled = (ud.setup.usemouse && CONTROL_MousePresent); // JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too for (bssize_t i=0; i>2,myplayer.palette,0); diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index dd6a80006..fff5aef78 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -159,6 +159,17 @@ extern camera_t g_camera; #define MAX_RETURN_VALUES 6 // KEEPINSYNC lunatic/_defs_game.lua +typedef struct { + int32_t usejoystick; + int32_t usemouse; + int32_t fullscreen; + int32_t xdim; + int32_t ydim; + int32_t bpp; + int32_t forcesetup; + int32_t noautoload; +} ud_setup_t; + typedef struct { #if !defined LUNATIC vec3_t camerapos; @@ -210,8 +221,6 @@ typedef struct { int8_t menutitle_pal, slidebar_palselected, slidebar_paldisabled; struct { - int32_t UseJoystick; - int32_t UseMouse; int32_t AutoAim; int32_t ShowWeapons; int32_t MouseDeadZone,MouseBias; @@ -248,18 +257,6 @@ typedef struct { int32_t ReverseStereo; - // - // Screen variables - // - - int32_t ScreenMode; - - int32_t ScreenWidth; - int32_t ScreenHeight; - int32_t ScreenBPP; - - int32_t ForceSetup; - int32_t NoAutoLoad; int32_t scripthandle; int32_t setupread; @@ -269,6 +266,8 @@ typedef struct { int32_t useprecache; } config; + ud_setup_t setup; + char overhead_on,last_overhead,showweapons; char god,warp_on,cashman,eog,showallmap; char show_help,scrollmode,noclip; @@ -517,15 +516,12 @@ enum }; -#define G_ModDirSnprintf(buf, size, basename, ...) \ - \ -(((g_modDir[0] != '/') ? Bsnprintf(buf, size, "%s/" basename, g_modDir, ##__VA_ARGS__) \ - : Bsnprintf(buf, size, basename, ##__VA_ARGS__)) >= ((int32_t)size) - 1\ -) -#define G_ModDirSnprintfLite(buf, size, basename) \ - \ -((g_modDir[0] != '/') ? Bsnprintf(buf, size, "%s/%s", g_modDir, basename) \ - : Bsnprintf(buf, size, basename)) +#define G_ModDirSnprintf(buf, size, basename, ...) \ + (((g_modDir[0] != '/') ? Bsnprintf(buf, size, "%s/" basename, g_modDir, ##__VA_ARGS__) : Bsnprintf(buf, size, basename, ##__VA_ARGS__)) \ + >= ((int32_t)size) - 1) + +#define G_ModDirSnprintfLite(buf, size, basename) \ + ((g_modDir[0] != '/') ? Bsnprintf(buf, size, "%s/%s", g_modDir, basename) : Bsnprintf(buf, size, basename)) static inline void G_NewGame_EnterLevel(void) { diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 2ac037ab8..4e874a695 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -2867,29 +2867,24 @@ LUNATIC_EXTERN void C_SetCfgName(const char *cfgname) if (Bstrcmp(g_setupFileName, cfgname) == 0) // no need to do anything if name is the same return; - char temp[BMAX_PATH]; - struct Bstat st; - - int32_t fullscreen = ud.config.ScreenMode; - int32_t xdim = ud.config.ScreenWidth, ydim = ud.config.ScreenHeight, bpp = ud.config.ScreenBPP; - int32_t usemouse = ud.config.UseMouse, usejoy = ud.config.UseJoystick; -#ifdef USE_OPENGL - int32_t glrm = glrendmode; -#endif - if (Bstrcmp(g_setupFileName, SETUPFILENAME) != 0) // set to something else via -cfg return; + ud_setup_t const config = ud.setup; +#ifdef POLYMER + int const renderMode = glrendmode; +#endif + struct Bstat st; + if (Bstat(g_modDir, &st) < 0) { if (errno == ENOENT) // path doesn't exist { if (Bmkdir(g_modDir, S_IRWXU) < 0) { - OSD_Printf("Failed to create configuration file directory %s\n", g_modDir); + OSD_Printf("Failed to create directory \"%s\"!\n", g_modDir); return; } - else OSD_Printf("Created configuration file directory %s\n", g_modDir); } else { @@ -2904,7 +2899,8 @@ LUNATIC_EXTERN void C_SetCfgName(const char *cfgname) } // XXX: Back up 'cfgname' as it may be the global 'tempbuf'. - Bstrncpyz(temp, cfgname, sizeof(temp)); + char *temp = Xstrdup(cfgname); + CONFIG_WriteSetup(1); if (g_modDir[0] != '/') @@ -2912,18 +2908,15 @@ LUNATIC_EXTERN void C_SetCfgName(const char *cfgname) else Bstrncpyz(g_setupFileName, temp, sizeof(g_setupFileName)); + DO_FREE_AND_NULL(temp); + initprintf("Using config file \"%s\".\n", g_setupFileName); CONFIG_ReadSetup(); - ud.config.ScreenMode = fullscreen; - ud.config.ScreenWidth = xdim; - ud.config.ScreenHeight = ydim; - ud.config.ScreenBPP = bpp; - ud.config.UseMouse = usemouse; - ud.config.UseJoystick = usejoy; -#ifdef USE_OPENGL - glrendmode = glrm; + ud.setup = config; +#ifdef POLYMER + glrendmode = renderMode; #endif } diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index f303c3178..ff7bc60c9 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -383,7 +383,7 @@ static MenuEntry_t ME_GAMESETUP_SAVESETUP = MAKE_MENUENTRY( "Save setup", &MF_Re #endif #if defined STARTUP_SETUP_WINDOW && !defined EDUKE32_SIMPLE_MENU -static MenuOption_t MEO_GAMESETUP_STARTWIN = MAKE_MENUOPTION( &MF_Redfont, &MEOS_OffOn, &ud.config.ForceSetup ); +static MenuOption_t MEO_GAMESETUP_STARTWIN = MAKE_MENUOPTION( &MF_Redfont, &MEOS_OffOn, &ud.setup.forcesetup ); static MenuEntry_t ME_GAMESETUP_STARTWIN = MAKE_MENUENTRY( "Startup window:", &MF_Redfont, &MEF_BigOptionsRt, &MEO_GAMESETUP_STARTWIN, Option ); #endif @@ -2038,7 +2038,7 @@ static void Menu_Pre(MenuID_t cm) case MENU_OPTIONS: MenuEntry_DisableOnCondition(&ME_OPTIONS_PLAYERSETUP, ud.recstat == 1); - MenuEntry_HideOnCondition(&ME_OPTIONS_JOYSTICKSETUP, !ud.config.UseJoystick || CONTROL_JoyPresent == 0); + MenuEntry_HideOnCondition(&ME_OPTIONS_JOYSTICKSETUP, !ud.setup.usejoystick || CONTROL_JoyPresent == 0); break; case MENU_COLCORR: @@ -3050,10 +3050,10 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry) G_UpdateScreenArea(); videoSetRenderMode(nrend); vsync = videoSetVsync(nvsync); - ud.config.ScreenMode = fullscreen; - ud.config.ScreenWidth = xres; - ud.config.ScreenHeight = yres; - ud.config.ScreenBPP = bpp; + ud.setup.fullscreen = fullscreen; + ud.setup.xdim = xres; + ud.setup.ydim = yres; + ud.setup.bpp = bpp; } else if (entry == &ME_SOUND_RESTART) { @@ -3289,7 +3289,7 @@ static void Menu_EntryOptionDidModify(MenuEntry_t *entry) videoResetMode(); if (videoSetGameMode(fullscreen, xres, yres, bpp, upscalefactor)) OSD_Printf("restartvid: Reset failed...\n"); - onvideomodechange(ud.config.ScreenBPP>8); + onvideomodechange(ud.setup.bpp>8); G_RefreshLights(); } #endif diff --git a/source/duke3d/src/osdcmds.cpp b/source/duke3d/src/osdcmds.cpp index 6002fe291..c53624586 100644 --- a/source/duke3d/src/osdcmds.cpp +++ b/source/duke3d/src/osdcmds.cpp @@ -424,9 +424,9 @@ int osdcmd_restartvid(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); videoResetMode(); - if (videoSetGameMode(ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP,ud.detail)) + if (videoSetGameMode(ud.setup.fullscreen,ud.setup.xdim,ud.setup.ydim,ud.setup.bpp,ud.detail)) G_GameExit("restartvid: Reset failed...\n"); - onvideomodechange(ud.config.ScreenBPP>8); + onvideomodechange(ud.setup.bpp>8); G_UpdateScreenArea(); return OSDCMD_OK; @@ -444,8 +444,8 @@ int osdcmd_restartmap(osdcmdptr_t UNUSED(parm)) static int osdcmd_vidmode(osdcmdptr_t parm) { - int32_t newbpp = ud.config.ScreenBPP, newwidth = ud.config.ScreenWidth, - newheight = ud.config.ScreenHeight, newfs = ud.config.ScreenMode; + int32_t newbpp = ud.setup.bpp, newwidth = ud.setup.xdim, + newheight = ud.setup.ydim, newfs = ud.setup.fullscreen; int32_t tmp; if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; @@ -478,14 +478,14 @@ static int osdcmd_vidmode(osdcmdptr_t parm) if (videoSetGameMode(newfs,newwidth,newheight,newbpp,upscalefactor)) { initprintf("vidmode: Mode change failed!\n"); - if (videoSetGameMode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP, upscalefactor)) + if (videoSetGameMode(ud.setup.fullscreen, ud.setup.xdim, ud.setup.ydim, ud.setup.bpp, upscalefactor)) G_GameExit("vidmode: Reset failed!\n"); } - ud.config.ScreenBPP = newbpp; - ud.config.ScreenWidth = newwidth; - ud.config.ScreenHeight = newheight; - ud.config.ScreenMode = newfs; - onvideomodechange(ud.config.ScreenBPP>8); + ud.setup.bpp = newbpp; + ud.setup.xdim = newwidth; + ud.setup.ydim = newheight; + ud.setup.fullscreen = newfs; + onvideomodechange(ud.setup.bpp>8); G_UpdateScreenArea(); return OSDCMD_OK; } @@ -1397,11 +1397,11 @@ static int osdcmd_cvar_set_game(osdcmdptr_t parm) } else if (!Bstrcasecmp(parm->name, "in_mouse")) { - CONTROL_MouseEnabled = (ud.config.UseMouse && CONTROL_MousePresent); + CONTROL_MouseEnabled = (ud.setup.usemouse && CONTROL_MousePresent); } else if (!Bstrcasecmp(parm->name, "in_joystick")) { - CONTROL_JoystickEnabled = (ud.config.UseJoystick && CONTROL_JoyPresent); + CONTROL_JoystickEnabled = (ud.setup.usejoystick && CONTROL_JoyPresent); } else if (!Bstrcasecmp(parm->name, "vid_gamma")) { @@ -1576,8 +1576,8 @@ int32_t registerosdcommands(void) { "hud_hidestick", "hide the touch input stick", (void *)&droidinput.hideStick, CVAR_BOOL, 0, 1 }, #endif - { "in_joystick","enables input from the joystick if it is present",(void *)&ud.config.UseJoystick, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 }, - { "in_mouse","enables input from the mouse if it is present",(void *)&ud.config.UseMouse, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 }, + { "in_joystick","enables input from the joystick if it is present",(void *)&ud.setup.usejoystick, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 }, + { "in_mouse","enables input from the mouse if it is present",(void *)&ud.setup.usemouse, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 }, { "in_aimmode", "0:toggle, 1:hold to aim", (void *)&ud.mouseaiming, CVAR_BOOL, 0, 1 }, { diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index d53145c91..4a944e1a1 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -1821,7 +1821,7 @@ int G_EnterLevel(int gameMode) FX_StopAllSounds(); S_ClearSoundLocks(); FX_SetReverb(0); - videoSetGameMode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP, upscalefactor); + videoSetGameMode(ud.setup.fullscreen, ud.setup.xdim, ud.setup.ydim, ud.setup.bpp, upscalefactor); } if (Menu_HaveUserMap()) diff --git a/source/duke3d/src/startgtk.game.cpp b/source/duke3d/src/startgtk.game.cpp index 3fd2bb661..4298de0c4 100644 --- a/source/duke3d/src/startgtk.game.cpp +++ b/source/duke3d/src/startgtk.game.cpp @@ -20,19 +20,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- -#include "compat.h" - -#include "gtkpixdata.h" - -#include "dynamicgtk.h" - -#include "duke3d.h" -#include "grpscan.h" #include "build.h" - -#include "game.h" #include "common.h" #include "common_game.h" +#include "compat.h" +#include "duke3d.h" +#include "dynamicgtk.h" +#include "game.h" +#include "grpscan.h" +#include "gtkpixdata.h" enum { @@ -105,15 +101,9 @@ static struct static struct { grpfile_t const * grp; - int32_t fullscreen; -#ifdef POLYMER - int32_t polymer; -#endif - int32_t xdim3d, ydim3d, bpp3d; - int32_t forcesetup; - int32_t autoload; - int32_t usemouse, usejoy; - char *custommoddir; + char *gamedir; + ud_setup_t shared; + int polymer; } settings; static int32_t retval = -1, mode = TAB_MESSAGES; @@ -133,14 +123,14 @@ static void on_vmode3dcombo_changed(GtkComboBox *combobox, gpointer user_data) if (!gtk_combo_box_get_active_iter(combobox, &iter)) return; if (!(data = gtk_combo_box_get_model(combobox))) return; gtk_tree_model_get(data, &iter, 1, &val, -1); - settings.xdim3d = validmode[val].xdim; - settings.ydim3d = validmode[val].ydim; + settings.shared.xdim = validmode[val].xdim; + settings.shared.ydim = validmode[val].ydim; } static void on_fullscreencheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) { UNREFERENCED_PARAMETER(user_data); - settings.fullscreen = gtk_toggle_button_get_active(togglebutton); + settings.shared.fullscreen = gtk_toggle_button_get_active(togglebutton); PopulateForm(POPULATE_VIDEO); } @@ -152,9 +142,9 @@ static void on_polymercheck_toggled(GtkToggleButton *togglebutton, gpointer user { glrendmode = REND_POLYMER; settings.polymer = TRUE; - if (settings.bpp3d == 8) + if (settings.shared.bpp == 8) { - settings.bpp3d = 32; + settings.shared.bpp = 32; PopulateForm(POPULATE_VIDEO); } } @@ -171,10 +161,10 @@ static void on_inputdevcombo_changed(GtkComboBox *combobox, gpointer user_data) UNREFERENCED_PARAMETER(user_data); switch (gtk_combo_box_get_active(combobox)) { - case 0: settings.usemouse = 0; settings.usejoy = 0; break; - case 1: settings.usemouse = 1; settings.usejoy = 0; break; - case 2: settings.usemouse = 0; settings.usejoy = 1; break; - case 3: settings.usemouse = 1; settings.usejoy = 1; break; + case 0: settings.shared.usemouse = 0; settings.shared.usejoystick = 0; break; + case 1: settings.shared.usemouse = 1; settings.shared.usejoystick = 0; break; + case 2: settings.shared.usemouse = 0; settings.shared.usejoystick = 1; break; + case 3: settings.shared.usemouse = 1; settings.shared.usejoystick = 1; break; } } @@ -193,21 +183,21 @@ static void on_custommodcombo_changed(GtkComboBox *combobox, gpointer user_data) path = gtk_tree_model_get_path(model, &iter); if (*gtk_tree_path_get_indices(path) == NONE) - settings.custommoddir = NULL; - else settings.custommoddir = value; + settings.gamedir = NULL; + else settings.gamedir = value; } } static void on_autoloadcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) { UNREFERENCED_PARAMETER(user_data); - settings.autoload = gtk_toggle_button_get_active(togglebutton); + settings.shared.noautoload = !gtk_toggle_button_get_active(togglebutton); } static void on_alwaysshowcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) { UNREFERENCED_PARAMETER(user_data); - settings.forcesetup = gtk_toggle_button_get_active(togglebutton); + settings.shared.forcesetup = gtk_toggle_button_get_active(togglebutton); } static void on_cancelbutton_clicked(GtkButton *button, gpointer user_data) @@ -316,17 +306,17 @@ static void PopulateForm(unsigned char pgs) GtkTreeIter iter; char buf[64]; - mode3d = videoCheckMode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); + mode3d = videoCheckMode(&settings.shared.xdim, &settings.shared.ydim, settings.shared.bpp, settings.shared.fullscreen, 1); if (mode3d < 0) { int32_t i, cd[] = { 32, 24, 16, 15, 8, 0 }; - for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } + for (i=0; cd[i];) { if (cd[i] >= settings.shared.bpp) i++; else break; } for (; cd[i]; i++) { - mode3d = videoCheckMode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); + mode3d = videoCheckMode(&settings.shared.xdim, &settings.shared.ydim, cd[i], settings.shared.fullscreen, 1); if (mode3d < 0) continue; - settings.bpp3d = cd[i]; + settings.shared.bpp = cd[i]; break; } } @@ -336,7 +326,7 @@ static void PopulateForm(unsigned char pgs) for (i=0; inext) + int const r = ComboBox_AddString(hwnd, "None"); + (void)ComboBox_SetItemData(hwnd, r, 0); + (void)ComboBox_SetCurSel(hwnd, r); + auto dirs = finddirs; + for (int i=1, j=1; dirs != NULL; dirs=dirs->next) { if (Bstrcasecmp(dirs->name, "autoload") == 0) { @@ -133,7 +118,7 @@ static void PopulateForm(int32_t pgs) (void)ComboBox_AddString(hwnd, dirs->name); (void)ComboBox_SetItemData(hwnd, i, j); - if (Bstrcasecmp(dirs->name,settings.gamedir) == 0) + if (Bstrcasecmp(dirs->name, settings.gamedir) == 0) (void)ComboBox_SetCurSel(hwnd, i); i++; @@ -143,41 +128,41 @@ static void PopulateForm(int32_t pgs) if (pgs & POPULATE_VIDEO) { - int32_t mode; + HWND hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE); + int mode = videoCheckMode(&settings.shared.xdim, &settings.shared.ydim, settings.shared.bpp, settings.shared.fullscreen, 1); - hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE); - - mode = videoCheckMode(&settings.xdim, &settings.ydim, settings.bpp, settings.flags&1, 1); - if (mode < 0 || (settings.bpp < 15 && (settings.flags & 2))) + if (mode < 0 || (settings.shared.bpp < 15 && (settings.polymer))) { - int32_t cd[] = { 32, 24, 16, 15, 8, 0 }; + int CONSTEXPR cd[] = { 32, 24, 16, 15, 8, 0 }; + int i; + for (i=0; cd[i];) { - if (cd[i] >= settings.bpp) i++; + if (cd[i] >= settings.shared.bpp) i++; else break; } for (; cd[i]; i++) { - mode = videoCheckMode(&settings.xdim, &settings.ydim, cd[i], settings.flags&1, 1); + mode = videoCheckMode(&settings.shared.xdim, &settings.shared.ydim, cd[i], settings.shared.fullscreen, 1); if (mode < 0) continue; - settings.bpp = cd[i]; + settings.shared.bpp = cd[i]; break; } } - Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), ((settings.flags&1) ? BST_CHECKED : BST_UNCHECKED)); - Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), ((settings.flags&2) ? BST_CHECKED : BST_UNCHECKED)); + Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), ((settings.shared.fullscreen) ? BST_CHECKED : BST_UNCHECKED)); + Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), ((settings.polymer) ? BST_CHECKED : BST_UNCHECKED)); (void)ComboBox_ResetContent(hwnd); - for (i=0; inext) + for (auto fg = foundgrps; fg; fg=fg->next) { Bsprintf(buf, "%s\t%s", fg->type->name, fg->filename); - j = ListBox_AddString(hwnd, buf); + int const j = ListBox_AddString(hwnd, buf); (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg); if (settings.grp == fg) - { (void)ListBox_SetCurSel(hwnd, j); - } } } } @@ -247,61 +227,55 @@ static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L switch (LOWORD(wParam)) { case IDCFULLSCREEN: - if (settings.flags & 1) settings.flags &= ~1; - else settings.flags |= 1; + settings.shared.fullscreen = !settings.shared.fullscreen; PopulateForm(POPULATE_VIDEO); return TRUE; case IDCPOLYMER: - if (settings.flags & 2) settings.flags &= ~2; - else settings.flags |= 2; - if (settings.bpp == 8) settings.bpp = 32; + settings.polymer = !settings.polymer; + if (settings.shared.bpp == 8) settings.shared.bpp = 32; PopulateForm(POPULATE_VIDEO); return TRUE; case IDCVMODE: if (HIWORD(wParam) == CBN_SELCHANGE) { - int32_t i; - i = ComboBox_GetCurSel((HWND)lParam); + int i = ComboBox_GetCurSel((HWND)lParam); if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); if (i != CB_ERR) { - settings.xdim = validmode[i].xdim; - settings.ydim = validmode[i].ydim; - settings.bpp = validmode[i].bpp; + settings.shared.xdim = validmode[i].xdim; + settings.shared.ydim = validmode[i].ydim; + settings.shared.bpp = validmode[i].bpp; } } return TRUE; case IDCALWAYSSHOW: - settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; + settings.shared.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; return TRUE; case IDCAUTOLOAD: - if (IsDlgButtonChecked(hwndDlg, IDCAUTOLOAD) == BST_CHECKED) - settings.flags &= ~4; - else settings.flags |= 4; + settings.shared.noautoload = (IsDlgButtonChecked(hwndDlg, IDCAUTOLOAD) != BST_CHECKED); return TRUE; case IDCINPUT: if (HIWORD(wParam) == CBN_SELCHANGE) { - int32_t i; - i = ComboBox_GetCurSel((HWND)lParam); + int i = ComboBox_GetCurSel((HWND)lParam); if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); if (i != CB_ERR) { switch (i) { case INPUT_KB: - settings.usemouse = settings.usejoy = 0; + settings.shared.usemouse = settings.shared.usejoystick = 0; break; case INPUT_MOUSE: - settings.usemouse = 1; - settings.usejoy = 0; + settings.shared.usemouse = 1; + settings.shared.usejoystick = 0; break; case INPUT_JOYSTICK: - settings.usemouse = 0; - settings.usejoy = 1; + settings.shared.usemouse = 0; + settings.shared.usejoystick = 1; break; case INPUT_ALL: - settings.usemouse = settings.usejoy = 1; + settings.shared.usemouse = settings.shared.usejoystick = 1; break; } } @@ -311,9 +285,7 @@ static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L case IDCGAMEDIR: if (HIWORD(wParam) == CBN_SELCHANGE) { - int32_t i,j; - CACHE1D_FIND_REC *dir = NULL; - i = ComboBox_GetCurSel((HWND)lParam); + int i = ComboBox_GetCurSel((HWND)lParam); if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); if (i != CB_ERR) { @@ -321,21 +293,23 @@ static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L settings.gamedir = NULL; else { - for (j=1,dir=finddirs; dir != NULL; dir=dir->next,j++) + CACHE1D_FIND_REC *dir = finddirs; + for (int j = 1; dir != NULL; dir = dir->next, j++) + { if (j == i) { settings.gamedir = dir->name; break; } + } } } } return TRUE; case IDCDATA: { - intptr_t i; if (HIWORD(wParam) != LBN_SELCHANGE) break; - i = ListBox_GetCurSel((HWND)lParam); + intptr_t i = ListBox_GetCurSel((HWND)lParam); if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i); if (i != CB_ERR) { @@ -354,53 +328,43 @@ static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L } -static void SetPage(int32_t n) +static void SetPage(int pageNum) { - HWND tab; - int32_t cur; - tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); - cur = (int32_t)SendMessage(tab, TCM_GETCURSEL,0,0); - ShowWindow(pages[cur],SW_HIDE); - SendMessage(tab, TCM_SETCURSEL, n, 0); - ShowWindow(pages[n],SW_SHOW); - mode = n; + HWND tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); + auto const cur = SendMessage(tab, TCM_GETCURSEL, 0, 0); + ShowWindow(pages[cur], SW_HIDE); + SendMessage(tab, TCM_SETCURSEL, pageNum, 0); + ShowWindow(pages[pageNum], SW_SHOW); + mode = pageNum; SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL)); } -static void EnableConfig(int32_t n) +static void EnableConfig(bool n) { //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n); EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n); + EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n); EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n); + EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n); + EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUT), n); EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), n); EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n); - EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUT), n); - - EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n); - EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n); } static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HBITMAP hbmp = NULL; - HDC hdc; switch (uMsg) { case WM_INITDIALOG: { - HWND hwnd; - RECT r, rdlg, chrome, rtab, rcancel, rstart; - int32_t xoffset = 0, yoffset = 0; - // Fetch the positions (in screen coordinates) of all the windows we need to tweak - ZeroMemory(&chrome, sizeof(chrome)); + RECT chrome = {}; AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE); + RECT rdlg; GetWindowRect(hwndDlg, &rdlg); - GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); - GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); - GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); // Knock off the non-client area of the main dialogue to give just the client area rdlg.left -= chrome.left; @@ -408,17 +372,26 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, rdlg.right -= chrome.right; rdlg.bottom -= chrome.bottom; + RECT rtab; + GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); + // Translate them to client-relative coordinates wrt the main dialogue window rtab.right -= rtab.left - 1; rtab.bottom -= rtab.top - 1; rtab.left -= rdlg.left; rtab.top -= rdlg.top; + RECT rcancel; + GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); + rcancel.right -= rcancel.left - 1; rcancel.bottom -= rcancel.top - 1; rcancel.left -= rdlg.left; rcancel.top -= rdlg.top; + RECT rstart; + GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); + rstart.right -= rstart.left - 1; rstart.bottom -= rstart.top - 1; rstart.left -= rdlg.left; @@ -432,11 +405,15 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, // Load the bitmap into the bitmap control and fetch its dimensions hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP)); - hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP); + + HWND hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_BITMAP); SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); + + RECT r; GetClientRect(hwnd, &r); - xoffset = r.right; - yoffset = r.bottom - rdlg.bottom; + + int const xoffset = r.right; + int const yoffset = r.bottom - rdlg.bottom; // Shift and resize the controls that require it rtab.left += xoffset; @@ -454,7 +431,7 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE); // Move the main dialogue to the centre of the screen - hdc = GetDC(NULL); + HDC hdc = GetDC(NULL); rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2; rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2; ReleaseDC(NULL, hdc); @@ -463,17 +440,16 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, // Add tabs to the tab control { - TCITEM tab; + static char textSetup[] = TEXT("Setup"); + static char textMessageLog[] = TEXT("Message Log"); hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL); - ZeroMemory(&tab, sizeof(tab)); + TCITEM tab = {}; tab.mask = TCIF_TEXT; - static char textSetup[] = TEXT("Setup"); tab.pszText = textSetup; SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab); tab.mask = TCIF_TEXT; - static char textMessageLog[] = TEXT("Message Log"); tab.pszText = textMessageLog; SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab); @@ -487,14 +463,14 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, r.left += rtab.left; // Create the pages and position them in the tab control, but hide them - pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), - MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); + pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); + SetWindowPos(pages[TAB_CONFIG], hwnd, r.left, r.top, r.right, r.bottom, SWP_HIDEWINDOW); + pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES); - SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); - SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); + SetWindowPos(pages[TAB_MESSAGES], hwnd, r.left, r.top, r.right, r.bottom, SWP_HIDEWINDOW); // Tell the editfield acting as the console to exclude the width of the scrollbar - GetClientRect(pages[TAB_MESSAGES],&r); + GetClientRect(pages[TAB_MESSAGES], &r); r.right -= GetSystemMetrics(SM_CXVSCROLL)+4; r.left = r.top = 0; SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r); @@ -513,24 +489,17 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, case WM_NOTIFY: { - LPNMHDR nmhdr = (LPNMHDR)lParam; - int32_t cur; + auto nmhdr = (LPNMHDR)lParam; if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break; - cur = (int32_t)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); + int const cur = SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); switch (nmhdr->code) { - case TCN_SELCHANGING: - { - if (cur < 0 || !pages[cur]) break; - ShowWindow(pages[cur],SW_HIDE); - return TRUE; - } - case TCN_SELCHANGE: - { - if (cur < 0 || !pages[cur]) break; - ShowWindow(pages[cur],SW_SHOW); - return TRUE; - } + case TCN_SELCHANGING: + case TCN_SELCHANGE: + if (cur < 0 || !pages[cur]) + break; + ShowWindow(pages[cur], nmhdr->code == TCN_SELCHANGING ? SW_HIDE : SW_SHOW); + return TRUE; } break; } @@ -584,10 +553,8 @@ static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, int32_t startwin_open(void) { - INITCOMMONCONTROLSEX icc; if (startupdlg) return 1; - icc.dwSize = sizeof(icc); - icc.dwICC = ICC_TAB_CLASSES; + INITCOMMONCONTROLSEX icc = { sizeof(icc), ICC_TAB_CLASSES }; InitCommonControlsEx(&icc); startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); if (startupdlg) @@ -609,43 +576,43 @@ int32_t startwin_close(void) int32_t startwin_puts(const char *buf) { - const char *p = NULL, *q = NULL; - static char workbuf[1024]; - static int32_t newline = 0; - int32_t curlen, linesbefore, linesafter; - HWND edctl; - int32_t vis; - static HWND dactrl = NULL; - if (!startupdlg) return 1; - edctl = pages[TAB_MESSAGES]; + const HWND edctl = pages[TAB_MESSAGES]; + if (!edctl) return -1; + static HWND dactrl = NULL; if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); - vis = ((int32_t)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); + int const vis = ((int)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); - if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); - curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); + if (vis) + SendMessage(edctl, WM_SETREDRAW, FALSE, 0); + + int const curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); - linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - p = buf; + + int const numlines = SendMessage(edctl, EM_GETLINECOUNT, 0, 0); + static bool newline = false; + const char *p = buf; + while (*p) { if (newline) { SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); - newline = 0; + newline = false; } - q = p; + const char *q = p; while (*q && *q != '\n') q++; + static char workbuf[1024]; Bmemcpy(workbuf, p, q-p); if (*q == '\n') { if (!q[1]) { - newline = 1; + newline = true; workbuf[q-p] = 0; } else @@ -663,9 +630,13 @@ int32_t startwin_puts(const char *buf) } SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); } - linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); - if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); + + int const newnumlines = SendMessage(edctl, EM_GETLINECOUNT, 0, 0); + SendMessage(edctl, EM_LINESCROLL, 0, newnumlines - numlines); + + if (vis) + SendMessage(edctl, WM_SETREDRAW, TRUE, 0); + return 0; } @@ -685,7 +656,6 @@ int32_t startwin_idle(void *v) int32_t startwin_run(void) { - MSG msg; if (!startupdlg) return 1; done = -1; @@ -693,24 +663,22 @@ int32_t startwin_run(void) SetPage(TAB_CONFIG); EnableConfig(1); - settings.flags = 0; - if (ud.config.ScreenMode) settings.flags |= 1; #ifdef POLYMER - if (glrendmode == REND_POLYMER) settings.flags |= 2; + settings.polymer = (glrendmode == REND_POLYMER); +#else + settings.polymer = 0; #endif - if (ud.config.NoAutoLoad) settings.flags |= 4; - settings.xdim = ud.config.ScreenWidth; - settings.ydim = ud.config.ScreenHeight; - settings.bpp = ud.config.ScreenBPP; - settings.forcesetup = ud.config.ForceSetup; - settings.usemouse = ud.config.UseMouse; - settings.usejoy = ud.config.UseJoystick; + + settings.shared = ud.setup; settings.grp = g_selectedGrp; settings.gamedir = g_modDir; + PopulateForm(-1); - while (done < 0) + do { + MSG msg; + switch (GetMessage(&msg, NULL, 0,0)) { case 0: @@ -719,35 +687,24 @@ int32_t startwin_run(void) case -1: return -1; default: - if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; + if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) + break; TranslateMessage(&msg); DispatchMessage(&msg); break; } } + while (done < 0); SetPage(TAB_MESSAGES); EnableConfig(0); + if (done) { - ud.config.ScreenMode = (settings.flags&1); -#ifdef POLYMER - if (settings.flags & 2) glrendmode = REND_POLYMER; - else glrendmode = REND_POLYMOST; -#endif - if (settings.flags & 4) ud.config.NoAutoLoad = 1; - else ud.config.NoAutoLoad = 0; - ud.config.ScreenWidth = settings.xdim; - ud.config.ScreenHeight = settings.ydim; - ud.config.ScreenBPP = settings.bpp; - ud.config.ForceSetup = settings.forcesetup; - ud.config.UseMouse = settings.usemouse; - ud.config.UseJoystick = settings.usejoy; + ud.setup = settings.shared; + glrendmode = (settings.polymer) ? REND_POLYMER : REND_POLYMOST; g_selectedGrp = settings.grp; - - if (g_noSetup == 0 && settings.gamedir != NULL) - Bstrcpy(g_modDir,settings.gamedir); - else Bsprintf(g_modDir,"/"); + Bstrcpy(g_modDir, (g_noSetup == 0 && settings.gamedir != NULL) ? settings.gamedir : "/"); } return done;