From 8ed510ca88bcd1d024c768378a32d9fdc9f93da3 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 24 Jan 2023 14:46:25 +0000 Subject: [PATCH] Precalculate as much shared minimap/automap data on level load as possible - `P_InitMinimapInfo` - Writes to `p_local.h` extern struct - Handles everything previously distributed across multiple K_drawKartMinimapIcon calls (and most of AM_findMinMaxBoundaries) - Reduces complexity of drawKartMinimapIcon significantly - Last prerequisite before implementing user-placable minimap boundaries... --- src/am_map.c | 62 ++++++++------------------------ src/am_map.h | 2 +- src/k_hud.c | 95 +++++++++++--------------------------------------- src/m_misc.cpp | 4 +-- src/p_local.h | 12 +++++++ src/p_setup.c | 64 ++++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 126 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index 314d3ad8c..0618ec4ee 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -255,51 +255,21 @@ static inline void AM_restoreScaleAndLoc(void) */ static void AM_findMinMaxBoundaries(void) { - fixed_t a; - fixed_t b; + fixed_t a, b; - node_t *bsp = &nodes[numnodes-1]; + min_x = minimapinfo.min_x << MAPBITS; + max_x = minimapinfo.max_x << MAPBITS; + min_y = minimapinfo.min_y << MAPBITS; + max_y = minimapinfo.max_y << MAPBITS; - min_x = bsp->bbox[0][BOXLEFT]; - max_x = bsp->bbox[0][BOXRIGHT]; - min_y = bsp->bbox[0][BOXBOTTOM]; - max_y = bsp->bbox[0][BOXTOP]; - - if (bsp->bbox[1][BOXLEFT] < min_x) - min_x = bsp->bbox[1][BOXLEFT]; - if (bsp->bbox[1][BOXRIGHT] > max_x) - max_x = bsp->bbox[1][BOXRIGHT]; - if (bsp->bbox[1][BOXBOTTOM] < min_y) - min_y = bsp->bbox[1][BOXBOTTOM]; - if (bsp->bbox[1][BOXTOP] > max_y) - max_y = bsp->bbox[1][BOXTOP]; - - max_w = (max_x >>= FRACTOMAPBITS) - (min_x >>= FRACTOMAPBITS); - max_h = (max_y >>= FRACTOMAPBITS) - (min_y >>= FRACTOMAPBITS); + max_w = minimapinfo.map_w << MAPBITS; + max_h = minimapinfo.map_h << MAPBITS; a = FixedDiv(f_w<>FRACBITS; - } - min_scale_mtof = a; - max_scale_mtof = f_h; - } - else - { - if (am_minigen) - { - f_w = FixedMul(b, max_w)>>FRACBITS; - } - min_scale_mtof = b; - max_scale_mtof = f_w; - } - max_scale_mtof = FixedDiv(max_scale_mtof<bbox[0][BOXLEFT]; - maxx = bsp->bbox[0][BOXRIGHT]; - miny = bsp->bbox[0][BOXBOTTOM]; - maxy = bsp->bbox[0][BOXTOP]; - - if (bsp->bbox[1][BOXLEFT] < minx) - minx = bsp->bbox[1][BOXLEFT]; - if (bsp->bbox[1][BOXRIGHT] > maxx) - maxx = bsp->bbox[1][BOXRIGHT]; - if (bsp->bbox[1][BOXBOTTOM] < miny) - miny = bsp->bbox[1][BOXBOTTOM]; - if (bsp->bbox[1][BOXTOP] > maxy) - maxy = bsp->bbox[1][BOXTOP]; - - // You might be wondering why these are being bitshift here - // it's because mapwidth and height would otherwise overflow for maps larger than half the size possible... - // map boundaries and sizes will ALWAYS be whole numbers thankfully - // later calculations take into consideration that these are actually not in terms of FRACUNIT though - minx >>= FRACBITS; - maxx >>= FRACBITS; - miny >>= FRACBITS; - maxy >>= FRACBITS; - - mapwidth = maxx - minx; - mapheight = maxy - miny; - - // These should always be small enough to be bitshift back right now - xoffset = (minx + mapwidth/2)<width, mapwidth); - yscale = FixedDiv(AutomapPic->height, mapheight); - zoom = FixedMul(min(xscale, yscale), FRACUNIT-FRACUNIT/20); - - amnumxpos = (FixedMul(objx, zoom) - FixedMul(xoffset, zoom)); - amnumypos = -(FixedMul(objy, zoom) - FixedMul(yoffset, zoom)); + amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x); + amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y); if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((hudx + AutomapPic->width/2 - (icon->width/2))<height/2 - (icon->height/2))<width/2 + (icon->width/2))<width)-SHORT(icon->width))/2)<height)-SHORT(icon->height))/2)<minimapPic; - - if (!AutomapPic) + if (minimapinfo.minimap_pic == NULL) { return; // no pic, just get outta here } @@ -3352,28 +3302,25 @@ static void K_drawKartMinimap(void) if (!minimaptrans) return; - x = MINI_X - (AutomapPic->width/2); - y = MINI_Y - (AutomapPic->height/2); + x = MINI_X - (SHORT(minimapinfo.minimap_pic->width)/2); + y = MINI_Y - (SHORT(minimapinfo.minimap_pic->height)/2); minimaptrans = ((10-minimaptrans)<width), y, splitflags|V_FLIP, AutomapPic); + V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, splitflags|minimaptrans|V_FLIP, minimapinfo.minimap_pic); else - V_DrawScaledPatch(x, y, splitflags, AutomapPic); + V_DrawScaledPatch(x, y, splitflags|minimaptrans, minimapinfo.minimap_pic); - { - splitflags &= ~minimaptrans; - splitflags |= V_HUDTRANSHALF; - } + // most icons will be rendered semi-ghostly. + splitflags |= V_HUDTRANSHALF; // let offsets transfer to the heads, too! if (encoremode) - x += SHORT(AutomapPic->leftoffset); + x += SHORT(minimapinfo.minimap_pic->leftoffset); else - x -= SHORT(AutomapPic->leftoffset); - y -= SHORT(AutomapPic->topoffset); + x -= SHORT(minimapinfo.minimap_pic->leftoffset); + y -= SHORT(minimapinfo.minimap_pic->topoffset); // initialize for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) @@ -3402,7 +3349,7 @@ static void K_drawKartMinimap(void) interpx = R_InterpolateFixed(g->mo->old_x, g->mo->x); interpy = R_InterpolateFixed(g->mo->old_y, g->mo->y); - K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, faceprefix[skin][FACE_MINIMAP], colormap, AutomapPic); + K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, faceprefix[skin][FACE_MINIMAP], colormap); g = g->next; } @@ -3469,13 +3416,13 @@ static void K_drawKartMinimap(void) interpx = R_InterpolateFixed(mobj->old_x, mobj->x); interpy = R_InterpolateFixed(mobj->old_y, mobj->y); - K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, workingPic, colormap, AutomapPic); + K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, workingPic, colormap); // Target reticule if ((gametype == GT_RACE && players[i].position == spbplace) || (gametype == GT_BATTLE && K_IsPlayerWanted(&players[i]))) { - K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, kp_wantedreticle, NULL, AutomapPic); + K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, kp_wantedreticle, NULL); } } } @@ -3532,7 +3479,7 @@ static void K_drawKartMinimap(void) interpx = R_InterpolateFixed(mobj->old_x, mobj->x); interpy = R_InterpolateFixed(mobj->old_y, mobj->y); - K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, workingPic, colormap, AutomapPic); + K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, workingPic, colormap); } // draw our local players here, opaque. @@ -3565,7 +3512,7 @@ static void K_drawKartMinimap(void) interpy = R_InterpolateFixed(bossinfo.weakspots[i].spot->old_y, bossinfo.weakspots[i].spot->y); // temporary graphic? - K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, kp_wantedreticle, colormap, AutomapPic); + K_drawKartMinimapIcon(interpx, interpy, x, y, splitflags, kp_wantedreticle, colormap); } } diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 7717e86a3..6c17583e2 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -1644,7 +1644,6 @@ void M_MinimapGenerate(void) char *filepath; boolean ret = false; minigen_t *minigen = NULL; - INT32 wh = 100; size_t option_scale; INT32 mul = 1; @@ -1682,7 +1681,6 @@ void M_MinimapGenerate(void) return; } - wh *= mul; filepath = va("%s" PATHSEP "MINIMAP-%d.png", srb2home, mul); } else @@ -1690,7 +1688,7 @@ void M_MinimapGenerate(void) filepath = va("%s" PATHSEP "MINIMAP.png", srb2home); } - minigen = AM_MinimapGenerate(wh); + minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) goto failure; diff --git a/src/p_local.h b/src/p_local.h index 89c9197c4..0c0bea7f2 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -520,6 +520,18 @@ extern fixed_t bmaporgy; // origin of block map extern mobj_t **blocklinks; // for thing chains extern precipmobj_t **precipblocklinks; // special blockmap for precip rendering +extern struct minimapinfo +{ + patch_t *minimap_pic; + UINT8 mapthingcount; + INT32 min_x, min_y; + INT32 max_x, max_y; + INT32 map_w, map_h; + INT32 minimap_w, minimap_h; + fixed_t offs_x, offs_y; + fixed_t zoom; +} minimapinfo; + // // P_INTER // diff --git a/src/p_setup.c b/src/p_setup.c index ab3b8b306..6ac25edfa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8134,6 +8134,68 @@ static void P_InitGametype(void) } } +struct minimapinfo minimapinfo; + +static void P_InitMinimapInfo(void) +{ + fixed_t a; + fixed_t b; + + node_t *bsp = &nodes[numnodes-1]; + + minimapinfo.minimap_pic = mapheaderinfo[gamemap-1]->minimapPic; + + minimapinfo.mapthingcount = 0; + // TODO iterate over mapthings to look for possible user-defined bounds + + minimapinfo.min_x = bsp->bbox[0][BOXLEFT]; + minimapinfo.max_x = bsp->bbox[0][BOXRIGHT]; + minimapinfo.min_y = bsp->bbox[0][BOXBOTTOM]; + minimapinfo.max_y = bsp->bbox[0][BOXTOP]; + + if (bsp->bbox[1][BOXLEFT] < minimapinfo.min_x) + minimapinfo.min_x = bsp->bbox[1][BOXLEFT]; + if (bsp->bbox[1][BOXRIGHT] > minimapinfo.max_x) + minimapinfo.max_x = bsp->bbox[1][BOXRIGHT]; + if (bsp->bbox[1][BOXBOTTOM] < minimapinfo.min_y) + minimapinfo.min_y = bsp->bbox[1][BOXBOTTOM]; + if (bsp->bbox[1][BOXTOP] > minimapinfo.max_y) + minimapinfo.max_y = bsp->bbox[1][BOXTOP]; + + // You might be wondering why these are being bitshift here + // it's because mapwidth and height would otherwise overflow for maps larger than half the size possible... + // map boundaries and sizes will ALWAYS be whole numbers thankfully + // later calculations take into consideration that these are actually not in terms of FRACUNIT though + minimapinfo.map_w = (minimapinfo.max_x >>= FRACBITS) - (minimapinfo.min_x >>= FRACBITS); + minimapinfo.map_h = (minimapinfo.max_y >>= FRACBITS) - (minimapinfo.min_y >>= FRACBITS); + + minimapinfo.minimap_w = minimapinfo.minimap_h = 100; + + a = FixedDiv(minimapinfo.minimap_w<>(FRACBITS-4); + minimapinfo.zoom = a; + } + else + { + if (a != b) + { + minimapinfo.minimap_w = FixedMul(b, minimapinfo.map_w)>>(FRACBITS-4); + } + minimapinfo.zoom = b; + } + + minimapinfo.zoom >>= (FRACBITS-4); + minimapinfo.zoom -= (minimapinfo.zoom/20); + + // These should always be small enough to be bitshift back right now + minimapinfo.offs_x = FixedMul((minimapinfo.min_x + minimapinfo.map_w/2) << FRACBITS, minimapinfo.zoom); + minimapinfo.offs_y = FixedMul((minimapinfo.min_y + minimapinfo.map_h/2) << FRACBITS, minimapinfo.zoom); +} + /** Loads a level from a lump or external wad. * * \param fromnetsave If true, skip some stuff because we're loading a netgame snapshot. @@ -8416,6 +8478,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) skyboxmo[0] = skyboxviewpnts[0]; skyboxmo[1] = skyboxcenterpnts[0]; + P_InitMinimapInfo(); + for (numcoopstarts = 0; numcoopstarts < MAXPLAYERS; numcoopstarts++) if (!playerstarts[numcoopstarts]) break;