From b4dcc12e4ff87b51e7e51d32c5793a2a2247a1a6 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 24 Jan 2023 16:10:01 +0000 Subject: [PATCH] Support for user-specified minimap bounds The totally-not-a-secret reason I made this branch. - doomednum 770 (associated with polyobject anchors 760/761 and skybox centerpoint 780) - Place exactly two in a map to draw an implicit rectangle. - Supports top-left/bottom-right AND bottom-left/top-right placements. - I_Errors if you place too many (or only one). - You don't *have* to have these, this is just a bonus if you're a map like Power Plant or CDSS1 negatively affected by your skybox. --- src/info/mobjs.h | 1 + src/p_local.h | 1 - src/p_setup.c | 79 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/info/mobjs.h b/src/info/mobjs.h index 6d1c86690..420089a39 100644 --- a/src/info/mobjs.h +++ b/src/info/mobjs.h @@ -730,6 +730,7 @@ _(OVERLAY) _(ANGLEMAN) _(POLYANCHOR) _(POLYSPAWN) +_(MINIMAPBOUND) // Skybox objects _(SKYBOX) diff --git a/src/p_local.h b/src/p_local.h index 0c0bea7f2..c58ff19cf 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -523,7 +523,6 @@ 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; diff --git a/src/p_setup.c b/src/p_setup.c index 6ac25edfa..b51786f24 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -8138,6 +8138,7 @@ struct minimapinfo minimapinfo; static void P_InitMinimapInfo(void) { + size_t i, count; fixed_t a; fixed_t b; @@ -8145,29 +8146,67 @@ static void P_InitMinimapInfo(void) minimapinfo.minimap_pic = mapheaderinfo[gamemap-1]->minimapPic; - minimapinfo.mapthingcount = 0; - // TODO iterate over mapthings to look for possible user-defined bounds + minimapinfo.min_x = minimapinfo.max_x = minimapinfo.min_y = minimapinfo.max_y = INT32_MAX; + count = 0; + for (i = 0; i < nummapthings; i++) + { + if (mapthings[i].type != mobjinfo[MT_MINIMAPBOUND].doomednum) + continue; + count++; - 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 (mapthings[i].x < minimapinfo.min_x) + { + minimapinfo.max_x = minimapinfo.min_x; + minimapinfo.min_x = mapthings[i].x; + } + else + { + minimapinfo.max_x = mapthings[i].x; + } - 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]; + if (mapthings[i].y < minimapinfo.min_y) + { + minimapinfo.max_y = minimapinfo.min_y; + minimapinfo.min_y = mapthings[i].y; + } + else + { + minimapinfo.max_y = mapthings[i].y; + } + } - // 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); + if (count == 0) + { + 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.min_x >>= FRACBITS; + minimapinfo.max_x >>= FRACBITS; + minimapinfo.min_y >>= FRACBITS; + minimapinfo.max_y >>= FRACBITS; + } + else if (count != 2) + { + I_Error("P_InitMinimapInfo: Too %s minimap helper objects! (found %s of mapthingnum %d, should have 2)", + (count < 2 ? "few" : "many"), sizeu1(count), mobjinfo[MT_MINIMAPBOUND].doomednum); + } + minimapinfo.map_w = minimapinfo.max_x - minimapinfo.min_x; + minimapinfo.map_h = minimapinfo.max_y - minimapinfo.min_y; minimapinfo.minimap_w = minimapinfo.minimap_h = 100;