Make this less insufferable

* Zero is now a valid tag for v.interpolate
* Reset lerp coordinates when v.interpString is called again
* Leaving string mode enabled on exit no longer breaks other scripts
* Fix fadeScreen having an uninitialized ID
This commit is contained in:
GenericHeroGuy committed 2024-04-04 23:39:23 +02:00
1 parent aeb5ae994e
commit 18e0485f39
3 files changed
+73 -29

No files matched your search

+3
View File
@@ -41,9 +41,12 @@ enum hud {
};
extern boolean hud_running;
extern boolean hud_interpolate;
extern UINT8 hud_interptag;
extern UINT32 hud_interpcounter;
extern boolean hud_interpstring;
extern boolean hud_interplatch;
boolean LUA_HudEnabled(enum hud option);
+30 -6
View File
@@ -32,9 +32,12 @@
#define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!");
boolean hud_running = false;
boolean hud_interpolate = false;
UINT8 hud_interptag = 0;
UINT32 hud_interpcounter = 0;
boolean hud_interpstring = false;
boolean hud_interplatch = false;
static UINT8 hud_enabled[(hud_MAX/8)+1];
static UINT8 hudAvailable; // hud hooks field
@@ -1184,14 +1187,35 @@ static int libd_getDrawInfo(lua_State *L)
static int libd_interpolate(lua_State *L)
{
HUDONLY
hud_interptag = luaL_checkinteger(L, 1);
// do type checking even if interpolation is disabled
boolean newinterpolate;
UINT8 newtag;
if (lua_isnumber(L, 1))
{
newinterpolate = true;
newtag = luaL_checkinteger(L, 1);
}
else
{
newinterpolate = luaL_checkboolean(L, 1);
newtag = 0;
}
if (!cv_uncappedhud.value)
return 0;
hud_interpolate = newinterpolate;
hud_interptag = newtag;
return 0;
}
static int libd_interpString(lua_State *L)
{
HUDONLY
hud_interpstring = luaL_checkboolean(L, 1);
hud_interpstring = hud_interplatch = luaL_checkboolean(L, 1);
return 0;
}
@@ -1460,7 +1484,7 @@ void LUAh_GameHUD(huddrawlist_h list)
hud_interpcounter = 0;
lua_pushnil(gL);
while (lua_next(gL, -5) != 0) {
hud_interptag = 0;
hud_interpolate = hud_interpstring = hud_interplatch = false;
hud_interpcounter++;
lua_pushvalue(gL, -5); // graphics library (HUD[1])
lua_pushvalue(gL, -5); // stplyr
@@ -1498,7 +1522,7 @@ void LUAh_ScoresHUD(huddrawlist_h list)
lua_pushnil(gL);
hud_interpcounter = 0;
while (lua_next(gL, -3) != 0) {
hud_interptag = 0;
hud_interpolate = hud_interpstring = hud_interplatch = false;
hud_interpcounter++;
lua_pushvalue(gL, -3); // graphics library (HUD[1])
LUA_Call(gL, 1, 0, 1);
@@ -1534,7 +1558,7 @@ void LUAh_IntermissionHUD(huddrawlist_h list)
lua_pushnil(gL);
hud_interpcounter = 0;
while (lua_next(gL, -3) != 0) {
hud_interptag = 0;
hud_interpolate = hud_interpstring = hud_interplatch = false;
hud_interpcounter++;
lua_pushvalue(gL, -3); // graphics library (HUD[1])
LUA_Call(gL, 1, 0, 1);
@@ -1570,7 +1594,7 @@ void LUAh_VoteHUD(huddrawlist_h list)
lua_pushnil(gL);
hud_interpcounter = 0;
while (lua_next(gL, -3) != 0) {
hud_interptag = 0;
hud_interpolate = hud_interpstring = hud_interplatch = false;
hud_interpcounter++;
lua_pushvalue(gL, -3); // graphics library (HUD[1])
LUA_Call(gL, 1, 0, 1);
+40 -23
View File
@@ -306,13 +306,27 @@ static void CalcFillCoords(drawitem_t *item)
}
}
// leave bit 0 free for the string mode
#define INTERP_LATCH 1
#define INTERP_STRING 2
#define GETITEMID \
item->id = hud_interptag \
? (((UINT64)gL->savedpc << 32) | (hud_interpcounter << 9) | (hud_interptag << 1) | (hud_interpstring ? INTERP_LATCH : 0)) \
: 0;
static UINT64 GetItemId(void)
{
if (!hud_interpolate)
return 0;
// leave bits 0 and 1 free for the string mode
UINT64 id = ((UINT64)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2);
if (hud_interplatch)
{
id |= INTERP_LATCH;
hud_interplatch = false;
}
if (hud_interpstring)
id |= INTERP_STRING;
return id;
}
void LUA_HUD_AddDraw(
huddrawlist_h list,
@@ -325,7 +339,7 @@ void LUA_HUD_AddDraw(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_Draw;
item->x = x << FRACBITS;
item->y = y << FRACBITS;
@@ -346,7 +360,7 @@ void LUA_HUD_AddDrawScaled(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawScaled;
item->x = x;
item->y = y;
@@ -369,7 +383,7 @@ void LUA_HUD_AddDrawStretched(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawStretched;
item->x = x;
item->y = y;
@@ -390,7 +404,7 @@ void LUA_HUD_AddDrawNum(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawNum;
item->x = x;
item->y = y;
@@ -409,7 +423,7 @@ void LUA_HUD_AddDrawPaddedNum(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawPaddedNum;
item->x = x;
item->y = y;
@@ -429,7 +443,7 @@ void LUA_HUD_AddDrawPingNum(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawPingNum;
item->x = x;
item->y = y;
@@ -449,7 +463,7 @@ void LUA_HUD_AddDrawFill(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawFill;
item->x = x;
item->y = y;
@@ -470,7 +484,7 @@ void LUA_HUD_AddDrawString(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawString;
item->x = x;
item->y = y;
@@ -490,7 +504,7 @@ void LUA_HUD_AddDrawKartString(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawKartString;
item->x = x;
item->y = y;
@@ -508,7 +522,7 @@ void LUA_HUD_AddDrawLevelTitle(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
GETITEMID
item->id = GetItemId();
item->type = DI_DrawLevelTitle;
item->x = x;
item->y = y;
@@ -524,6 +538,8 @@ void LUA_HUD_AddFadeScreen(
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
// nothing to interpolate here
item->id = 0;
item->type = DI_FadeScreen;
item->color = color;
item->strength = strength;
@@ -548,7 +564,7 @@ void LUA_HUD_DrawList(huddrawlist_h list)
drawitem_t *olditem = NULL;
const char *itemstr = &list->strbuf[item->stroffset];
if (item->id && cv_uncappedhud.value) {
if (item->id) {
// find the old one too
// this is kinda cursed... we need to check every item
// but stop when the first-checked item is reached again
@@ -568,13 +584,11 @@ void LUA_HUD_DrawList(huddrawlist_h list)
// gotcha!
olditem = old;
if (item->id & INTERP_LATCH) {
if (!latchitem) {
lerpx = FixedMul(frac, item->x - olditem->x);
lerpy = FixedMul(frac, item->y - olditem->y);
latchitem = item;
oldlatchitem = olditem;
}
} else {
lerpx = FixedMul(frac, item->x - olditem->x);
lerpy = FixedMul(frac, item->y - olditem->y);
latchitem = item;
oldlatchitem = olditem;
} else if (!(item->id & INTERP_STRING)) {
lerpx = FixedMul(frac, item->x - olditem->x);
lerpy = FixedMul(frac, item->y - olditem->y);
latchitem = NULL;
@@ -584,6 +598,9 @@ void LUA_HUD_DrawList(huddrawlist_h list)
if (j == stop)
break;
}
} else {
lerpx = lerpy = 0;
latchitem = NULL;
}
#define LERP(it) (olditem ? olditem->it + FixedMul(frac, item->it - olditem->it) : item->it)