From 12ffca73740a99549b52bb07126ff906e0ffe7e7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 04:13:02 +0200 Subject: [PATCH] precalc automap and minimap stuff on mapload instead of every frame --- src/am_map.c | 24 +++++---------- src/k_kart.c | 85 ++++++++++++--------------------------------------- src/p_local.h | 12 ++++++++ src/p_setup.c | 57 ++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 83 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index d94ec7262..ac8236b41 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -260,25 +260,15 @@ static inline void AM_restoreScaleAndLoc(void) */ static void AM_findMinMaxBoundaries(void) { - size_t i; - fixed_t a; - fixed_t b; + fixed_t a, b; - min_x = min_y = +INT32_MAX; - max_x = max_y = -INT32_MAX; + min_x = minimapinfo.min_x << MAPBITS; + max_x = minimapinfo.max_x << MAPBITS; + min_y = minimapinfo.min_y << MAPBITS; + max_y = minimapinfo.max_y << MAPBITS; - for (i = 0; i < numvertexes; i++) - { - if (vertexes[i].x < min_x) - min_x = vertexes[i].x; - else if (vertexes[i].x > max_x) - max_x = vertexes[i].x; - - if (vertexes[i].y < min_y) - min_y = vertexes[i].y; - else if (vertexes[i].y > max_y) - max_y = vertexes[i].y; - } + max_w = minimapinfo.map_w << MAPBITS; + max_h = minimapinfo.map_h << MAPBITS; max_w = (max_x >>= FRACTOMAPBITS) - (min_x >>= FRACTOMAPBITS); max_h = (max_y >>= FRACTOMAPBITS) - (min_y >>= FRACTOMAPBITS); diff --git a/src/k_kart.c b/src/k_kart.c index 03efb24c9..9ed535d3b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9622,7 +9622,7 @@ static void K_drawKartPlayerCheck(void) } } -static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, patch_t *AutomapPic) +static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) { // amnum xpos & ypos are the icon's speed around the HUD. // The number being divided by is for how fast it moves. @@ -9637,60 +9637,17 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat fixed_t amnumxpos, amnumypos; INT32 amxpos, amypos; - node_t *bsp = &nodes[numnodes-1]; - fixed_t maxx, minx, maxy, miny; - - fixed_t mapwidth, mapheight; - fixed_t xoffset, yoffset; - fixed_t xscale, yscale, zoom; - if (mo->skin) - skin = ((skin_t*)((mo->localskin) ? mo->localskin : mo->skin))-((skinlocal) ? localskins : skins); + skin = ((skin_t*)(mo->localskin ? mo->localskin : mo->skin))-(skinlocal ? localskins : skins); - maxx = maxy = INT32_MAX; - minx = miny = INT32_MIN; - minx = bsp->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(lerp(mo->old_x, mo->x), zoom) - FixedMul(xoffset, zoom)); - amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), zoom) - FixedMul(yoffset, zoom)); + amnumxpos = (FixedMul(lerp(mo->old_x, mo->x), minimapinfo.zoom) - minimapinfo.offs_x); + amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), minimapinfo.zoom) - minimapinfo.offs_y); if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((x + AutomapPic->width/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->width/2))<height/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->height/2))<width)-SHORT((skinlocal ? localfacemmapprefix : facemmapprefix)[skin]->width))/2)<height)-SHORT((skinlocal ? localfacemmapprefix : facemmapprefix)[skin]->height))/2)<color) // 'default' color V_DrawSciencePatch(amxpos, amypos, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], FRACUNIT); @@ -9728,8 +9685,6 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat static void K_drawKartMinimap(void) { - INT32 lumpnum; - patch_t *AutomapPic; INT32 i = 0; INT32 x, y; INT32 minimaptrans, splitflags; @@ -9744,17 +9699,15 @@ static void K_drawKartMinimap(void) if (stplyr != &players[displayplayers[0]]) return; - lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); - - if (lumpnum != -1) - AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); - else + if (minimapinfo.minimap_pic == NULL) + { return; // no pic, just get outta here + } drawinfo_t info; K_getMinimapDrawinfo(&info); - x = info.x - (AutomapPic->width/2); - y = info.y - (AutomapPic->height/2); + x = info.x - (SHORT(minimapinfo.minimap_pic->width)/2); + y = info.y - (SHORT(minimapinfo.minimap_pic->height)/2); splitflags = info.flags; @@ -9775,9 +9728,9 @@ static void K_drawKartMinimap(void) splitflags |= minimaptrans; if (encoremode) - V_DrawScaledPatch(x+(AutomapPic->width), y, splitflags|V_FLIP, AutomapPic); + V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, minimaptrans|V_FLIP, minimapinfo.minimap_pic); else - V_DrawScaledPatch(x, y, splitflags, AutomapPic); + V_DrawScaledPatch(x, y, splitflags, minimapinfo.minimap_pic); if (!(splitscreen == 2)) { @@ -9787,10 +9740,10 @@ static void K_drawKartMinimap(void) // 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 < 4; i++) @@ -9802,7 +9755,7 @@ static void K_drawKartMinimap(void) demoghost *g = ghosts; while (g) { - K_drawKartMinimapHead(g->mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(g->mo, x, y, splitflags); g = g->next; } @@ -9843,7 +9796,7 @@ static void K_drawKartMinimap(void) continue; } - K_drawKartMinimapHead(players[i].mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(players[i].mo, x, y, splitflags); } } @@ -9855,7 +9808,7 @@ static void K_drawKartMinimap(void) { if (i == -1) continue; // this doesn't interest us - K_drawKartMinimapHead(players[localplayers[i]].mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(players[localplayers[i]].mo, x, y, splitflags); } } diff --git a/src/p_local.h b/src/p_local.h index 0193ec09d..6916acc44 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -392,6 +392,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 671ba92ac..17d050dc4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2487,6 +2487,61 @@ static boolean P_CanSave(void) return false; // SRB2Kart: no SP, no saving. } +struct minimapinfo minimapinfo; +static void P_InitMinimapInfo(void) +{ + INT32 lumpnum; + fixed_t a; + fixed_t b; + node_t *bsp = &nodes[numnodes-1]; + lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); + + if (lumpnum != -1) + minimapinfo.minimap_pic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); + + 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 skipprecip If true, don't spawn precipitation. @@ -2738,6 +2793,8 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) P_SpawnSecretItems(loademblems); + P_InitMinimapInfo(); + for (numcoopstarts = 0; numcoopstarts < MAXPLAYERS; numcoopstarts++) if (!playerstarts[numcoopstarts]) break;