Merge remote-tracking branch 'ghghghghghg/lua-hudinterpolate-redux' into lugstuff

This commit is contained in:
Alug committed 2024-05-25 17:23:49 +02:00
commit c640096d9c
3 files changed
+37 -15

No files matched your search

+29 -4
View File
@@ -83,12 +83,37 @@ v.interpolate(false)
```
NOTE: The default tag for `true` is 0.
## v.interpString(true)
## v.interpLatch(true)
Enables string interpolation mode. The next call to a drawing function will have its interpolation offsets
latched and reused for all following draw calls.
Disable with `false` when done.
Enables interpolation offset latching. The next call to a drawing function will have its lerp offsets
saved and reused for all following draw calls. Disable with `false` when done.
Interpolation cannot easily "snap" between two points; latching can help overcome this by manually
setting the lerp offsets.
```lua
v.interpolate(true)
-- X coordinate for the HUD item
-- every so often, this will wrap around to zero
local x = (leveltime*4) % 256
-- draw an interpolated patch, but... when X rolls back to zero,
-- the patch will slide all the way across the screen!
v.draw(x, 100, ...)
-- this is where interpLatch comes into play
-- enable latching, then draw an invisible patch,
-- moving at the same speed as the visible patch
-- the exact coordinates don't matter, it just has to move at the right speed
v.interpLatch(true)
v.draw(leveltime*4, 0, v.cachePatch("K_TRNULL"))
-- now we can draw the patch again, and when X becomes zero,
-- it'll snap right back without sliding across the screen
v.draw(x, 150, ...)
-- don't forget to turn off latching!
v.interpLatch(false)
```
When using a custom string drawer, enable this mode to avoid interpolation artifacting when the string changes.
## mobj.spritexscale, mobj.spriteyscale, mobj.spritexoffset, mobj.spriteyoffset, mobj.rollangle, mobj.sloperoll, mobj.rollmodel fields
+2 -2
View File
@@ -1212,7 +1212,7 @@ static int libd_interpolate(lua_State *L)
return 0;
}
static int libd_interpString(lua_State *L)
static int libd_interpLatch(lua_State *L)
{
HUDONLY
hud_interpstring = hud_interplatch = luaL_checkboolean(L, 1);
@@ -1247,7 +1247,7 @@ static luaL_Reg lib_draw[] = {
{"getHudColor", libd_getHudColor},
{"useColorHud", libd_useColorHud},
{"interpolate", libd_interpolate},
{"interpString", libd_interpString},
{"interpLatch", libd_interpLatch},
{NULL, NULL}
};
+6 -9
View File
@@ -318,7 +318,7 @@ static void CalcFillCoords(drawitem_t *item)
#define INTERP_LATCH 1
#define INTERP_STRING 2
#define INTERP_FLAGS 3 // all bits combined
#define INTERP_FLAGMASK 0x3
static UINT64 GetItemId(void)
{
@@ -587,17 +587,15 @@ void LUA_HUD_DrawList(huddrawlist_h list)
// this is kinda cursed... we need to check every item
// but stop when the first-checked item is reached again
size_t stop = j;
while(true)
do
{
if (j == list->olditems_len)
{
// wrap around
j = 0;
if (j == stop) // i'm dumb
break;
continue;
}
drawitem_t *old = &list->olditems[j++];
if ((old->id & ~INTERP_FLAGS) == (item->id & ~INTERP_FLAGS)) // don't include flags in search
if ((old->id & ~INTERP_FLAGMASK) == (item->id & ~INTERP_FLAGMASK))
{
// gotcha!
olditem = old;
@@ -616,9 +614,8 @@ void LUA_HUD_DrawList(huddrawlist_h list)
}
break;
}
if (j == stop)
break;
}
while (j != stop);
}
else
{
@@ -653,7 +650,7 @@ void LUA_HUD_DrawList(huddrawlist_h list)
V_DrawPingNum(LERPS(x), LERPS(y), item->flags, item->num, item->colormap);
break;
case DI_DrawFill:
V_DrawFill(LERPS(x), LERPS(y), item->w, item->h, item->c);
V_DrawFill(LERPS(x), LERPS(y), LERP(w), LERP(h), item->c);
break;
case DI_DrawString:
switch(item->align)