slight cleanup drawOnMinimap

This commit is contained in:
Alug committed 2025-04-02 18:42:35 +02:00
1 parent 8033348aa1
commit 42b2e0622f
3 files changed
+68 -84

No files matched your search

+25 -14
View File
@@ -8256,6 +8256,25 @@ void K_getMinimapDrawinfo(drawinfo_t *out)
out->flags = fflags;
}
INT32 K_getMinimapTrans(void)
{
INT32 minimaptrans = cv_kartminimap.value;
if (!minimaptrans)
return 0;
if (forceshowhud)
return (10-minimaptrans)<<FF_TRANSSHIFT;
if (timeinmap <= 105)
return 0;
if (timeinmap <= 113)
minimaptrans = ((((INT32)timeinmap) - 105)*minimaptrans)/(113-105);
return (10-minimaptrans)<<FF_TRANSSHIFT;
}
patch_t *K_getItemBoxPatch(boolean small, boolean dark)
{
UINT8 ofs = (cv_darkitembox.value && dark ? 1 : 0) + (small ? 2 : 0);
@@ -10333,26 +10352,18 @@ static void K_drawKartMinimap(void)
return; // no pic, just get outta here
}
minimaptrans = K_getMinimapTrans();
// Exit early if it wouldn't draw anyway.
if (!minimaptrans)
return;
drawinfo_t info;
K_getMinimapDrawinfo(&info);
x = info.x - (SHORT(minimapinfo.minimap_pic->width)/2);
y = info.y - (SHORT(minimapinfo.minimap_pic->height)/2);
splitflags = info.flags;
if (forceshowhud)
minimaptrans = cv_kartminimap.value;
else if (timeinmap > 105)
{
minimaptrans = cv_kartminimap.value;
if (timeinmap <= 113)
minimaptrans = ((((INT32)timeinmap) - 105)*minimaptrans)/(113-105);
if (!minimaptrans)
return;
}
else
return;
minimaptrans = ((10-minimaptrans)<<FF_TRANSSHIFT);
splitflags |= minimaptrans;
if (encoremode)
+1
View File
@@ -124,6 +124,7 @@ typedef struct
patch_t *K_getItemBoxPatch(boolean small, boolean dark);
patch_t *K_getItemMulPatch(boolean small);
void K_getItemBoxDrawinfo(drawinfo_t *out);
INT32 K_getMinimapTrans(void);
void K_getLapsDrawinfo(drawinfo_t *out);
void K_getMinimapDrawinfo(drawinfo_t *out);
+42 -70
View File
@@ -599,71 +599,16 @@ static int libd_drawOnMinimap(lua_State *L)
boolean centered; // the patch is centered and doesn't need readjusting on x/y coordinates.
huddrawlist_h list;
patch_t *AutomapPic = NULL;
// base position of the minimap which also takes splits into account:
INT32 MM_X, MM_Y;
drawinfo_t info;
// variables used for actually drawing the icon:
INT32 splitflags, minimaptrans;
fixed_t amnumxpos, amnumypos;
fixed_t amxpos, amypos;
INT32 mm_x, mm_y;
fixed_t patchw, patchh;
fixed_t patchw = 0, patchh = 0;
HUDONLY // only run this function in hud hooks
x = luaL_checkinteger(L, 1);
y = luaL_checkinteger(L, 2);
scale = luaL_checkinteger(L, 3);
patch = *((patch_t **)luaL_checkudata(L, 4, META_PATCH));
if (!lua_isnoneornil(L, 5))
colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP));
centered = lua_optboolean(L, 6);
// first, check what position the mmap is supposed to be in (pasted from k_kart.c):
MM_X = BASEVIDWIDTH - 50 + cv_mini_xoffset.value; // 270
MM_Y = (BASEVIDHEIGHT/2)-16 + cv_mini_yoffset.value; // 84
if (splitscreen)
{
MM_Y = (BASEVIDHEIGHT/2) + cv_mini_yoffset.value;
if (splitscreen > 1) // 3P : bottom right
{
MM_X = (3*BASEVIDWIDTH/4) + cv_mini_xoffset.value;
MM_Y = (3*BASEVIDHEIGHT/4) + cv_mini_yoffset.value;
if (splitscreen > 2) // 4P: centered
{
MM_X = (BASEVIDWIDTH/2) + cv_mini_xoffset.value;
MM_Y = (BASEVIDHEIGHT/2) + cv_mini_yoffset.value;
}
}
}
// splitscreen flags
splitflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split)
// translucency:
if (timeinmap > 105)
{
minimaptrans = cv_kartminimap.value;
if (timeinmap <= 113)
minimaptrans = ((((INT32)timeinmap) - 105)*minimaptrans)/(113-105);
if (!minimaptrans)
return 0;
}
else
return 0;
minimaptrans = ((10-minimaptrans)<<FF_TRANSSHIFT);
splitflags |= minimaptrans;
if (!(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.
@@ -680,9 +625,37 @@ static int libd_drawOnMinimap(lua_State *L)
return 0; // no pic, just get outta here
}
minimaptrans = K_getMinimapTrans();
// Exit early if it wouldn't draw anyway.
if (!minimaptrans)
return 0;
x = luaL_checkinteger(L, 1);
y = luaL_checkinteger(L, 2);
scale = luaL_checkinteger(L, 3);
patch = *((patch_t **)luaL_checkudata(L, 4, META_PATCH));
if (!lua_isnoneornil(L, 5))
colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP));
centered = lua_optboolean(L, 6);
K_getMinimapDrawinfo(&info);
splitflags = info.flags;
splitflags |= minimaptrans;
if (!(splitscreen == 2))
{
splitflags &= ~minimaptrans;
splitflags |= V_HUDTRANSHALF;
}
splitflags &= ~V_HUDTRANSHALF;
splitflags |= V_HUDTRANS;
// Handle offsets and stuff.
mm_x = MM_X - (SHORT(AutomapPic->width)/2);
mm_y = MM_Y - (SHORT(AutomapPic->height)/2);
mm_x = info.x - (SHORT(AutomapPic->width)/2);
mm_y = info.y - (SHORT(AutomapPic->height)/2);
// let offsets transfer to the heads, too!
if (encoremode)
@@ -696,13 +669,12 @@ static int libd_drawOnMinimap(lua_State *L)
mm_y -= SHORT(AutomapPic->topoffset);
// scale patch coords
patchw = (SHORT(patch->width) * scale / 2);
patchh = (SHORT(patch->height) * scale / 2);
if (centered)
// patch is supposedly already centered, don't butt in.
if (!centered)
{
patchw = patchh = 0; // patch is supposedly already centered, don't butt in.
// scale patch coords
patchw = (SHORT(patch->width) * scale / 2);
patchh = (SHORT(patch->height) * scale / 2);
}
amnumxpos = (FixedMul(x, minimapinfo.zoom) - minimapinfo.offs_x);
@@ -716,11 +688,6 @@ static int libd_drawOnMinimap(lua_State *L)
amxpos = amnumxpos + ((mm_x + SHORT(AutomapPic->width) / 2)<<FRACBITS) - patchw;
amypos = amnumypos + ((mm_y + SHORT(AutomapPic->height) / 2)<<FRACBITS) - patchh;
// and NOW we can FINALLY DRAW OUR GOD DAMN PATCH :V
lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
list = (huddrawlist_h) lua_touserdata(L, -1);
lua_pop(L, 1);
if (cv_minihead.value)
{
amxpos += patchw / 2;
@@ -728,6 +695,11 @@ static int libd_drawOnMinimap(lua_State *L)
scale /= 2;
}
// and NOW we can FINALLY DRAW OUR GOD DAMN PATCH :V
lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
list = (huddrawlist_h) lua_touserdata(L, -1);
lua_pop(L, 1);
if (LUA_HUD_IsDrawListValid(list))
{
LUA_HUD_AddDrawScaled(list, amxpos, amypos, scale, patch, splitflags, colormap, 0);