Get rotated sprites with v.getSprite(2)Patch

NOTE: since rotated sprites are offset upward by 4px from non-rotated
sprites, these functions will now return a third boolean (true) if a
rotated sprite was returned, so that scripters can offset accordingly.
This commit is contained in:
fickleheart 2020-02-10 01:00:37 -06:00
parent 1d2f6c9581
commit 76b397bece
1 changed files with 38 additions and 2 deletions

View File

@ -424,7 +424,7 @@ static int libd_cachePatch(lua_State *L)
return 1;
}
// v.getSpritePatch(sprite, [frame, [angle]])
// v.getSpritePatch(sprite, [frame, [angle, [rollangle]]])
static int libd_getSpritePatch(lua_State *L)
{
UINT32 i; // sprite prefix
@ -475,13 +475,31 @@ static int libd_getSpritePatch(lua_State *L)
if (angle >= ((sprframe->rotate & SRF_3DGE) ? 16 : 8)) // out of range?
return 0;
#ifdef ROTSPRITE
if (lua_isnumber(L, 4))
{
// rotsprite?????
angle_t rollangle = luaL_checkangle(L, 4);
INT32 rot = R_GetRollAngle(rollangle);
if (rot) {
if (!(sprframe->rotsprite.cached & (1<<angle)))
R_CacheRotSprite(i, frame, NULL, sprframe, angle, sprframe->flip & (1<<angle));
LUA_PushUserdata(L, sprframe->rotsprite.patch[angle][rot], META_PATCH);
lua_pushboolean(L, false);
lua_pushboolean(L, true);
return 3;
}
}
#endif
// push both the patch and it's "flip" value
LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_PATCH), META_PATCH);
lua_pushboolean(L, (sprframe->flip & (1<<angle)) != 0);
return 2;
}
// v.getSprite2Patch(skin, sprite, [super?,] [frame, [angle]])
// v.getSprite2Patch(skin, sprite, [super?,] [frame, [angle, [rollangle]]])
static int libd_getSprite2Patch(lua_State *L)
{
INT32 i; // skin number
@ -570,6 +588,24 @@ static int libd_getSprite2Patch(lua_State *L)
if (angle >= ((sprframe->rotate & SRF_3DGE) ? 16 : 8)) // out of range?
return 0;
#ifdef ROTSPRITE
if (lua_isnumber(L, 4))
{
// rotsprite?????
angle_t rollangle = luaL_checkangle(L, 4);
INT32 rot = R_GetRollAngle(rollangle);
if (rot) {
if (!(sprframe->rotsprite.cached & (1<<angle)))
R_CacheRotSprite(SPR_PLAY, frame, &skins[i].sprinfo[j], sprframe, angle, sprframe->flip & (1<<angle));
LUA_PushUserdata(L, sprframe->rotsprite.patch[angle][rot], META_PATCH);
lua_pushboolean(L, false);
lua_pushboolean(L, true);
return 3;
}
}
#endif
// push both the patch and it's "flip" value
LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_PATCH), META_PATCH);
lua_pushboolean(L, (sprframe->flip & (1<<angle)) != 0);