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

This commit is contained in:
Alug committed 2024-05-23 20:29:22 +02:00
commit ed7fcae33b
3 files changed
+57 -11

No files matched your search

+39
View File
@@ -52,6 +52,45 @@ Returns the displayplayer's HUD color.
Returns true if colorization is enabled, false otherwise.
## v.interpolate(true)
Enables HUD interpolation. Each call to a drawing function will have its coordinates interpolated
by assigning an unique ID to every call.
For example, three successive calls to `v.draw` will each have their own ID and interpolation offsets.
Pass `true` to enable interpolation, `false` to disable.
Alternatively, pass a number to enable interpolation with the specified tag.
Tags allow HUD items drawn by the same call to a drawing function to be differentiated.
Valid tags range from 0-255.
For example, when iterating players, use a unique tag for each player to avoid artifacting:
```lua
for p in players.iterate do
-- enable interpolation, using player numbers as the tag
-- every draw will have different interp offsets per player
v.interpolate(#p)
-- doesn't matter for unconditional draws like this one...
v.draw(...)
-- but it does matter if there's a condition!
-- without tags, this patch would warp between players
-- whenever their `someVar` changes
if p.someVar then v.draw(...) end
end
-- don't want interpolation anymore? then disable it
v.interpolate(false)
```
NOTE: The default tag for `true` is 0.
## v.interpString(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.
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
Same fields as in SRB2 2.2
+5 -5
View File
@@ -42,11 +42,11 @@ 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;
extern boolean hud_interpolate; // interpolation enabled
extern UINT8 hud_interptag; // current tag
extern UINT32 hud_interpcounter; // number of HUD hooks ran
extern boolean hud_interpstring; // string mode
extern boolean hud_interplatch; // string mode was toggled
boolean LUA_HudEnabled(enum hud option);
+13 -6
View File
@@ -318,6 +318,7 @@ static void CalcFillCoords(drawitem_t *item)
#define INTERP_LATCH 1
#define INTERP_STRING 2
#define INTERP_FLAGS 3 // all bits combined
static UINT64 GetItemId(void)
{
@@ -325,7 +326,7 @@ static UINT64 GetItemId(void)
return 0;
// leave bits 0 and 1 free for the string mode
UINT64 id = ((UINT64)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2);
UINT64 id = ((uintptr_t)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2);
if (hud_interplatch)
{
@@ -580,7 +581,8 @@ void LUA_HUD_DrawList(huddrawlist_h list)
drawitem_t *olditem = NULL;
const char *itemstr = &list->strbuf[item->stroffset];
if (item->id) {
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
@@ -595,16 +597,19 @@ void LUA_HUD_DrawList(huddrawlist_h list)
break;
}
drawitem_t *old = &list->olditems[j++];
if ((old->id & ~3) == (item->id & ~3))
if ((old->id & ~INTERP_FLAGS) == (item->id & ~INTERP_FLAGS)) // don't include flags in search
{
// gotcha!
olditem = old;
if (item->id & INTERP_LATCH) {
if (item->id & INTERP_LATCH)
{
lerpx = FixedMul(frac, item->x - olditem->x);
lerpy = FixedMul(frac, item->y - olditem->y);
latchitem = item;
oldlatchitem = olditem;
} else if (!(item->id & INTERP_STRING)) {
}
else if (!(item->id & INTERP_STRING))
{
lerpx = FixedMul(frac, item->x - olditem->x);
lerpy = FixedMul(frac, item->y - olditem->y);
latchitem = NULL;
@@ -614,7 +619,9 @@ void LUA_HUD_DrawList(huddrawlist_h list)
if (j == stop)
break;
}
} else {
}
else
{
lerpx = lerpy = 0;
latchitem = NULL;
}