From 970f9488446d6bedef115ee00d55dc8f6d140231 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 21 Sep 2024 20:13:53 +0200 Subject: [PATCH] precalc automap and minimap stuff on mapload instead of every frame --- src/am_map.c | 61 +++++++++++-------------------------- src/am_map.h | 2 +- src/k_kart.c | 83 ++++++++++++--------------------------------------- src/m_misc.c | 42 ++++++++++++++++++++++++-- src/p_local.h | 12 ++++++++ src/p_setup.c | 57 +++++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 112 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index d28f792f6..ef579ac38 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -252,23 +252,15 @@ 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 = 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); @@ -276,26 +268,8 @@ static void AM_findMinMaxBoundaries(void) 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<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); - 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); @@ -10014,8 +9973,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; @@ -10030,17 +9987,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; @@ -10061,9 +10016,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)) { @@ -10073,10 +10028,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++) @@ -10088,7 +10043,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; } @@ -10129,7 +10084,7 @@ static void K_drawKartMinimap(void) continue; } - K_drawKartMinimapHead(players[i].mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(players[i].mo, x, y, splitflags); } } @@ -10141,7 +10096,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/m_misc.c b/src/m_misc.c index 09661c9dd..c6e4bca8f 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1576,10 +1576,11 @@ boolean M_ScreenshotResponder(event_t *ev) void M_MinimapGenerate(void) { #ifdef USE_PNG - char *filepath = va(pandf, srb2home, "MINIMAP.png"); + char *filepath; boolean ret = false; minigen_t *minigen = NULL; - INT32 wh = 100; + size_t option_scale; + INT32 mul = 1; if (gamestate != GS_LEVEL) { @@ -1593,7 +1594,37 @@ void M_MinimapGenerate(void) return; } - minigen = AM_MinimapGenerate(wh); + option_scale = COM_CheckPartialParm("-m"); + + if (option_scale) + { + if (COM_Argc() < option_scale + 2)/* no argument after? */ + { + CONS_Alert(CONS_ERROR, + "No multiplier follows parameter '%s'.\n", + COM_Argv(option_scale)); + return; + } + + mul = atoi(COM_Argv(option_scale + 1)); + + if (mul < 1 || mul > 10) + { + CONS_Alert(CONS_ERROR, + "Multiplier %d must be within range 1-10.\n", + mul); + return; + } + + filepath = va("%s" PATHSEP "%s-MINIMAP-%d.png", srb2home, G_BuildMapName(gamemap), mul); + } + else + { + filepath = va("%s" PATHSEP "%s-MINIMAP.png", srb2home, G_BuildMapName(gamemap)); + } + + minigen = AM_MinimapGenerate(mul); + if (minigen == NULL || minigen->buf == NULL) goto failure; @@ -1607,6 +1638,10 @@ failure: if (ret) { CONS_Printf(M_GetText("%s saved.\nRemember that this is not a complete minimap,\nand must be edited before putting in-game.\n"), filepath); + if (mul != 1) + { + CONS_Printf("You should divide its size by %d!\n", mul); + } } else { @@ -1615,6 +1650,7 @@ failure: #endif //#ifdef USE_PNG } + // ========================================================================== // TRANSLATION FUNCTIONS // ========================================================================== diff --git a/src/p_local.h b/src/p_local.h index 021ebb443..b194d6caa 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -388,6 +388,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 28679a731..cd749aae5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2443,6 +2443,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. @@ -2694,6 +2749,8 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) P_SpawnSecretItems(loademblems); + P_InitMinimapInfo(); + for (numcoopstarts = 0; numcoopstarts < MAXPLAYERS; numcoopstarts++) if (!playerstarts[numcoopstarts]) break;