From 32ce2b47447c3dcca2abd0836141e21a11a6ce4a Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 27 Mar 2024 15:10:25 +0000 Subject: [PATCH] M_DrawCupPreview: Prevent glitchy rollover state (resolves #1183, #1048) Now performs unsigned portion of calculation including modulo, THEN multiplied by FRACUNIT Variable names have been adjusted a little to make this clearer --- src/k_menudraw.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 0c115c0fe..fd359091c 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -2764,9 +2764,12 @@ static void M_DrawCupPreview(INT16 y, levelsearch_t *baselevelsearch) UINT8 i = 0; INT16 maxlevels = M_CountLevelsToShowInList(&locklesslevelsearch); - const fixed_t step = (82 * FRACUNIT); - fixed_t previewanimwork = (cupgrid.previewanim * FRACUNIT) + rendertimefrac_unpaused; - fixed_t x = -(previewanimwork % step); + const UINT32 ustep = 82; + const fixed_t fracstep = (ustep * FRACUNIT); + + UINT32 unsignedportion = 0; + fixed_t x = 0; + INT16 map, start = M_GetFirstLevelInList(&i, &locklesslevelsearch); UINT8 starti = i; @@ -2774,7 +2777,10 @@ static void M_DrawCupPreview(INT16 y, levelsearch_t *baselevelsearch) if (baselevelsearch->cup && maxlevels > 0) { - INT16 add = (previewanimwork / step) % maxlevels; + unsignedportion = (cupgrid.previewanim % (maxlevels * ustep)); + x = (unsignedportion * FRACUNIT) + rendertimefrac_unpaused; + + INT16 add = (x / fracstep) % maxlevels; map = start; while (add > 0) { @@ -2787,6 +2793,8 @@ static void M_DrawCupPreview(INT16 y, levelsearch_t *baselevelsearch) add--; } + + x = -(x % fracstep); while (x < BASEVIDWIDTH * FRACUNIT) { if (map >= nummapheaders) @@ -2814,17 +2822,21 @@ static void M_DrawCupPreview(INT16 y, levelsearch_t *baselevelsearch) NULL); } - x += step; + x += fracstep; map = M_GetNextLevelInList(map, &i, &locklesslevelsearch); } } else { + unsignedportion = (cupgrid.previewanim % ustep); + x = (unsignedportion * FRACUNIT) + rendertimefrac_unpaused; + + x = -(x % fracstep); while (x < BASEVIDWIDTH * FRACUNIT) { V_DrawFixedPatch(x + FRACUNIT, (y+2) * FRACUNIT, FRACUNIT, 0, staticpat, NULL); - x += step; + x += fracstep; } } }