HUD patch rotation

This commit is contained in:
Anonimus authored and Alug committed 2025-03-07 00:44:23 +01:00
1 parent 7401ddca43
commit 2dedbc25f6
4 files changed
+105

No files matched your search

+4
View File
@@ -28,6 +28,10 @@ exist.
Returns the values of the given HUD item's `xoffset`/`yoffset` cvars.
Available for any HUD item with offset cvars.
## patch = v.cachePatchRotated(name, rollangle)
Like v.cachePatch, it caches a new patch with the corresponding name. Unlike v.cachePatch, however,
a rollangle can be supplied to the function so that it returns a rotated patch instead.
## x, y, flags = v.getDrawInfo(item)
Returns the X, Y and flags where the given HUD item will be drawn for the current displayplayer.
+23
View File
@@ -397,6 +397,25 @@ FUNCINLINE static ATTRINLINE int libd_cachePatch(lua_State *L)
return 1;
}
#ifdef ROTSPRITE
static int libd_cachePatchRotated(lua_State *L)
{
HUDONLY
if ((cv_spriteroll.value))
{
angle_t rollangle = luaL_checkangle(L, 2);
INT32 rot = R_GetRollAngle(rollangle);
LUA_PushUserdata(L, W_CachePatchNameRotated(luaL_checkstring(L, 1), rot, PU_STATIC), META_PATCH);
}
else
{
LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_STATIC), META_PATCH);
}
return 1;
}
#endif
// this is structured like getSprite2Patch in vanilla 2.2
// v.getSpritePatch(skin, sprite, [frame, [angle, [rollangle]]])
static int libd_getSpritePatch(lua_State *L)
@@ -1175,6 +1194,10 @@ static int libd_interpLatch(lua_State *L)
static luaL_Reg lib_draw[] = {
{"patchExists", libd_patchExists},
{"cachePatch", libd_cachePatch},
#ifdef ROTSPRITE
// Is this ifdef nonsense? Yes.
{"cachePatchRotated", libd_cachePatchRotated},
#endif
{"draw", libd_draw},
{"drawScaled", libd_drawScaled},
{"drawStretched", libd_drawStretched},
+70
View File
@@ -71,6 +71,10 @@
#include "hardware/hw_glob.h"
#endif
#ifdef ROTSPRITE
#include "r_patch.h" // RotatedPatch_Create
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -826,6 +830,11 @@ UINT16 W_InitFile(const char *filename, boolean local)
wadfile->hwrcache = M_AATreeAlloc(AATREE_ZUSER);
#endif
#ifdef ROTSPRITE
// allocates rotsprite structures and store them in a tree
wadfile->rotcache = M_AATreeAlloc(AATREE_ZUSER);
#endif
//
// add the wadfile
//
@@ -1789,6 +1798,24 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag)
#endif // HWRENDER
#ifdef ROTSPRITE
// Caches a rotsprite for patch rotation.
void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum)
{
aatree_t *rotcache = wadfiles[wadnum]->rotcache;
rotsprite_t *rspr;
if (!(rspr = M_AATreeGet(rotcache, lumpnum)))
{
rspr = RotatedPatch_Create(ROTANGLES);
M_AATreeSet(rotcache, lumpnum, rspr);
}
return (void *)rspr;
}
#endif // ROTSPRITE
void W_UnlockCachedPatch(void *patch)
{
if (!patch)
@@ -1817,6 +1844,49 @@ void *W_CachePatchName(const char *name, INT32 tag)
return W_CachePatchNum(num, tag);
}
#ifdef ROTSPRITE
// Caches a patch, and if needed, rotates said patch.
void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
{
lumpnum_t num;
patch_t *ptr;
rotsprite_t *rspr;
INT32 idx = rotationangle;
const char *finalname = name;
num = W_CheckNumForName(finalname);
// No rotation? No need to do any of this nonsense.
if (rotationangle < 1 || rotationangle >= ROTANGLES)
return W_CachePatchNum(num, tag);
rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num));
if (rspr->patches[idx] == NULL)
{
INT32 xpivot = 0, ypivot = 0;
if (num == LUMPERROR)
ptr = (patch_t *)(W_CacheLumpNum(W_GetNumForName("MISSING"), PU_STATIC));
ptr = (patch_t *)(W_CacheLumpNum(num, PU_STATIC));
// >y pivot centered
// >x pivot not centered
// Why?
xpivot = ptr->width / 2;
ypivot = ptr->height / 2;
RotatedPatch_DoRotation(rspr, ptr, rotationangle, xpivot, ypivot, false);
// free image data
Z_Free(ptr);
}
return rspr->patches[idx];
}
#endif
#ifndef NOMD5
/**
+8
View File
@@ -130,6 +130,9 @@ typedef struct wadfile_s
lumpcache_t *lumpcache;
#ifdef HWRENDER
aatree_t *hwrcache; // patches are cached in renderer's native format
#endif
#ifdef ROTSPRITE
aatree_t *rotcache; // Cache rotsprites for rotating patches.
#endif
UINT16 numlumps; // this wad's number of resources
FILE *handle;
@@ -221,6 +224,11 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag); // return a patch_t
#define W_CachePatchNum(lumpnum, tag) W_CacheLumpNum(lumpnum, tag)
#endif
#ifdef ROTSPRITE
void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum); // Get patch-based rotsprites from the cache.
void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag);
#endif
void W_UnlockCachedPatch(void *patch);
void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5);