From e0667544d2d7068e941a31c3d8aa2768534b688b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 15:15:42 -0600 Subject: [PATCH 1/8] Clamp chase_dist and chase_height because integer overflow is a thing. --- src/p_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_map.cpp b/src/p_map.cpp index 0b86aa41e..456db2d0f 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -4279,7 +4279,7 @@ CVAR(Float, chase_dist, 90.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) void P_AimCamera(AActor *t1, fixed_t &CameraX, fixed_t &CameraY, fixed_t &CameraZ, sector_t *&CameraSector) { - fixed_t distance = (fixed_t)(chase_dist * FRACUNIT); + fixed_t distance = (fixed_t)(clamp(chase_dist, 0, 30000) * FRACUNIT); angle_t angle = (t1->angle - ANG180) >> ANGLETOFINESHIFT; angle_t pitch = (angle_t)(t1->pitch) >> ANGLETOFINESHIFT; FTraceResults trace; @@ -4289,7 +4289,7 @@ void P_AimCamera(AActor *t1, fixed_t &CameraX, fixed_t &CameraY, fixed_t &Camera vy = FixedMul(finecosine[pitch], finesine[angle]); vz = finesine[pitch]; - sz = t1->z - t1->floorclip + t1->height + (fixed_t)(chase_height * FRACUNIT); + sz = t1->z - t1->floorclip + t1->height + (fixed_t)(clamp(chase_height, -1000, 1000) * FRACUNIT); if (Trace(t1->x, t1->y, sz, t1->Sector, vx, vy, vz, distance, 0, 0, NULL, trace) && From f00c8e194323e6939d642e37ce831cb6a135ee27 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 16:34:38 -0600 Subject: [PATCH 2/8] Revert "Move C_ExecCmdLineParams() call slightly later in the startup process." This reverts commit 3c376aa342994971e0e3f578476e8085d346cdf1. - I was wrong. It breaks pullin and complete logging (at the very least). --- src/d_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 2ceec3926..11a8c4ff0 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2273,6 +2273,8 @@ void D_DoomMain (void) execFiles = Args->GatherFiles ("-exec"); D_MultiExec (execFiles, true); + C_ExecCmdLineParams (); // [RH] do all +set commands on the command line + CopyFiles(allwads, pwads); // Since this function will never leave we must delete this array here manually. @@ -2288,8 +2290,6 @@ void D_DoomMain (void) // Now that wads are loaded, define mod-specific cvars. ParseCVarInfo(); - C_ExecCmdLineParams (); // [RH] do all +set commands on the command line - // [RH] Initialize localizable strings. GStrings.LoadStrings (false); From 4017a6d864b6fa4a97c4c6e8013c99169ccc4d3b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 17:21:57 -0600 Subject: [PATCH 3/8] Retry setting unknown cvars after CVARINFOs are processed. - Fixed: Using +set cvarname and +cvarname on the command line would not work if cvarname was defined in CVARINFO. This should be the proper way to fix it. Rather than move all command line execution after loading CVARINFO, keep command line execution before wads are loaded. If an attempt is made to set an unknown cvar or to run an unknown command (which could potentially be shorthand for setting an unknown cvar), save it and try running it again after all CVARINFOs have been handled. --- src/c_dispatch.cpp | 50 ++++++++++++++++++++++++++++++++++++++++------ src/c_dispatch.h | 1 + src/d_main.cpp | 3 +++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 65e017bdc..0719f5a90 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -185,6 +185,9 @@ static const char *KeyConfCommands[] = "clearplayerclasses" }; +static TArray StoredStartupSets; +static bool RunningStoredStartups; + // CODE -------------------------------------------------------------------- IMPLEMENT_CLASS (DWaitingCommand) @@ -537,6 +540,18 @@ void ResetButtonStates () } } +void C_ExecStoredSets() +{ + assert(!RunningStoredStartups); + RunningStoredStartups = true; + for (unsigned i = 0; i < StoredStartupSets.Size(); ++i) + { + C_DoCommand(StoredStartupSets[i]); + } + StoredStartupSets.Clear(); + RunningStoredStartups = false; +} + void C_DoCommand (const char *cmd, int keynum) { FConsoleCommand *com; @@ -612,7 +627,22 @@ void C_DoCommand (const char *cmd, int keynum) if ( (com = FindNameInHashTable (Commands, beg, len)) ) { - if (gamestate != GS_STARTUP || ParsingKeyConf || + if (gamestate == GS_STARTUP && !RunningStoredStartups && + len == 3 && strnicmp(beg, "set", 3) == 0) + { + // Save setting of unknown cvars for later, in case a loaded wad has a + // CVARINFO that defines it. + FCommandLine args(beg); + if (args.argc() > 1 && FindCVar(args[1], NULL) == NULL) + { + StoredStartupSets.Push(beg); + } + else + { + com->Run(args, players[consoleplayer].mo, keynum); + } + } + else if (gamestate != GS_STARTUP || ParsingKeyConf || (len == 3 && strnicmp (beg, "set", 3) == 0) || (len == 7 && strnicmp (beg, "logfile", 7) == 0) || (len == 9 && strnicmp (beg, "unbindall", 9) == 0) || @@ -657,12 +687,20 @@ void C_DoCommand (const char *cmd, int keynum) } else { // We don't know how to handle this command - char cmdname[64]; - size_t minlen = MIN (len, 63); + if (gamestate == GS_STARTUP && !RunningStoredStartups) + { + // Save it for later, in case a CVARINFO defines it. + StoredStartupSets.Push(beg); + } + else + { + char cmdname[64]; + size_t minlen = MIN (len, 63); - memcpy (cmdname, beg, minlen); - cmdname[len] = 0; - Printf ("Unknown command \"%s\"\n", cmdname); + memcpy (cmdname, beg, minlen); + cmdname[len] = 0; + Printf ("Unknown command \"%s\"\n", cmdname); + } } } } diff --git a/src/c_dispatch.h b/src/c_dispatch.h index f4518608d..b494005c7 100644 --- a/src/c_dispatch.h +++ b/src/c_dispatch.h @@ -42,6 +42,7 @@ class APlayerPawn; extern bool CheckCheatmode (bool printmsg = true); void C_ExecCmdLineParams (); +void C_ExecStoredSets(); // Add commands to the console as if they were typed in. Can handle wait // and semicolon-separated commands. This function may modify the source diff --git a/src/d_main.cpp b/src/d_main.cpp index 11a8c4ff0..817d3b9ec 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2290,6 +2290,9 @@ void D_DoomMain (void) // Now that wads are loaded, define mod-specific cvars. ParseCVarInfo(); + // Try setting previously unknown cvars again, as a CVARINFO may have made them known. + C_ExecStoredSets(); + // [RH] Initialize localizable strings. GStrings.LoadStrings (false); From 798267d223f0c5b0d39e5b9674557e986d75169d Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 17:29:13 -0600 Subject: [PATCH 4/8] Remove memcpy from "Unknown command" error printing --- src/c_dispatch.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/c_dispatch.cpp b/src/c_dispatch.cpp index 0719f5a90..7a6748fdc 100644 --- a/src/c_dispatch.cpp +++ b/src/c_dispatch.cpp @@ -694,12 +694,7 @@ void C_DoCommand (const char *cmd, int keynum) } else { - char cmdname[64]; - size_t minlen = MIN (len, 63); - - memcpy (cmdname, beg, minlen); - cmdname[len] = 0; - Printf ("Unknown command \"%s\"\n", cmdname); + Printf ("Unknown command \"%.*s\"\n", len, beg); } } } From bce7d12379ce1c892c0478d03978fb1083089c2c Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 18:40:15 -0600 Subject: [PATCH 5/8] Change clipping in DSBarInfo::DrawGraphic() - Fixed: When DSBarInfo::DrawGraphic() is used scaled, without fullscreen offset, if one of the top and left clip locations was 0 and the other was non-0, the 0 one would be clipped to the edge of a 4:3 box centered on the screen instead of the edge of the screen. --- src/g_shared/sbarinfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/g_shared/sbarinfo.cpp b/src/g_shared/sbarinfo.cpp index a738a5aad..7a11a2865 100644 --- a/src/g_shared/sbarinfo.cpp +++ b/src/g_shared/sbarinfo.cpp @@ -1215,7 +1215,11 @@ public: if(Scaled) { if(cx != 0 || cy != 0) + { screen->VirtualToRealCoords(dcx, dcy, tmp, tmp, script->resW, script->resH, true); + if (cx == 0) dcx = 0; + if (cy == 0) dcy = 0; + } if(cr != 0 || cb != 0 || clearDontDraw) screen->VirtualToRealCoords(dcr, dcb, tmp, tmp, script->resW, script->resH, true); screen->VirtualToRealCoords(dx, dy, w, h, script->resW, script->resH, true); From f76d137d33b32208cc7809221c0879889f2ab596 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 18:58:59 -0600 Subject: [PATCH 6/8] Be less ugly when hiding warnings for using the %B formatter - Take advantage of the new _Pragma operator to hide the printf warning suppression inside of macros instead of needing to litter the code around Printfs with a bunch of junk. --- src/p_3dfloors.cpp | 2 ++ src/p_acs.cpp | 17 ++--------------- src/zstring.h | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index d13e46204..fc35409dc 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -968,10 +968,12 @@ CCMD (dump3df) fixed_t height=ffloors[i]->top.plane->ZatPoint(CenterSpot(sector)); fixed_t bheight=ffloors[i]->bottom.plane->ZatPoint(CenterSpot(sector)); + IGNORE_FORMAT_PRE Printf("FFloor %d @ top = %f (model = %d), bottom = %f (model = %d), flags = %B, alpha = %d %s %s\n", i, height / 65536., ffloors[i]->top.model->sectornum, bheight / 65536., ffloors[i]->bottom.model->sectornum, ffloors[i]->flags, ffloors[i]->alpha, (ffloors[i]->flags&FF_EXISTS)? "Exists":"", (ffloors[i]->flags&FF_DYNAMIC)? "Dynamic":""); + IGNORE_FORMAT_POST } } } diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 2929eb32a..2ea64f26e 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -7496,22 +7496,9 @@ scriptwait: break; case PCD_PRINTBINARY: -#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6)))) || defined(__clang__) -#define HAS_DIAGNOSTIC_PRAGMA -#endif -#ifdef HAS_DIAGNOSTIC_PRAGMA -#pragma GCC diagnostic push -#ifdef __clang__ -#pragma GCC diagnostic ignored "-Wformat-invalid-specifier" -#else -#pragma GCC diagnostic ignored "-Wformat=" -#endif -#pragma GCC diagnostic ignored "-Wformat-extra-args" -#endif + IGNORE_FORMAT_PRE work.AppendFormat ("%B", STACK(1)); -#ifdef HAS_DIAGNOSTIC_PRAGMA -#pragma GCC diagnostic pop -#endif + IGNORE_FORMAT_POST --sp; break; diff --git a/src/zstring.h b/src/zstring.h index 1736f3421..fe7ee72cf 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -47,6 +47,24 @@ #define PRINTFISH(x) #endif +#ifdef __clang__ +#define IGNORE_FORMAT_PRE \ + _Pragma("GCC diagnostic push" \ + _Pragma("GCC diagnostic ignored \"-Wformat-invalid-specifier\"") \ + _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"") +#define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop") +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6))) +#define IGNORE_FORMAT_PRE \ + _Pragma("GCC diagnostic push" \ + _Pragma("GCC diagnostic ignored \"-Wformat=\"") \ + _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"") +#define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop") +#else +#define IGNORE_FORMAT_PRE +#define IGNORE_FORMAT_POST +#endif + + struct FStringData { unsigned int Len; // Length of string, excluding terminating null From 84afd2252f02f444cd1a22aeee70641a5268b306 Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Fri, 26 Dec 2014 20:10:41 -0500 Subject: [PATCH 7/8] - Fixed missing right paren on the first _Pragma from last commit. --- src/zstring.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zstring.h b/src/zstring.h index fe7ee72cf..0104020fa 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -49,13 +49,13 @@ #ifdef __clang__ #define IGNORE_FORMAT_PRE \ - _Pragma("GCC diagnostic push" \ + _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wformat-invalid-specifier\"") \ _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"") #define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop") #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6))) #define IGNORE_FORMAT_PRE \ - _Pragma("GCC diagnostic push" \ + _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wformat=\"") \ _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"") #define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop") From 1aa00f1b0eb574f8174e4821c3aa9f0a5ec08746 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 26 Dec 2014 19:22:09 -0600 Subject: [PATCH 8/8] Draw player setup cursor equivalently to options menu cursors - Explicitly size and position the text cursor in FListMenuItem::DrawSelector() the same way that the options menu does it using M_DrawConText(): By sizing it to a scaled 8x8 cell. --- src/menu/listmenu.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/menu/listmenu.cpp b/src/menu/listmenu.cpp index 53b4fee22..402c1d5e9 100644 --- a/src/menu/listmenu.cpp +++ b/src/menu/listmenu.cpp @@ -300,7 +300,12 @@ void FListMenuItem::DrawSelector(int xofs, int yofs, FTextureID tex) if ((DMenu::MenuTime%8) < 6) { screen->DrawText(ConFont, OptionSettings.mFontColorSelection, - mXpos + xofs, mYpos + yofs, "\xd", DTA_Clean, true, TAG_DONE); + (mXpos + xofs - 160) * CleanXfac + screen->GetWidth() / 2, + (mYpos + yofs - 100) * CleanYfac + screen->GetHeight() / 2, + "\xd", + DTA_CellX, 8 * CleanXfac, + DTA_CellY, 8 * CleanYfac, + TAG_DONE); } } else