From 9d864729db4499808caacac82e88dac2c0ffba3d Mon Sep 17 00:00:00 2001 From: NepDisk Date: Mon, 2 Jun 2025 11:23:51 -0400 Subject: [PATCH] Port v.cachePatch second parameter for rotation from Classic https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2662 --- src/hardware/hw_draw.c | 3 ++- src/lua_hudlib.c | 14 ++++++++++++++ src/r_patchrotation.c | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 9475f6062..af06449a6 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -541,8 +541,9 @@ void HWR_DrawPic(INT32 x, INT32 y, lumpnum_t lumpnum) // -------------------------------------------------------------------------- // Fills a box of pixels using a flat texture as a pattern +// Fixed to properly align like the other draw functions -luigi budd // -------------------------------------------------------------------------- -void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum) +void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum) { const size_t len = W_LumpLength(flatlumpnum); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 24f833d25..c71f7f629 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -357,6 +357,20 @@ static int libd_cachePatch(lua_State *L) } else patch = W_CachePatchLongName(name, PU_PATCH); + +#ifdef ROTSPRITE + if (lua_isnumber(L, 2)) + { + angle_t rollangle = luaL_checkangle(L, 2); + INT32 rot = R_GetRollAngle(rollangle); + if (rot) { + patch_t *rotpatch = Patch_GetRotated(patch, rot, false); + LUA_PushUserdata(L, rotpatch, META_PATCH); + return 1; + } + } +#endif + LUA_PushUserdata(L, patch, META_PATCH); return 1; } diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c index 7b88d792b..1c933db3d 100644 --- a/src/r_patchrotation.c +++ b/src/r_patchrotation.c @@ -111,12 +111,26 @@ INT32 R_GetRollAngle(angle_t rollangle) patch_t *Patch_GetRotated(patch_t *patch, INT32 angle, boolean flip) { rotsprite_t *rotsprite = patch->rotated; - if (rotsprite == NULL || angle < 1 || angle >= ROTANGLES) + if (angle < 1 || angle >= ROTANGLES) return NULL; + if (rotsprite == NULL) + { + rotsprite = RotatedPatch_Create(ROTANGLES); + patch->rotated = rotsprite; + } + if (flip) angle += rotsprite->angles; + if (rotsprite->patches[angle] == NULL) + { + INT32 xpivot = 0, ypivot = 0; + xpivot = patch->leftoffset; + ypivot = patch->topoffset; + RotatedPatch_DoRotation(rotsprite, patch, angle, xpivot, ypivot, flip); + } + return rotsprite->patches[angle]; }