diff --git a/source/rr/src/cheats.h b/source/rr/src/cheats.h index 009be67b8..7ad9b0f44 100644 --- a/source/rr/src/cheats.h +++ b/source/rr/src/cheats.h @@ -22,6 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #pragma once +#define MAXCHEATLEN 20 +#define NUMCHEATCODES (int32_t)ARRAY_SIZE(CheatStrings) + extern void G_DoCheats(void); extern void G_SetupCheats(void); diff --git a/source/rr/src/cmdline.h b/source/rr/src/cmdline.h index 14f5896f4..cd3b18bcd 100644 --- a/source/rr/src/cmdline.h +++ b/source/rr/src/cmdline.h @@ -20,6 +20,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- +#ifndef cmdline_h__ +#define cmdline_h__ + +#include "compat.h" + extern void G_CheckCommandLine(int32_t argc, char const * const * argv); extern void G_ShowParameterHelp(void); extern void G_ShowDebugHelp(void); @@ -33,3 +38,4 @@ extern const char *CommandMap; extern const char *CommandName; extern int32_t g_forceWeaponChoice; extern int32_t g_fakeMultiMode; +#endif // cmdline_h__ diff --git a/source/rr/src/common.cpp b/source/rr/src/common.cpp index 47dcaadfb..75a333442 100644 --- a/source/rr/src/common.cpp +++ b/source/rr/src/common.cpp @@ -211,8 +211,6 @@ void G_SetupGlobalPsky(void) ////////// static char g_rootDir[BMAX_PATH]; -//char g_modDir[BMAX_PATH] = "/"; - int g_useCwd; static void G_LoadAddon(void); int32_t g_groupFileHandle; diff --git a/source/rr/src/common_game.h b/source/rr/src/common_game.h index a379b90b6..a3326737f 100644 --- a/source/rr/src/common_game.h +++ b/source/rr/src/common_game.h @@ -7,6 +7,7 @@ #ifndef EDUKE32_COMMON_GAME_H_ #define EDUKE32_COMMON_GAME_H_ +#include "collections.h" #include "grpscan.h" #ifdef __cplusplus @@ -133,8 +134,6 @@ extern void G_SetupGlobalPsky(void); ////////// -extern char g_modDir[BMAX_PATH]; -extern int kopen4loadfrommod(const char *filename, char searchfirst); extern void G_AddSearchPaths(void); extern void G_CleanupSearchPaths(void); diff --git a/source/rr/src/config.cpp b/source/rr/src/config.cpp index 7cf6c4a0a..95421a345 100644 --- a/source/rr/src/config.cpp +++ b/source/rr/src/config.cpp @@ -116,24 +116,52 @@ const char *CONFIG_AnalogNumToName(int32_t func) } -void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN]) +void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN], bool lazy/*=false*/) { - Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); + static char const s_gamefunc_[] = "gamefunc_"; + int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - CONTROL_ClearAllBinds(); + if (!lazy) + { + Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); + CONTROL_ClearAllBinds(); + } - for (size_t i=0; i < ARRAY_SIZE(gamefunctions); ++i) + for (int i=0; i < ARRAY_SSIZE(gamefunctions); ++i) { if (gamefunctions[i][0] == '\0') continue; - ud.config.KeyboardKeys[i][0] = KB_StringToScanCode(keyptr[i<<1]); - ud.config.KeyboardKeys[i][1] = KB_StringToScanCode(keyptr[(i<<1)+1]); + auto &key = ud.config.KeyboardKeys[i]; + + int const default0 = KB_StringToScanCode(keyptr[i<<1]); + int const default1 = KB_StringToScanCode(keyptr[(i<<1)+1]); + + // skip the function if the default key is already used + // or the function is assigned to another key + if (lazy && (key[0] != 0xff || (CONTROL_KeyIsBound(default0) && Bstrlen(CONTROL_KeyBinds[default0].cmdstr) > strlen_gamefunc_ + && CONFIG_FunctionNameToNum(CONTROL_KeyBinds[default0].cmdstr + strlen_gamefunc_) >= 0))) + { +#if 0 // defined(DEBUGGINGAIDS) + if (key[0] != 0xff) + initprintf("Skipping %s bound to %s\n", keyptr[i<<1], CONTROL_KeyBinds[default0].cmdstr); +#endif + continue; + } + + key[0] = default0; + key[1] = default1; + + if (key[0]) + CONTROL_FreeKeyBind(key[0]); + + if (key[1]) + CONTROL_FreeKeyBind(key[1]); if (i == gamefunc_Show_Console) - OSD_CaptureKey(ud.config.KeyboardKeys[i][0]); + OSD_CaptureKey(key[0]); else - CONFIG_MapKey(i, ud.config.KeyboardKeys[i][0], 0, ud.config.KeyboardKeys[i][1], 0); + CONFIG_MapKey(i, key[0], 0, key[1], 0); } } @@ -154,8 +182,8 @@ void CONFIG_SetDefaults(void) droidinput.toggleCrouch = 1; droidinput.quickSelectWeapon = 1; - 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); @@ -167,27 +195,23 @@ 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 - ud.config.ScreenMode = 1; - #ifdef USE_OPENGL - ud.config.ScreenBPP = 32; + ud.setup.bpp = 32; #else - ud.config.ScreenBPP = 8; + ud.setup.bpp = 8; #endif ud.config.useprecache = 1; - ud.config.ForceSetup = 1; - ud.config.NoAutoLoad = 1; ud.config.AmbienceToggle = 1; ud.config.AutoAim = 1; ud.config.FXVolume = 255; @@ -261,11 +285,16 @@ void CONFIG_SetDefaults(void) ud.weaponswitch = 3; // new+empty ud.angleinterpolation = 0; #ifdef GEKKO - ud.config.UseJoystick = 1; + ud.setup.usejoystick = 1; #else - ud.config.UseJoystick = 0; + ud.setup.usejoystick = 0; #endif - ud.config.UseMouse = 1; + + ud.setup.forcesetup = 1; + ud.setup.noautoload = 1; + ud.setup.fullscreen = 1; + ud.setup.usemouse = 1; + ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM ud.display_bonus_screen = 1; ud.show_level_text = 1; @@ -284,6 +313,7 @@ void CONFIG_SetDefaults(void) ud.autosave = 1; ud.autosavedeletion = 1; ud.maxautosaves = 5; + ud.fov = 90; ud.config.CheckForUpdates = 1; @@ -395,47 +425,48 @@ void CONFIG_SetDefaults(void) // wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup -void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2) +void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2) { - int32_t i, j, k; - int32_t ii[] = { key1, key2, oldkey1, oldkey2 }; + int const keys[] = { key1, key2, oldkey1, oldkey2 }; char buf[2*MAXGAMEFUNCLEN]; - UNREFERENCED_PARAMETER(which); -// CONTROL_MapKey(which, key1, key2); - if (which == gamefunc_Show_Console) OSD_CaptureKey(key1); - for (k = 0; (unsigned)k < ARRAY_SIZE(ii); k++) + for (int k = 0; (unsigned)k < ARRAY_SIZE(keys); k++) { - if (ii[k] == 0xff || !ii[k]) + if (keys[k] == 0xff || !keys[k]) continue; - for (j=0; ConsoleKeys[j].name; j++) - if (ii[k] == ConsoleKeys[j].id) + int match = 0; + + for (; sctokeylut[match].key; match++) + { + if (keys[k] == sctokeylut[match].sc) break; + } tempbuf[0] = 0; - for (i=NUMGAMEFUNCTIONS-1; i>=0; i--) + for (int i=NUMGAMEFUNCTIONS-1; i>=0; i--) { - if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k]) + if (ud.config.KeyboardKeys[i][0] == keys[k] || ud.config.KeyboardKeys[i][1] == keys[k]) { - Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i)); + Bsprintf(buf, "gamefunc_%s; ", CONFIG_FunctionNumToName(i)); Bstrcat(tempbuf,buf); } } - i = Bstrlen(tempbuf); - if (i >= 2) + int const len = Bstrlen(tempbuf); + + if (len >= 2) { - tempbuf[i-2] = 0; // cut off the trailing "; " - CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : ""); + tempbuf[len-2] = 0; // cut off the trailing "; " + CONTROL_BindKey(keys[k], tempbuf, 1, sctokeylut[match].key ? sctokeylut[match].key : ""); } else { - CONTROL_FreeKeyBind(ii[k]); + CONTROL_FreeKeyBind(keys[k]); } } } @@ -638,8 +669,8 @@ int32_t 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); SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "CacheSize", &dummy); if (dummy > MAXCACHE1DSIZE) @@ -669,10 +700,10 @@ int32_t CONFIG_ReadSetup(void) SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout); SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]); - - 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", "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", "WindowPositioning", (int32_t *)&windowpos); @@ -682,14 +713,14 @@ int32_t CONFIG_ReadSetup(void) SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP); - - if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32; + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.setup.bpp); + + if (ud.setup.bpp < 8) ud.setup.bpp = 32; #ifdef POLYMER - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy); - if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER; - else glrendmode = REND_POLYMOST; + int32_t rendmode = 0; + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &rendmode); + glrendmode = (rendmode > 0) ? REND_POLYMER : REND_POLYMOST; #endif SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions); @@ -763,18 +794,18 @@ void CONFIG_WriteSetup(uint32_t flags) SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",ud.executions,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); SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "CacheSize", MAXCACHE1DSIZE, FALSE, FALSE); #ifdef POLYMER SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer",glrendmode == REND_POLYMER,FALSE,FALSE); #endif - - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,FALSE,FALSE); // JBF 20040523 - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,FALSE,FALSE); // JBF 20031206 - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,FALSE,FALSE); // JBF 20031206 - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,FALSE,FALSE); // JBF 20031206 + + 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); @@ -804,7 +835,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 (dummy=0; dummy 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 @@ -1013,13 +1014,14 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) #endif ))); + viewingRange = Blrintf(float(vr) * tanf(ud.fov * (PI/360.f))); + if (!RRRA || !pPlayer->drug_mode) { if (!r_usenewaspect) - renderSetAspect(vr, yxaspect); + renderSetAspect(viewingRange, yxaspect); else { - viewingRange = vr; yxAspect = tabledivide32_noinline(65536 * ydim * 8, xdim * 5); renderSetAspect(mulscale16(viewingRange,viewingrange), yxaspect); @@ -1141,10 +1143,10 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) if (pPlayer->drug_stat[0] == 0) { pPlayer->drug_stat[1]++; - aspect = vr + pPlayer->drug_stat[1] * 5000; - if (vr * 3 < aspect) + aspect = viewingRange + pPlayer->drug_stat[1] * 5000; + if (viewingRange * 3 < aspect) { - pPlayer->drug_aspect = vr * 3; + pPlayer->drug_aspect = viewingRange * 3; pPlayer->drug_stat[0] = 2; } else @@ -1156,14 +1158,14 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) else if (pPlayer->drug_stat[0] == 3) { pPlayer->drug_stat[1]--; - aspect = vr + pPlayer->drug_stat[1] * 5000; - if (aspect < vr) + aspect = viewingRange + pPlayer->drug_stat[1] * 5000; + if (aspect < viewingRange) { pPlayer->drug_mode = 0; pPlayer->drug_stat[0] = 0; pPlayer->drug_stat[2] = 0; pPlayer->drug_stat[1] = 0; - pPlayer->drug_aspect = vr; + pPlayer->drug_aspect = viewingRange; } else { @@ -1180,7 +1182,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) else { pPlayer->drug_stat[2]++; - aspect = pPlayer->drug_stat[2] * 500 + vr * 3; + aspect = pPlayer->drug_stat[2] * 500 + viewingRange * 3; pPlayer->drug_aspect = aspect; P_UpdateScreenPal(pPlayer); } @@ -1197,7 +1199,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) else { pPlayer->drug_stat[2]--; - aspect = pPlayer->drug_stat[2] * 500 + vr * 3; + aspect = pPlayer->drug_stat[2] * 500 + viewingRange * 3; pPlayer->drug_aspect = aspect; P_UpdateScreenPal(pPlayer); } @@ -6813,7 +6815,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); } } @@ -7526,10 +7528,10 @@ static void G_Startup(void) if (g_modDir[0] != '/' && (cwd = getcwd(NULL, 0))) { Bchdir(g_modDir); - if (artLoadFiles("tiles%03d.art",MAXCACHE1DSIZE) < 0) + if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) { Bchdir(cwd); - if (artLoadFiles("tiles%03d.art",MAXCACHE1DSIZE) < 0) + if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) G_GameExit("Failed loading art."); } Bchdir(cwd); @@ -7538,7 +7540,7 @@ static void G_Startup(void) #endif } - else if (artLoadFiles("tiles%03d.art",MAXCACHE1DSIZE) < 0) + else if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) G_GameExit("Failed loading art."); } @@ -7872,7 +7874,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()) { @@ -7883,7 +7885,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) @@ -8045,8 +8047,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,g_player[myconnectindex].ps->palette,0); - + g_frameDelay = calcFrameDelay(r_maxfps + r_maxfpsoffset); + videoSetPalette(ud.brightness>>2, g_player[myconnectindex].ps->palette, 0); S_MusicStartup(); S_SoundStartup(); } @@ -8284,7 +8291,7 @@ MAIN_LOOP_RESTART: OSD_DispatchQueued(); char gameUpdate = false; - uint32_t gameUpdateStartTime = timerGetTicks(); + double const gameUpdateStartTime = timerGetHiTicks(); if (((g_netClient || g_netServer) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME) { if (g_networkMode != NET_DEDICATED_SERVER) @@ -8336,7 +8343,7 @@ MAIN_LOOP_RESTART: while (((g_netClient || g_netServer) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME); gameUpdate = true; - g_gameUpdateTime = timerGetTicks()-gameUpdateStartTime; + g_gameUpdateTime = timerGetHiTicks()-gameUpdateStartTime; if (g_gameUpdateAvgTime < 0.f) g_gameUpdateAvgTime = g_gameUpdateTime; g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES-1.f)*g_gameUpdateAvgTime+g_gameUpdateTime)/((float) GAMEUPDATEAVGTIMENUMSAMPLES); @@ -8374,7 +8381,7 @@ MAIN_LOOP_RESTART: if (gameUpdate) { - g_gameUpdateAndDrawTime = timerGetTicks()-gameUpdateStartTime; + g_gameUpdateAndDrawTime = timerGetHiTicks()-gameUpdateStartTime; } } diff --git a/source/rr/src/game.h b/source/rr/src/game.h index e369bcba6..143664887 100644 --- a/source/rr/src/game.h +++ b/source/rr/src/game.h @@ -30,6 +30,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #endif #include "fix16.h" +#include "gamedefs.h" +#include "gamedef.h" +#include "net.h" #ifdef __cplusplus extern "C" { @@ -136,6 +139,18 @@ void A_DeleteSprite(int spriteNum); #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 { vec3_t camerapos; int32_t const_visibility,uw_framerate; @@ -163,7 +178,7 @@ typedef struct { int32_t playerbest; - int32_t configversion, bgstretch; + int32_t configversion, bgstretch, frameperiod; int32_t default_volume, default_skill; @@ -174,6 +189,8 @@ typedef struct { uint32_t userbytever; + int32_t fov; + fix16_t cameraq16ang, cameraq16horiz; int16_t camerasect; int16_t pause_on,from_bonus; @@ -183,8 +200,6 @@ typedef struct { int8_t menutitle_pal, slidebar_palselected, slidebar_paldisabled; struct { - int32_t UseJoystick; - int32_t UseMouse; int32_t AutoAim; int32_t ShowOpponentWeapons; int32_t MouseDeadZone,MouseBias; @@ -221,18 +236,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; @@ -242,6 +245,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; @@ -290,7 +295,6 @@ extern int32_t g_cameraClock; extern int32_t g_cameraDistance; extern int32_t g_crosshairSum; extern int32_t g_doQuickSave; -extern int32_t g_forceWeaponChoice; extern int32_t g_fakeMultiMode; extern int32_t g_levelTextTime; extern int32_t g_quitDeadline; @@ -298,6 +302,7 @@ extern int32_t g_restorePalette; extern int32_t hud_glowingquotes; extern int32_t hud_showmapname; extern int32_t r_maxfps; +extern int32_t r_maxfpsoffset; extern int32_t tempwallptr; extern int32_t ticrandomseed; extern int32_t vote_map; @@ -311,7 +316,8 @@ extern int32_t MAXCACHE1DSIZE; extern palette_t CrosshairColors; extern palette_t DefaultCrosshairColors; -extern uint64_t g_frameDelay; +extern double g_frameDelay; +static inline double calcFrameDelay(int maxFPS) { return maxFPS ? ((double)timerGetFreqU64() / (double)(maxFPS)) : 0.0; } int32_t A_CheckInventorySprite(spritetype *s); int32_t A_InsertSprite(int16_t whatsect, int32_t s_x, int32_t s_y, int32_t s_z, int16_t s_pn, int8_t s_s, uint8_t s_xr, diff --git a/source/rr/src/gamedef.h b/source/rr/src/gamedef.h index 93c179aa8..045a81278 100644 --- a/source/rr/src/gamedef.h +++ b/source/rr/src/gamedef.h @@ -23,7 +23,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef gamedef_h_ #define gamedef_h_ +#include "actors.h" #include "build.h" // hashtable_t +#include "cheats.h" #include "common.h" // tokenlist #include "player.h" // projectile_t @@ -46,9 +48,6 @@ enum #define LABEL_HASPARM2 1 #define LABEL_ISSTRING 2 -#define MAXCHEATLEN 20 -#define NUMCHEATCODES (int32_t)ARRAY_SIZE(CheatStrings) - #define VM_INSTMASK 0xfff #define C_CUSTOMERROR(Text, ...) \ diff --git a/source/rr/src/global.h b/source/rr/src/global.h index 614dd866e..0ebd60426 100644 --- a/source/rr/src/global.h +++ b/source/rr/src/global.h @@ -23,6 +23,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef global_h_ #define global_h_ +#include "build.h" +#include "compat.h" +#include "duke3d.h" +#include "mmulti.h" +#include "quotes.h" +#include "sector.h" +#include "sounds.h" + #define MAXMINECARTS 16 #define MAXJAILDOORS 32 #define MAXLIGHTNINSECTORS 64 @@ -41,9 +49,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // duke3d global soup :( -// XXX: we don't #include everything we need. -#include "compat.h" -#include "build.h" G_EXTERN int32_t g_interpolationCnt; G_EXTERN int32_t g_interpolationLock; @@ -51,11 +56,6 @@ G_EXTERN int32_t oldipos[MAXINTERPOLATIONS]; G_EXTERN int32_t *curipos[MAXINTERPOLATIONS]; G_EXTERN int32_t bakipos[MAXINTERPOLATIONS]; -#include "mmulti.h" - -#include "duke3d.h" -#include "sector.h" -#include "quotes.h" #ifdef __cplusplus extern "C" { @@ -230,8 +230,8 @@ G_EXTERN int32_t g_screenCapture; G_EXTERN sound_t g_sounds[MAXSOUNDS]; G_EXTERN uint32_t everyothertime; G_EXTERN uint32_t g_moveThingsCount; -G_EXTERN uint32_t g_gameUpdateTime; -G_EXTERN uint32_t g_gameUpdateAndDrawTime; +G_EXTERN double g_gameUpdateTime; +G_EXTERN double g_gameUpdateAndDrawTime; #define GAMEUPDATEAVGTIMENUMSAMPLES 100 extern float g_gameUpdateAvgTime; diff --git a/source/rr/src/macros.h b/source/rr/src/macros.h index f37e55b55..9a8eadf2c 100644 --- a/source/rr/src/macros.h +++ b/source/rr/src/macros.h @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef EDUKE32_MACROS_H_ #define EDUKE32_MACROS_H_ +#include "mmulti.h" + // Macros, some from SW source static FORCE_INLINE int32_t krand2(void) diff --git a/source/rr/src/menus.cpp b/source/rr/src/menus.cpp index 5dd4be32c..71c5e69ba 100644 --- a/source/rr/src/menus.cpp +++ b/source/rr/src/menus.cpp @@ -380,7 +380,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 @@ -519,12 +519,14 @@ static MenuOptionSet_t MEOS_VIDEOSETUP_VSYNC = MAKE_MENUOPTIONSET(MEOSN_VIDEOSET static MenuOption_t MEO_VIDEOSETUP_VSYNC = MAKE_MENUOPTION(&MF_Redfont, &MEOS_VIDEOSETUP_VSYNC, &newvsync); static MenuEntry_t ME_VIDEOSETUP_VSYNC = MAKE_MENUENTRY("VSync:", &MF_Redfont, &MEF_BigOptionsRt, &MEO_VIDEOSETUP_VSYNC, Option); -static char const *MEOSN_VIDEOSETUP_FRAMELIMIT [] = { "None", "30 fps", "60 fps", "120 fps", }; -static int32_t MEOSV_VIDEOSETUP_FRAMELIMIT [] = { 0, 30, 60, 120 }; -static MenuOptionSet_t MEOS_VIDEOSETUP_FRAMELIMIT = MAKE_MENUOPTIONSET(MEOSN_VIDEOSETUP_FRAMELIMIT, MEOSV_VIDEOSETUP_FRAMELIMIT, 0x2); +static char const *MEOSN_VIDEOSETUP_FRAMELIMIT [] = { "30 fps", "60 fps", "75 fps", "100 fps", "120 fps", "144 fps", "165 fps", "240 fps" }; +static int32_t MEOSV_VIDEOSETUP_FRAMELIMIT [] = { 30, 60, 75, 100, 120, 144, 165, 240 }; +static MenuOptionSet_t MEOS_VIDEOSETUP_FRAMELIMIT = MAKE_MENUOPTIONSET(MEOSN_VIDEOSETUP_FRAMELIMIT, MEOSV_VIDEOSETUP_FRAMELIMIT, 0x0); static MenuOption_t MEO_VIDEOSETUP_FRAMELIMIT= MAKE_MENUOPTION(&MF_Redfont, &MEOS_VIDEOSETUP_FRAMELIMIT, &r_maxfps); static MenuEntry_t ME_VIDEOSETUP_FRAMELIMIT = MAKE_MENUENTRY("Framerate limit:", &MF_Redfont, &MEF_BigOptionsRt, &MEO_VIDEOSETUP_FRAMELIMIT, Option); +static MenuRangeInt32_t MEO_VIDEOSETUP_FRAMELIMITOFFSET = MAKE_MENURANGE( &r_maxfpsoffset, &MF_Redfont, -10, 10, 0, 21, 1 ); +static MenuEntry_t ME_VIDEOSETUP_FRAMELIMITOFFSET = MAKE_MENUENTRY( "FPS offset:", &MF_Redfont, &MEF_BigOptionsRt, &MEO_VIDEOSETUP_FRAMELIMITOFFSET, RangeInt32 ); static MenuEntry_t ME_VIDEOSETUP_APPLY = MAKE_MENUENTRY( "Apply Changes", &MF_Redfont, &MEF_BigOptions_Apply, &MEO_NULL, Link ); @@ -546,6 +548,10 @@ static MenuEntry_t ME_DISPLAYSETUP_ASPECTRATIO = MAKE_MENUENTRY( "Widescreen:", #endif +static MenuRangeInt32_t MEO_DISPLAYSETUP_FOV = MAKE_MENURANGE( &ud.fov, &MF_Redfont, 75, 120, 0, 10, 0 ); +static MenuEntry_t ME_DISPLAYSETUP_FOV = MAKE_MENUENTRY( "FOV:", &MF_Redfont, &MEF_BigOptionsRt, &MEO_DISPLAYSETUP_FOV, RangeInt32 ); + + #ifdef USE_OPENGL //POGOTODO: allow filtering again in standalone once indexed colour textures support filtering @@ -709,6 +715,7 @@ static MenuEntry_t *MEL_DISPLAYSETUP[] = { #ifndef EDUKE32_ANDROID_MENU &ME_DISPLAYSETUP_VIDEOSETUP, &ME_DISPLAYSETUP_ASPECTRATIO, + &ME_DISPLAYSETUP_FOV, #endif &ME_DISPLAYSETUP_UPSCALING, }; @@ -720,6 +727,7 @@ static MenuEntry_t *MEL_DISPLAYSETUP_GL[] = { #ifndef EDUKE32_ANDROID_MENU &ME_DISPLAYSETUP_VIDEOSETUP, &ME_DISPLAYSETUP_ASPECTRATIO, + &ME_DISPLAYSETUP_FOV, #endif &ME_DISPLAYSETUP_TEXFILTER, #ifdef EDUKE32_ANDROID_MENU @@ -741,6 +749,7 @@ static MenuEntry_t *MEL_DISPLAYSETUP_GL_POLYMER[] = { &ME_DISPLAYSETUP_COLORCORR, #ifndef EDUKE32_ANDROID_MENU &ME_DISPLAYSETUP_VIDEOSETUP, + &ME_DISPLAYSETUP_FOV, #endif &ME_DISPLAYSETUP_TEXFILTER, &ME_DISPLAYSETUP_ANISOTROPY, @@ -2030,6 +2039,8 @@ static void Menu_Pre(MenuID_t cm) && vsync == newvsync ) || (newrendermode != REND_CLASSIC && resolution[nr].bppmax <= 8)); + + MenuEntry_DisableOnCondition(&ME_VIDEOSETUP_FRAMELIMITOFFSET, !r_maxfps); break; } @@ -2079,7 +2090,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: @@ -3601,10 +3612,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) { @@ -3766,9 +3777,7 @@ static int32_t Menu_EntryOptionModify(MenuEntry_t *entry, int32_t newOption) } } else if (entry == &ME_VIDEOSETUP_FRAMELIMIT) - { - g_frameDelay = newOption ? (timerGetFreqU64()/newOption) : 0; - } + g_frameDelay = calcFrameDelay(newOption + r_maxfpsoffset); switch (g_currentMenu) { @@ -3831,7 +3840,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 @@ -3866,6 +3875,8 @@ static int32_t Menu_EntryRangeInt32Modify(MenuEntry_t *entry, int32_t newValue) joySetDeadZone(M_JOYSTICKAXES.currentEntry, newValue, *MEO_JOYSTICKAXIS_SATU.variable); else if (entry == &ME_JOYSTICKAXIS_SATU) joySetDeadZone(M_JOYSTICKAXES.currentEntry, *MEO_JOYSTICKAXIS_DEAD.variable, newValue); + else if (entry == &ME_VIDEOSETUP_FRAMELIMITOFFSET) + g_frameDelay = calcFrameDelay(r_maxfps + newValue); return 0; } diff --git a/source/rr/src/osdcmds.cpp b/source/rr/src/osdcmds.cpp index e680ef098..2d0d24c1d 100644 --- a/source/rr/src/osdcmds.cpp +++ b/source/rr/src/osdcmds.cpp @@ -20,14 +20,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- -#include "duke3d.h" -#include "osdcmds.h" -#include "menus.h" -#include "osdfuncs.h" -#include "demo.h" // g_firstDemoFile[] #include "cheats.h" -#include "sbar.h" +#include "cmdline.h" +#include "demo.h" // g_firstDemoFile[] +#include "duke3d.h" +#include "menus.h" +#include "osdcmds.h" +#include "osdfuncs.h" #include "savegame.h" +#include "sbar.h" + +#ifdef LUNATIC +# include "lunatic_game.h" +#endif #ifdef EDUKE32_TOUCH_DEVICES #include "in_android.h" @@ -38,7 +43,7 @@ float r_ambientlight = 1.0, r_ambientlightrecip = 1.0; uint32_t cl_cheatmask; -static inline int32_t osdcmd_quit(osdfuncparm_t const * const UNUSED(parm)) +static inline int osdcmd_quit(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); OSD_ShowDisplay(0); @@ -46,7 +51,7 @@ static inline int32_t osdcmd_quit(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_changelevel(osdfuncparm_t const * const parm) +static int osdcmd_changelevel(osdcmdptr_t parm) { int32_t volume=0,level; char *p; @@ -155,7 +160,7 @@ static int32_t osdcmd_changelevel(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_map(osdfuncparm_t const * const parm) +static int osdcmd_map(osdcmdptr_t parm) { int32_t i; char filename[BMAX_PATH]; @@ -274,7 +279,12 @@ static int32_t osdcmd_map(osdfuncparm_t const * const parm) ud.multimode = 1; - G_NewGame_EnterLevel(); + if (g_player[myconnectindex].ps->gm & MODE_GAME) + { + G_NewGame(ud.m_volume_number, ud.m_level_number, ud.m_player_skill); + g_player[myconnectindex].ps->gm = MODE_RESTART; + } + else G_NewGame_EnterLevel(); return OSDCMD_OK; } @@ -296,7 +306,7 @@ static int32_t osdcmd_map(osdfuncparm_t const * const parm) // the variance of the run times MUST be taken into account (that is, the // replaying must be performed multiple times for the old and new versions, // etc.) -static int32_t osdcmd_demo(osdfuncparm_t const * const parm) +static int osdcmd_demo(osdcmdptr_t parm) { if (numplayers > 1) { @@ -323,7 +333,7 @@ static int32_t osdcmd_demo(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_activatecheat(osdfuncparm_t const * const parm) +static int osdcmd_activatecheat(osdcmdptr_t parm) { if (parm->numparms != 1) return OSDCMD_SHOWHELP; @@ -336,7 +346,7 @@ static int32_t osdcmd_activatecheat(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_god(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_god(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); if (numplayers == 1 && g_player[myconnectindex].ps->gm & MODE_GAME) @@ -347,7 +357,7 @@ static int32_t osdcmd_god(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_noclip(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_noclip(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); @@ -363,7 +373,7 @@ static int32_t osdcmd_noclip(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_restartsound(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_restartsound(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); S_SoundShutdown(); @@ -381,7 +391,7 @@ static int32_t osdcmd_restartsound(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_music(osdfuncparm_t const * const parm) +static int osdcmd_music(osdcmdptr_t parm) { if (parm->numparms == 1) { @@ -411,19 +421,19 @@ static int32_t osdcmd_music(osdfuncparm_t const * const parm) return OSDCMD_SHOWHELP; } -int32_t osdcmd_restartvid(osdfuncparm_t const * const UNUSED(parm)) +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; } -int32_t osdcmd_restartmap(osdfuncparm_t const * const UNUSED(parm)) +int osdcmd_restartmap(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); @@ -433,10 +443,10 @@ int32_t osdcmd_restartmap(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_vidmode(osdfuncparm_t const * const 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; @@ -469,19 +479,19 @@ static int32_t osdcmd_vidmode(osdfuncparm_t const * const 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; } -static int32_t osdcmd_spawn(osdfuncparm_t const * const parm) +static int osdcmd_spawn(osdcmdptr_t parm) { int32_t picnum = 0; uint16_t cstat=0; @@ -575,40 +585,41 @@ static int32_t osdcmd_spawn(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_addpath(osdfuncparm_t const * const parm) +static int osdcmd_addpath(osdcmdptr_t parm) { - char pathname[BMAX_PATH]; + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; + addsearchpath(parm->parms[0]); - strcpy(pathname,parm->parms[0]); - addsearchpath(pathname); return OSDCMD_OK; } -static int32_t osdcmd_initgroupfile(osdfuncparm_t const * const parm) +static int osdcmd_initgroupfile(osdcmdptr_t parm) { - char file[BMAX_PATH]; + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; + initgroupfile(parm->parms[0]); - strcpy(file,parm->parms[0]); - initgroupfile(file); return OSDCMD_OK; } -static int32_t osdcmd_cmenu(osdfuncparm_t const * const parm) +static int osdcmd_cmenu(osdcmdptr_t parm) { - if (parm->numparms != 1) return OSDCMD_SHOWHELP; + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; + if (numplayers > 1) { - OSD_Printf("cmenu: disallowed in multiplayer\n"); + OSD_Printf("Command not allowed in multiplayer\n"); return OSDCMD_OK; } - else - { + + if ((g_player[myconnectindex].ps->gm & MODE_MENU) != MODE_MENU) + Menu_Open(myconnectindex); + Menu_Change(Batol(parm->parms[0])); - } return OSDCMD_OK; } @@ -616,18 +627,18 @@ static int32_t osdcmd_cmenu(osdfuncparm_t const * const parm) -static int32_t osdcmd_crosshaircolor(osdfuncparm_t const * const parm) +static int osdcmd_crosshaircolor(osdcmdptr_t parm) { - int32_t r, g, b; - if (parm->numparms != 3) { OSD_Printf("crosshaircolor: r:%d g:%d b:%d\n",CrosshairColors.r,CrosshairColors.g,CrosshairColors.b); return OSDCMD_SHOWHELP; } - r = Batol(parm->parms[0]); - g = Batol(parm->parms[1]); - b = Batol(parm->parms[2]); + + uint8_t const r = Batol(parm->parms[0]); + uint8_t const g = Batol(parm->parms[1]); + uint8_t const b = Batol(parm->parms[2]); + G_SetCrosshairColor(r,g,b); if (!OSD_ParsingScript()) @@ -636,7 +647,7 @@ static int32_t osdcmd_crosshaircolor(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_give(osdfuncparm_t const * const parm) +static int osdcmd_give(osdcmdptr_t parm) { int32_t i; @@ -722,7 +733,7 @@ void onvideomodechange(int32_t newmode) } #if !defined NETCODE_DISABLE -static int32_t osdcmd_name(osdfuncparm_t const * const parm) +static int osdcmd_name(osdcmdptr_t parm) { char namebuf[32]; @@ -748,152 +759,43 @@ static int32_t osdcmd_name(osdfuncparm_t const * const parm) } #endif -static int32_t osdcmd_button(osdfuncparm_t const * const parm) +static int osdcmd_button(osdcmdptr_t parm) { - static char const s_gamefunc_[] = "gamefunc_"; - int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; + static char const s_gamefunc_[] = "gamefunc_"; + int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - char const* p = parm->name + strlen_gamefunc_; + char const *p = parm->name + strlen_gamefunc_; - // if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game - CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME +// if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game + CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME return OSDCMD_OK; } -const keydef_t ConsoleKeys[]= -{ - { "Escape", 0x1 }, - { "1", 0x2 }, - { "2", 0x3 }, - { "3", 0x4 }, - { "4", 0x5 }, - { "5", 0x6 }, - { "6", 0x7 }, - { "7", 0x8 }, - { "8", 0x9 }, - { "9", 0xa }, - { "0", 0xb }, - { "-", 0xc }, - { "=", 0xd }, - { "BakSpc", 0xe }, - { "Tab", 0xf }, - { "Q", 0x10 }, - { "W", 0x11 }, - { "E", 0x12 }, - { "R", 0x13 }, - { "T", 0x14 }, - { "Y", 0x15 }, - { "U", 0x16 }, - { "I", 0x17 }, - { "O", 0x18 }, - { "P", 0x19 }, - { "[", 0x1a }, - { "]", 0x1b }, - { "Enter", 0x1c }, - { "LCtrl", 0x1d }, - { "A", 0x1e }, - { "S", 0x1f }, - { "D", 0x20 }, - { "F", 0x21 }, - { "G", 0x22 }, - { "H", 0x23 }, - { "J", 0x24 }, - { "K", 0x25 }, - { "L", 0x26 }, - { "SemiColon", 0x27 }, - { "'", 0x28 }, - { "Tilde", 0x29 }, - { "LShift", 0x2a }, - { "Backslash", 0x2b }, - { "Z", 0x2c }, - { "X", 0x2d }, - { "C", 0x2e }, - { "V", 0x2f }, - { "B", 0x30 }, - { "N", 0x31 }, - { "M", 0x32 }, - { ",", 0x33 }, - { ".", 0x34 }, - { "/", 0x35 }, - { "RShift", 0x36 }, - { "Kpad*", 0x37 }, - { "LAlt", 0x38 }, - { "Space", 0x39 }, - { "CapLck", 0x3a }, - { "F1", 0x3b }, - { "F2", 0x3c }, - { "F3", 0x3d }, - { "F4", 0x3e }, - { "F5", 0x3f }, - { "F6", 0x40 }, - { "F7", 0x41 }, - { "F8", 0x42 }, - { "F9", 0x43 }, - { "F10", 0x44 }, - { "NumLck", 0x45 }, - { "ScrLck", 0x46 }, - { "Kpad7", 0x47 }, - { "Kpad8", 0x48 }, - { "Kpad9", 0x49 }, - { "Kpad-", 0x4a }, - { "Kpad4", 0x4b }, - { "Kpad5", 0x4c }, - { "Kpad6", 0x4d }, - { "Kpad+", 0x4e }, - { "Kpad1", 0x4f }, - { "Kpad2", 0x50 }, - { "Kpad3", 0x51 }, - { "Kpad0", 0x52 }, - { "Kpad.", 0x53 }, - { "F11", 0x57 }, - { "F12", 0x58 }, - { "KpdEnt", 0x9c }, - { "RCtrl", 0x9d }, - { "Kpad/", 0xb5 }, - { "RAlt", 0xb8 }, - { "PrtScn", 0xb7 }, - { "Pause", 0xc5 }, - { "Home", 0xc7 }, - { "Up", 0xc8 }, - { "PgUp", 0xc9 }, - { "Left", 0xcb }, - { "Right", 0xcd }, - { "End", 0xcf }, - { "Down", 0xd0 }, - { "PgDn", 0xd1 }, - { "Insert", 0xd2 }, - { "Delete", 0xd3 }, - - {0,0} -}; - const char *const ConsoleButtons[] = { "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup", "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8" }; -static int32_t osdcmd_bind(osdfuncparm_t const * const parm) +static int osdcmd_bind(osdcmdptr_t parm) { - int32_t i, j, repeat; - if (parm->numparms==1 && !Bstrcasecmp(parm->parms[0],"showkeys")) { - for (i=0; ConsoleKeys[i].name; i++) - OSD_Printf("%s\n",ConsoleKeys[i].name); - for (i=0; inumparms==0) { - int32_t j=0; + int j=0; OSD_Printf("Current key bindings:\n"); - for (i=0; iparms[0],ConsoleKeys[i].name)) - break; + int i, j, repeat; - if (!ConsoleKeys[i].name) + for (i=0; i < ARRAY_SSIZE(sctokeylut); i++) + { + if (!Bstrcasecmp(parm->parms[0], sctokeylut[i].key)) + break; + } + + // didn't find the key + if (i == ARRAY_SSIZE(sctokeylut)) { for (i=0; iparms[0],ConsoleButtons[i])) break; + if (i >= MAXMOUSEBUTTONS) return OSDCMD_SHOWHELP; @@ -953,10 +861,10 @@ static int32_t osdcmd_bind(osdfuncparm_t const * const parm) if (parm->numparms < 2) { - if (CONTROL_KeyIsBound(ConsoleKeys[i].id)) - OSD_Printf("%-9s %s\"%s\"\n", ConsoleKeys[i].name, CONTROL_KeyBinds[ConsoleKeys[i].id].repeat?"":"norepeat ", - CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr); - else OSD_Printf("%s is unbound\n", ConsoleKeys[i].name); + if (CONTROL_KeyIsBound(sctokeylut[i].sc)) + OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat?"":"norepeat ", + CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr); + else OSD_Printf("%s is unbound\n", sctokeylut[i].key); return OSDCMD_OK; } @@ -977,20 +885,21 @@ static int32_t osdcmd_bind(osdfuncparm_t const * const parm) Bstrcat(tempbuf,parm->parms[j++]); } - CONTROL_BindKey(ConsoleKeys[i].id, tempbuf, repeat, ConsoleKeys[i].name); + CONTROL_BindKey(sctokeylut[i].sc, tempbuf, repeat, sctokeylut[i].key); - { char *cp = tempbuf; // Populate the keyboard config menu based on the bind. // Take care of processing one-to-many bindings properly, too. - while ((cp = Bstrstr(cp, "gamefunc_"))) + static char const s_gamefunc_[] = "gamefunc_"; + int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; + + while ((cp = Bstrstr(cp, s_gamefunc_))) { - char *semi; + cp += strlen_gamefunc_; - cp += 9; // skip the "gamefunc_" + char *semi = Bstrchr(cp, ';'); - semi = Bstrchr(cp, ';'); if (semi) *semi = 0; @@ -1002,14 +911,13 @@ static int32_t osdcmd_bind(osdfuncparm_t const * const parm) if (j != -1) { ud.config.KeyboardKeys[j][1] = ud.config.KeyboardKeys[j][0]; - ud.config.KeyboardKeys[j][0] = ConsoleKeys[i].id; -// CONTROL_MapKey(j, ConsoleKeys[i].id, ud.config.KeyboardKeys[j][0]); + ud.config.KeyboardKeys[j][0] = sctokeylut[i].sc; +// CONTROL_MapKey(j, sctokeylut[i].sc, ud.config.KeyboardKeys[j][0]); if (j == gamefunc_Show_Console) - OSD_CaptureKey(ConsoleKeys[i].id); + OSD_CaptureKey(sctokeylut[i].sc); } } - } if (!OSD_ParsingScript()) OSD_Printf("%s\n",parm->raw); @@ -1017,23 +925,18 @@ static int32_t osdcmd_bind(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_unbindall(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_unbindall(osdcmdptr_t UNUSED(parm)) { - int32_t i; - UNREFERENCED_CONST_PARAMETER(parm); - for (i=0; inumparms != 1) + return OSDCMD_SHOWHELP; - if (parm->numparms < 1) return OSDCMD_SHOWHELP; - - for (i=0; ConsoleKeys[i].name; i++) - if (!Bstrcasecmp(parm->parms[0],ConsoleKeys[i].name)) - break; - - if (!ConsoleKeys[i].name) + for (auto ConsoleKey : sctokeylut) { - for (i=0; iparms[0],ConsoleButtons[i])) - break; - - if (i >= MAXMOUSEBUTTONS) - return OSDCMD_SHOWHELP; - - CONTROL_FreeMouseBind(i); - - OSD_Printf("unbound %s\n",ConsoleButtons[i]); - - return OSDCMD_OK; + if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key)) + { + CONTROL_FreeKeyBind(ConsoleKey.sc); + OSD_Printf("unbound key %s\n", ConsoleKey.key); + return OSDCMD_OK; + } } - CONTROL_FreeKeyBind(ConsoleKeys[i].id); + for (int i = 0; i < MAXMOUSEBUTTONS; i++) + { + if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) + { + CONTROL_FreeMouseBind(i); + OSD_Printf("unbound %s\n", ConsoleButtons[i]); + return OSDCMD_OK; + } + } - OSD_Printf("unbound key %s\n",ConsoleKeys[i].name); - - return OSDCMD_OK; + return OSDCMD_SHOWHELP; } -static int32_t osdcmd_quicksave(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_quicksave(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); if (!(g_player[myconnectindex].ps->gm & MODE_GAME)) @@ -1083,7 +981,7 @@ static int32_t osdcmd_quicksave(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_quickload(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_quickload(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); if (!(g_player[myconnectindex].ps->gm & MODE_GAME)) @@ -1092,7 +990,7 @@ static int32_t osdcmd_quickload(osdfuncparm_t const * const UNUSED(parm)) return OSDCMD_OK; } -static int32_t osdcmd_screenshot(osdfuncparm_t const * const parm) +static int osdcmd_screenshot(osdcmdptr_t parm) { // KB_ClearKeysDown(); static const char *fn = "duke0000.png"; @@ -1105,14 +1003,14 @@ static int32_t osdcmd_screenshot(osdfuncparm_t const * const parm) } #if 0 -static int32_t osdcmd_savestate(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_savestate(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_PARAMETER(parm); G_SaveMapState(); return OSDCMD_OK; } -static int32_t osdcmd_restorestate(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_restorestate(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_PARAMETER(parm); G_RestoreMapState(); @@ -1121,7 +1019,7 @@ static int32_t osdcmd_restorestate(osdfuncparm_t const * const UNUSED(parm)) #endif #ifdef DEBUGGINGAIDS -static int32_t osdcmd_inittimer(osdfuncparm_t const * const parm) +static int osdcmd_inittimer(osdcmdptr_t parm) { if (parm->numparms != 1) { @@ -1137,14 +1035,14 @@ static int32_t osdcmd_inittimer(osdfuncparm_t const * const parm) #endif #if !defined NETCODE_DISABLE -static int32_t osdcmd_disconnect(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_disconnect(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); g_netDisconnect = 1; return OSDCMD_OK; } -static int32_t osdcmd_connect(osdfuncparm_t const * const parm) +static int osdcmd_connect(osdcmdptr_t parm) { if (parm->numparms != 1) return OSDCMD_SHOWHELP; @@ -1154,7 +1052,7 @@ static int32_t osdcmd_connect(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_password(osdfuncparm_t const * const parm) +static int osdcmd_password(osdcmdptr_t parm) { if (parm->numparms < 1) { @@ -1166,7 +1064,7 @@ static int32_t osdcmd_password(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_listplayers(osdfuncparm_t const * const parm) +static int osdcmd_listplayers(osdcmdptr_t parm) { ENetPeer *currentPeer; char ipaddr[32]; @@ -1197,7 +1095,7 @@ static int32_t osdcmd_listplayers(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_kick(osdfuncparm_t const * const parm) +static int osdcmd_kick(osdcmdptr_t parm) { ENetPeer *currentPeer; uint32_t hexaddr; @@ -1235,7 +1133,7 @@ static int32_t osdcmd_kick(osdfuncparm_t const * const parm) return OSDCMD_OK; } -static int32_t osdcmd_kickban(osdfuncparm_t const * const parm) +static int osdcmd_kickban(osdcmdptr_t parm) { ENetPeer *currentPeer; uint32_t hexaddr; @@ -1280,18 +1178,19 @@ static int32_t osdcmd_kickban(osdfuncparm_t const * const parm) } #endif -static int32_t osdcmd_purgesaves(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_purgesaves(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); G_DeleteOldSaves(); return OSDCMD_OK; } -static int32_t osdcmd_printtimes(osdfuncparm_t const * const UNUSED(parm)) +static int osdcmd_printtimes(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); char buf[32]; + int32_t maxlen = 0; int32_t haveac=0; for (int i=0; iname, "r_maxfps")) + else if (!Bstrcasecmp(parm->name, "r_maxfps") || !Bstrcasecmp(parm->name, "r_maxfpsoffset")) { if (r_maxfps != 0) r_maxfps = clamp(r_maxfps, 30, 1000); - g_frameDelay = r_maxfps ? (timerGetFreqU64()/r_maxfps) : 0; + g_frameDelay = calcFrameDelay(r_maxfps + r_maxfpsoffset); } else if (!Bstrcasecmp(parm->name, "r_ambientlight")) { @@ -1357,11 +1256,11 @@ static int32_t osdcmd_cvar_set_game(osdfuncparm_t const * const 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")) { @@ -1450,9 +1349,9 @@ static int32_t osdcmd_cvar_set_game(osdfuncparm_t const * const parm) return r; } -static int32_t osdcmd_cvar_set_multi(osdfuncparm_t const * const parm) +static int osdcmd_cvar_set_multi(osdcmdptr_t parm) { - int32_t r = osdcmd_cvar_set_game(parm); + int const r = osdcmd_cvar_set_game(parm); if (r != OSDCMD_OK) return r; @@ -1463,8 +1362,6 @@ static int32_t osdcmd_cvar_set_multi(osdfuncparm_t const * const parm) int32_t registerosdcommands(void) { - uint32_t i; - static osdcvardata_t cvars_game[] = { { "crosshair", "enable/disable crosshair", (void *)&ud.crosshair, CVAR_BOOL, 0, 1 }, @@ -1517,6 +1414,8 @@ int32_t registerosdcommands(void) { "demoplay_diffs","enable/disable application of diffs in demo playback",(void *)&demoplay_diffs, CVAR_BOOL, 0, 1 }, { "demoplay_showsync","enable/disable display of sync status",(void *)&demoplay_showsync, CVAR_BOOL, 0, 1 }, + { "fov", "change the field of view", (void *)&ud.fov, CVAR_INT|CVAR_FUNCPTR, 75, 120 }, + { "hud_althud", "enable/disable alternate mini-hud", (void *)&ud.althud, CVAR_BOOL, 0, 1 }, { "hud_custom", "change the custom hud", (void *)&ud.statusbarcustom, CVAR_INT, 0, ud.statusbarrange }, { "hud_position", "aligns the status bar to the bottom/top", (void *)&ud.hudontop, CVAR_BOOL, 0, 1 }, @@ -1538,8 +1437,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 }, { @@ -1560,6 +1459,7 @@ int32_t registerosdcommands(void) { "r_camrefreshdelay", "minimum delay between security camera sprite updates, 120 = 1 second", (void *)&ud.camera_time, CVAR_INT, 1, 240 }, { "r_drawweapon", "enable/disable weapon drawing", (void *)&ud.drawweapon, CVAR_INT, 0, 2 }, { "r_showfps", "show the frame rate counter", (void *)&ud.showfps, CVAR_INT, 0, 3 }, + { "r_showfpsperiod", "time in seconds before averaging min and max stats for r_showfps 2+", (void *)&ud.frameperiod, CVAR_INT, 0, 5 }, { "r_shadows", "enable/disable sprite and model shadows", (void *)&ud.shadows, CVAR_BOOL, 0, 1 }, { "r_size", "change size of viewable area", (void *)&ud.screen_size, CVAR_INT|CVAR_FUNCPTR, 0, 64 }, { "r_rotatespritenowidescreen", "pass bit 1024 to all CON rotatesprite calls", (void *)&g_rotatespriteNoWidescreen, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 }, @@ -1568,6 +1468,7 @@ int32_t registerosdcommands(void) { "r_ambientlight", "sets the global map light level",(void *)&r_ambientlight, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 }, { "r_maxfps", "limit the frame rate",(void *)&r_maxfps, CVAR_INT|CVAR_FUNCPTR, 0, 1000 }, + { "r_maxfpsoffset", "menu-controlled offset for r_maxfps",(void *)&r_maxfpsoffset, CVAR_INT|CVAR_FUNCPTR, -10, 10 }, { "sensitivity","changes the mouse sensitivity", (void *)&CONTROL_MouseSensitivity, CVAR_FLOAT|CVAR_FUNCPTR, 0, 25 }, @@ -1600,17 +1501,17 @@ int32_t registerosdcommands(void) osdcmd_cheatsinfo_stat.cheatnum = -1; - for (i=0; i=0; j--) - t[j] = Btolower(t[j]); - Bstrcat(tempbuf,": game button"); + Bsprintf(tempbuf, "gamefunc_%s", func); + + char *const t = Bstrtolower(Xstrdup(tempbuf)); + + Bstrcat(tempbuf, ": game button"); + OSD_RegisterFunction(t, Xstrdup(tempbuf), osdcmd_button); } diff --git a/source/rr/src/osdcmds.h b/source/rr/src/osdcmds.h index d47d6d171..70d3bd9c8 100644 --- a/source/rr/src/osdcmds.h +++ b/source/rr/src/osdcmds.h @@ -45,7 +45,6 @@ typedef struct { int32_t id; } keydef_t; -extern const keydef_t ConsoleKeys[]; extern const char *const ConsoleButtons[]; extern uint32_t cl_cheatmask; diff --git a/source/rr/src/player.h b/source/rr/src/player.h index 49213f21f..77c213634 100644 --- a/source/rr/src/player.h +++ b/source/rr/src/player.h @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define player_h_ #include "inv.h" +#include "namesdyn.h" #include "fix16.h" #ifdef __cplusplus diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index e4e02b063..3a2effbf5 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -2346,7 +2346,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/rr/src/screens.cpp b/source/rr/src/screens.cpp index 349433e58..d9b11cec7 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -778,12 +778,14 @@ static void G_ShowCacheLocks(void) static void G_PrintFPS(void) { - static int32_t frameCount = 0, lastFPS = 0, lastFrameTime = 0, cumulativeFrameDelay = 0; - static int32_t minFPS = -1, maxFPS = 0; - static uint32_t minGameUpdate = -1, maxGameUpdate = 0; + static int32_t frameCount; + static double cumulativeFrameDelay; + static double lastFrameTime; + static float lastFPS, minFPS = FLT_MAX, maxFPS; + static double minGameUpdate = DBL_MAX, maxGameUpdate; - int32_t frameTime = timerGetTicks(); - int32_t frameDelay = frameTime - lastFrameTime; + double frameTime = timerGetHiTicks(); + double frameDelay = frameTime - lastFrameTime; cumulativeFrameDelay += frameDelay; if (frameDelay >= 0) @@ -792,7 +794,7 @@ static void G_PrintFPS(void) if (ud.showfps) { - int32_t chars = Bsprintf(tempbuf, "%d ms (%3d fps)", frameDelay, lastFPS); + int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS); printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, 0, -1, tempbuf, x); printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET, @@ -800,13 +802,13 @@ static void G_PrintFPS(void) if (ud.showfps > 1) { - chars = Bsprintf(tempbuf, "max fps: %3d", maxFPS); + chars = Bsprintf(tempbuf, "max: %5.1f fps", maxFPS); printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+10+2+FPS_YOFFSET, 0, -1, tempbuf, x); printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+10+FPS_YOFFSET, FPS_COLOR(maxFPS < LOW_FPS), -1, tempbuf, x); - chars = Bsprintf(tempbuf, "min fps: %3d", minFPS); + chars = Bsprintf(tempbuf, "min: %5.1f fps", minFPS); printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+20+2+FPS_YOFFSET, 0, -1, tempbuf, x); printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+20+FPS_YOFFSET, @@ -817,17 +819,29 @@ static void G_PrintFPS(void) if (g_gameUpdateTime > maxGameUpdate) maxGameUpdate = g_gameUpdateTime; if (g_gameUpdateTime < minGameUpdate) minGameUpdate = g_gameUpdateTime; - chars = Bsprintf(tempbuf, "Game Update: %2u ms GU & Draw: %2u ms", g_gameUpdateTime, g_gameUpdateAndDrawTime); + chars = Bsprintf(tempbuf, "Game Update: %2.2f ms + draw: %2.2f ms", g_gameUpdateTime, g_gameUpdateAndDrawTime); printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+30+2+FPS_YOFFSET, 0, -1, tempbuf, x); printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+30+FPS_YOFFSET, FPS_COLOR(g_gameUpdateAndDrawTime >= SLOW_FRAME_TIME), -1, tempbuf, x); - chars = Bsprintf(tempbuf, "Min GU: %2u ms Max GU: %2u ms Avg GU: %5.2f ms", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); + chars = Bsprintf(tempbuf, "GU min/max/avg: %5.2f/%5.2f/%5.2f ms", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime); printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+40+2+FPS_YOFFSET, 0, -1, tempbuf, x); printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+40+FPS_YOFFSET, FPS_COLOR(maxGameUpdate >= SLOW_FRAME_TIME), -1, tempbuf, x); + + chars = Bsprintf(tempbuf, "G_MoveActors(): %.3e ms", g_moveActorsTime); + + printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x); + printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET, + COLOR_WHITE, -1, tempbuf, x); + + chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3e ms", g_moveWorldTime); + + printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+60+2+FPS_YOFFSET, 0, -1, tempbuf, x); + printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+60+FPS_YOFFSET, + COLOR_WHITE, -1, tempbuf, x); } // lag meter @@ -841,24 +855,26 @@ static void G_PrintFPS(void) } } - if (cumulativeFrameDelay >= 1000) + if (cumulativeFrameDelay >= 1000.0) { - g_frameRate = lastFPS = tabledivide32_noinline(1000*frameCount, cumulativeFrameDelay); + lastFPS = 1000.f * frameCount / cumulativeFrameDelay; + g_frameRate = Blrintf(lastFPS); frameCount = 0; - cumulativeFrameDelay = 0; + cumulativeFrameDelay = 0.0; if (ud.showfps > 1) { if (lastFPS > maxFPS) maxFPS = lastFPS; - if ((unsigned) lastFPS < (unsigned) minFPS) minFPS = lastFPS; + if (lastFPS < minFPS) minFPS = lastFPS; + static int secondCounter; - if (++secondCounter == 3) + if (++secondCounter >= ud.frameperiod) { - maxFPS = (lastFPS + maxFPS) >> 1; - minFPS = (lastFPS + minFPS) >> 1; - maxGameUpdate = (g_gameUpdateTime + maxGameUpdate) >> 1; - minGameUpdate = (g_gameUpdateTime + minGameUpdate) >> 1; + maxFPS = (lastFPS + maxFPS) * .5f; + minFPS = (lastFPS + minFPS) * .5f; + maxGameUpdate = (g_gameUpdateTime + maxGameUpdate) * 0.5; + minGameUpdate = (g_gameUpdateTime + minGameUpdate) * 0.5; secondCounter = 0; } } diff --git a/source/rr/src/sector.h b/source/rr/src/sector.h index eaa3f1b3a..2de44ee1a 100644 --- a/source/rr/src/sector.h +++ b/source/rr/src/sector.h @@ -23,10 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef sector_h_ #define sector_h_ -#include "gamevars.h" #include "actors.h" // actor_t -#include "player.h" // playerspawn_t +#include "gamevars.h" +#include "macros.h" #include "namesdyn.h" // for G_GetForcefieldPicnum() +#include "player.h" // playerspawn_t #ifdef __cplusplus extern "C" { diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index aea82dafc..03692ed55 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -920,7 +920,7 @@ void S_Callback(intptr_t num) if (num == MUSIC_ID) return; - dq[dnum & (DQSIZE - 1)] = num; + dq[dnum & (DQSIZE - 1)] = (uint32_t)num; dnum++; } diff --git a/source/rr/src/startgtk.game.cpp b/source/rr/src/startgtk.game.cpp index 3fd2bb661..7e90c64ee 100644 --- a/source/rr/src/startgtk.game.cpp +++ b/source/rr/src/startgtk.game.cpp @@ -20,19 +20,16 @@ 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 "cmdline.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 +102,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 +124,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 +143,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 +162,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 +184,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 +307,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 +327,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) { @@ -134,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++; @@ -144,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); - } } } } @@ -248,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; } } @@ -312,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) { @@ -322,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) { @@ -355,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; @@ -409,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; @@ -433,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; @@ -455,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); @@ -464,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); @@ -488,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); @@ -514,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; } @@ -585,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) @@ -610,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 @@ -664,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; } @@ -686,7 +656,6 @@ int32_t startwin_idle(void *v) int32_t startwin_run(void) { - MSG msg; if (!startupdlg) return 1; done = -1; @@ -694,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: @@ -720,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;