mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'drawOnMinimapInbounds' into 'master'
Fix and refactor drawOnMinimap (resolves #39, #192) Closes #192 and #39 See merge request KartKrew/RingRacers!40
This commit is contained in:
commit
2bc5fcc047
3 changed files with 116 additions and 173 deletions
122
src/k_hud.cpp
122
src/k_hud.cpp
|
|
@ -4234,6 +4234,19 @@ static void K_drawKartProgressionMinimapIcon(UINT32 distancetofinish, INT32 hudx
|
|||
V_DrawFixedPatch(hudx, hudy, FRACUNIT, flags, icon, colormap);
|
||||
}
|
||||
|
||||
position_t K_GetKartObjectPosToMinimapPos(fixed_t objx, fixed_t objy)
|
||||
{
|
||||
fixed_t amnumxpos, amnumypos;
|
||||
|
||||
amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x);
|
||||
amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y);
|
||||
|
||||
if (encoremode)
|
||||
amnumxpos = -amnumxpos;
|
||||
|
||||
return (position_t){amnumxpos, amnumypos};
|
||||
}
|
||||
|
||||
static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 hudy, INT32 flags, patch_t *icon, UINT8 *colormap)
|
||||
{
|
||||
// amnum xpos & ypos are the icon's speed around the HUD.
|
||||
|
|
@ -4242,35 +4255,27 @@ static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32
|
|||
|
||||
// am xpos & ypos are the icon's starting position. Withouht
|
||||
// it, they wouldn't 'spawn' on the top-right side of the HUD.
|
||||
|
||||
fixed_t amnumxpos, amnumypos;
|
||||
|
||||
position_t amnumpos;
|
||||
INT32 amxpos, amypos;
|
||||
|
||||
amnumpos = K_GetKartObjectPosToMinimapPos(objx, objy);
|
||||
|
||||
amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x);
|
||||
amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y);
|
||||
|
||||
if (encoremode)
|
||||
amnumxpos = -amnumxpos;
|
||||
|
||||
amxpos = amnumxpos + ((hudx - (SHORT(icon->width))/2)<<FRACBITS);
|
||||
amypos = amnumypos + ((hudy - (SHORT(icon->height))/2)<<FRACBITS);
|
||||
amxpos = amnumpos.x + ((hudx - (SHORT(icon->width))/2)<<FRACBITS);
|
||||
amypos = amnumpos.y + ((hudy - (SHORT(icon->height))/2)<<FRACBITS);
|
||||
|
||||
V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, icon, colormap);
|
||||
}
|
||||
|
||||
static void K_drawKartMinimapDot(fixed_t objx, fixed_t objy, INT32 hudx, INT32 hudy, INT32 flags, UINT8 color, UINT8 size)
|
||||
{
|
||||
fixed_t amnumxpos, amnumypos;
|
||||
position_t amnumpos;
|
||||
INT32 amxpos, amypos;
|
||||
|
||||
amnumxpos = (FixedMul(objx, minimapinfo.zoom) - minimapinfo.offs_x);
|
||||
amnumypos = -(FixedMul(objy, minimapinfo.zoom) - minimapinfo.offs_y);
|
||||
amnumpos = K_GetKartObjectPosToMinimapPos(objx, objy);
|
||||
|
||||
if (encoremode)
|
||||
amnumxpos = -amnumxpos;
|
||||
|
||||
amxpos = (amnumxpos / FRACUNIT);
|
||||
amypos = (amnumypos / FRACUNIT);
|
||||
amxpos = (amnumpos.x / FRACUNIT);
|
||||
amypos = (amnumpos.y / FRACUNIT);
|
||||
|
||||
if (flags & V_NOSCALESTART)
|
||||
{
|
||||
|
|
@ -4333,6 +4338,50 @@ static void K_drawKartMinimapWaypoint(waypoint_t *wp, UINT8 rank, INT32 hudx, IN
|
|||
K_drawKartMinimapDot(wp->mobj->x, wp->mobj->y, hudx, hudy, flags | V_NOSCALESTART, pal, size);
|
||||
}
|
||||
|
||||
INT32 K_GetMinimapTransFlags(const boolean usingProgressBar)
|
||||
{
|
||||
INT32 minimaptrans = 4;
|
||||
boolean dofade = (usingProgressBar && r_splitscreen > 0) || (!usingProgressBar && r_splitscreen >= 1);
|
||||
|
||||
if (dofade)
|
||||
{
|
||||
minimaptrans = FixedMul(minimaptrans, (st_translucency * FRACUNIT) / 10);
|
||||
|
||||
// If the minimap is fully transparent, just get your 0 back. Bail out with this.
|
||||
if (!minimaptrans)
|
||||
return minimaptrans;
|
||||
}
|
||||
|
||||
minimaptrans = ((10-minimaptrans)<<V_ALPHASHIFT);
|
||||
|
||||
return minimaptrans;
|
||||
}
|
||||
|
||||
INT32 K_GetMinimapSplitFlags(const boolean usingProgressBar)
|
||||
{
|
||||
INT32 splitflags = 0;
|
||||
|
||||
if (usingProgressBar)
|
||||
splitflags = (V_SLIDEIN|V_SNAPTOBOTTOM);
|
||||
else
|
||||
{
|
||||
if (r_splitscreen < 1) // 1P right aligned
|
||||
{
|
||||
splitflags = (V_SLIDEIN|V_SNAPTORIGHT);
|
||||
}
|
||||
else // 2/4P splits
|
||||
{
|
||||
if (r_splitscreen == 1)
|
||||
splitflags = V_SNAPTORIGHT; // 2P right aligned
|
||||
|
||||
// 3P lives in the middle of the bottom right
|
||||
// viewport and shouldn't fade in OR slide
|
||||
}
|
||||
}
|
||||
|
||||
return splitflags;
|
||||
}
|
||||
|
||||
#define ICON_DOT_RADIUS (10)
|
||||
|
||||
static void K_drawKartMinimap(void)
|
||||
|
|
@ -4342,8 +4391,8 @@ static void K_drawKartMinimap(void)
|
|||
INT32 i = 0;
|
||||
INT32 x, y;
|
||||
|
||||
INT32 minimaptrans = 4;
|
||||
INT32 splitflags = 0;
|
||||
INT32 minimaptrans;
|
||||
INT32 splitflags;
|
||||
|
||||
UINT8 skin = 0;
|
||||
UINT8 *colormap = NULL;
|
||||
|
|
@ -4356,7 +4405,7 @@ static void K_drawKartMinimap(void)
|
|||
fixed_t interpx, interpy;
|
||||
|
||||
boolean doprogressionbar = false;
|
||||
boolean dofade = false, doencore = false;
|
||||
boolean doencore = false;
|
||||
|
||||
UINT8 minipal;
|
||||
|
||||
|
|
@ -4377,6 +4426,11 @@ static void K_drawKartMinimap(void)
|
|||
// distancetofinish for an arbitrary object. ~toast 070423
|
||||
doprogressionbar = true;
|
||||
}
|
||||
|
||||
minimaptrans = K_GetMinimapTransFlags(doprogressionbar);
|
||||
if (!minimaptrans) return; // Exit early if it wouldn't draw anyway.
|
||||
|
||||
splitflags = K_GetMinimapSplitFlags(doprogressionbar);
|
||||
|
||||
if (doprogressionbar == false)
|
||||
{
|
||||
|
|
@ -4385,20 +4439,6 @@ static void K_drawKartMinimap(void)
|
|||
return; // no pic, just get outta here
|
||||
}
|
||||
|
||||
else if (r_splitscreen < 1) // 1P right aligned
|
||||
{
|
||||
splitflags = (V_SLIDEIN|V_SNAPTORIGHT);
|
||||
}
|
||||
else // 2/4P splits
|
||||
{
|
||||
if (r_splitscreen == 1)
|
||||
splitflags = V_SNAPTORIGHT; // 2P right aligned
|
||||
|
||||
dofade = true;
|
||||
}
|
||||
// 3P lives in the middle of the bottom right
|
||||
// viewport and shouldn't fade in OR slide
|
||||
|
||||
x = MINI_X;
|
||||
y = MINI_Y;
|
||||
|
||||
|
|
@ -4413,27 +4453,15 @@ static void K_drawKartMinimap(void)
|
|||
if (r_splitscreen > 0)
|
||||
{
|
||||
y = BASEVIDHEIGHT/2;
|
||||
dofade = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = 180;
|
||||
splitflags = (V_SLIDEIN|V_SNAPTOBOTTOM);
|
||||
}
|
||||
|
||||
workingPic = kp_wouldyoustillcatchmeifiwereaworm;
|
||||
}
|
||||
|
||||
if (dofade)
|
||||
{
|
||||
minimaptrans = FixedMul(minimaptrans, (st_translucency * FRACUNIT) / 10);
|
||||
|
||||
if (!minimaptrans)
|
||||
return;
|
||||
}
|
||||
|
||||
minimaptrans = ((10-minimaptrans)<<V_ALPHASHIFT);
|
||||
|
||||
// Really looking forward to never writing this loop again
|
||||
UINT8 bestplayer = MAXPLAYERS;
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
|
|
|
|||
11
src/k_hud.h
11
src/k_hud.h
|
|
@ -25,6 +25,8 @@ extern "C" {
|
|||
|
||||
#define POS_DELAY_TIME 10
|
||||
|
||||
extern INT32 MINI_X, MINI_Y;
|
||||
|
||||
struct trackingResult_t
|
||||
{
|
||||
fixed_t x, y;
|
||||
|
|
@ -34,6 +36,11 @@ struct trackingResult_t
|
|||
fixed_t fov;
|
||||
};
|
||||
|
||||
typedef struct position_t
|
||||
{
|
||||
fixed_t x, y;
|
||||
} position_t;
|
||||
|
||||
void K_ObjectTracking(trackingResult_t *result, const vector3_t *point, boolean reverse);
|
||||
|
||||
tic_t K_TranslateTimer(tic_t drawtime, UINT8 mode, INT32 *return_jitter);
|
||||
|
|
@ -118,6 +125,10 @@ playertagtype_t;
|
|||
playertagtype_t K_WhichPlayerTag(player_t *p);
|
||||
void K_DrawPlayerTag(fixed_t x, fixed_t y, player_t *p, playertagtype_t type, INT32 flags);
|
||||
|
||||
INT32 K_GetMinimapTransFlags(const boolean usingProgressBar);
|
||||
INT32 K_GetMinimapSplitFlags(const boolean usingProgressBar);
|
||||
position_t K_GetKartObjectPosToMinimapPos(fixed_t objx, fixed_t objy);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
156
src/lua_hudlib.c
156
src/lua_hudlib.c
|
|
@ -26,6 +26,7 @@
|
|||
#include "w_wad.h"
|
||||
#include "z_zone.h"
|
||||
#include "hu_stuff.h"
|
||||
#include "k_hud.h"
|
||||
|
||||
#include "lua_script.h"
|
||||
#include "lua_libs.h"
|
||||
|
|
@ -575,6 +576,7 @@ static int libd_drawStretched(lua_State *L)
|
|||
|
||||
// KART: draw patch on minimap from x, y coordinates on the map
|
||||
// Sal: Let's please just merge the relevant info into the actual function, and have Lua call that...
|
||||
// JugadorXEI: hey, sure.
|
||||
static int libd_drawOnMinimap(lua_State *L)
|
||||
{
|
||||
fixed_t x, y, scale; // coordinates of the object
|
||||
|
|
@ -585,22 +587,12 @@ static int libd_drawOnMinimap(lua_State *L)
|
|||
|
||||
// variables used to replicate k_kart's mmap drawer:
|
||||
patch_t *AutomapPic;
|
||||
INT32 mx, my;
|
||||
INT32 splitflags, minimaptrans;
|
||||
|
||||
// base position of the minimap which also takes splits into account:
|
||||
INT32 MM_X, MM_Y;
|
||||
|
||||
// variables used for actually drawing the icon:
|
||||
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;
|
||||
position_t amnumpos;
|
||||
INT32 minimapflags;
|
||||
fixed_t amxpos, amypos;
|
||||
INT32 mm_x, mm_y;
|
||||
fixed_t patchw, patchh;
|
||||
|
||||
HUDONLY // only run this function in hud hooks
|
||||
|
|
@ -611,56 +603,7 @@ static int libd_drawOnMinimap(lua_State *L)
|
|||
if (!lua_isnoneornil(L, 5))
|
||||
colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP));
|
||||
centered = lua_optboolean(L, 6);
|
||||
|
||||
// replicate exactly what source does for its minimap drawer; AKA hardcoded garbo.
|
||||
|
||||
// first, check what position the mmap is supposed to be in (pasted from k_kart.c):
|
||||
MM_X = BASEVIDWIDTH - 50; // 270
|
||||
MM_Y = (BASEVIDHEIGHT/2)-16; // 84
|
||||
if (r_splitscreen)
|
||||
{
|
||||
MM_Y = (BASEVIDHEIGHT/2);
|
||||
if (r_splitscreen > 1) // 3P : bottom right
|
||||
{
|
||||
MM_X = (3*BASEVIDWIDTH/4);
|
||||
MM_Y = (3*BASEVIDHEIGHT/4);
|
||||
|
||||
if (r_splitscreen > 2) // 4P: centered
|
||||
{
|
||||
MM_X = (BASEVIDWIDTH/2);
|
||||
MM_Y = (BASEVIDHEIGHT/2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// splitscreen flags
|
||||
splitflags = (r_splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split)
|
||||
|
||||
{
|
||||
const tic_t length = TICRATE/2;
|
||||
|
||||
if (!lt_exitticker)
|
||||
return 0;
|
||||
minimaptrans = 4;
|
||||
if (lt_exitticker < length)
|
||||
minimaptrans = (((INT32)lt_exitticker)*minimaptrans)/((INT32)length);
|
||||
if (!minimaptrans)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
minimaptrans = ((10-minimaptrans)<<FF_TRANSSHIFT);
|
||||
splitflags |= minimaptrans;
|
||||
|
||||
if (!(r_splitscreen == 2))
|
||||
{
|
||||
splitflags &= ~minimaptrans;
|
||||
splitflags |= V_HUDTRANSHALF;
|
||||
}
|
||||
|
||||
splitflags &= ~V_HUDTRANSHALF;
|
||||
splitflags |= V_HUDTRANS;
|
||||
|
||||
|
||||
// Draw the HUD only when playing in a level.
|
||||
// hu_stuff needs this, unlike st_stuff.
|
||||
if (gamestate != GS_LEVEL)
|
||||
|
|
@ -668,79 +611,40 @@ static int libd_drawOnMinimap(lua_State *L)
|
|||
|
||||
if (R_GetViewNumber() != 0)
|
||||
return 0;
|
||||
|
||||
AutomapPic = mapheaderinfo[gamemap-1]->minimapPic;
|
||||
|
||||
|
||||
AutomapPic = minimapinfo.minimap_pic;
|
||||
if (!AutomapPic)
|
||||
{
|
||||
return 0; // no pic, just get outta here
|
||||
}
|
||||
|
||||
mx = MM_X - (AutomapPic->width/2);
|
||||
my = MM_Y - (AutomapPic->height/2);
|
||||
|
||||
// let offsets transfer to the heads, too!
|
||||
|
||||
// Handle offsets and stuff.
|
||||
mm_x = MINI_X;
|
||||
mm_y = MINI_Y - SHORT(AutomapPic->topoffset);
|
||||
|
||||
if (encoremode)
|
||||
mx += SHORT(AutomapPic->leftoffset);
|
||||
{
|
||||
mm_x += SHORT(AutomapPic->leftoffset);
|
||||
}
|
||||
else
|
||||
mx -= SHORT(AutomapPic->leftoffset);
|
||||
my -= SHORT(AutomapPic->topoffset);
|
||||
{
|
||||
mm_x -= SHORT(AutomapPic->leftoffset);
|
||||
}
|
||||
|
||||
// now that we have replicated this behavior, we can draw an icon from our supplied x, y coordinates by replicating k_kart.c's totally understandable uncommented code!!!
|
||||
|
||||
// get map boundaries using nodes
|
||||
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;
|
||||
|
||||
// these are our final map boundaries:
|
||||
mapwidth = maxx - minx;
|
||||
mapheight = maxy - miny;
|
||||
|
||||
// These should always be small enough to be bitshift back right now
|
||||
xoffset = (minx + mapwidth/2)<<FRACBITS;
|
||||
yoffset = (miny + mapheight/2)<<FRACBITS;
|
||||
|
||||
xscale = FixedDiv(AutomapPic->width, mapwidth);
|
||||
yscale = FixedDiv(AutomapPic->height, mapheight);
|
||||
zoom = FixedMul(min(xscale, yscale), FRACUNIT-FRACUNIT/20);
|
||||
|
||||
amnumxpos = (FixedMul(x, zoom) - FixedMul(xoffset, zoom));
|
||||
amnumypos = -(FixedMul(y, zoom) - FixedMul(yoffset, zoom));
|
||||
|
||||
if (encoremode)
|
||||
amnumxpos = -amnumxpos;
|
||||
// Minimap flags:
|
||||
minimapflags = K_GetMinimapSplitFlags(false)|K_GetMinimapTransFlags(false);
|
||||
|
||||
// scale patch coords
|
||||
patchw = patch->width*scale /2;
|
||||
patchh = patch->height*scale /2;
|
||||
patchw = (SHORT(patch->width) / 2) * scale;
|
||||
patchh = (SHORT(patch->height) / 2) * scale;
|
||||
|
||||
if (centered)
|
||||
patchw = patchh = 0; // patch is supposedly already centered, don't butt in.
|
||||
|
||||
amxpos = amnumxpos + ((mx + AutomapPic->width/2)<<FRACBITS) - patchw;
|
||||
amypos = amnumypos + ((my + AutomapPic->height/2)<<FRACBITS) - patchh;
|
||||
amnumpos = K_GetKartObjectPosToMinimapPos(x, y);
|
||||
|
||||
amxpos = amnumpos.x + (mm_x<<FRACBITS) - patchw;
|
||||
amypos = amnumpos.y + (mm_y<<FRACBITS) - patchh;
|
||||
|
||||
// and NOW we can FINALLY DRAW OUR GOD DAMN PATCH :V
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
|
||||
|
|
@ -748,9 +652,9 @@ static int libd_drawOnMinimap(lua_State *L)
|
|||
lua_pop(L, 1);
|
||||
|
||||
if (LUA_HUD_IsDrawListValid(list))
|
||||
LUA_HUD_AddDrawScaled(list, amxpos, amypos, scale, patch, splitflags, colormap);
|
||||
LUA_HUD_AddDrawScaled(list, amxpos, amypos, scale, patch, minimapflags, colormap);
|
||||
else
|
||||
V_DrawFixedPatch(amxpos, amypos, scale, splitflags, patch, colormap);
|
||||
V_DrawFixedPatch(amxpos, amypos, scale, minimapflags, patch, colormap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue