From ce1422a70bfba16ae5e8555e572ea70bd50182b4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 30 Apr 2017 22:53:05 +0100 Subject: [PATCH 1/6] Starting work for v.getSpritePatch and v.getSprite2Patch, dunno if these work yet mind --- src/lua_hudlib.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 5b3cd46ce..128a54dc8 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -12,6 +12,7 @@ #include "doomdef.h" #ifdef HAVE_BLUA +#include "fastcmp.h" #include "r_defs.h" #include "r_local.h" #include "st_stuff.h" // hudinfo[] @@ -343,6 +344,122 @@ static int libd_cachePatch(lua_State *L) return 1; } +static int libd_getSpritePatch(lua_State *L) +{ + UINT32 i; // sprite prefix + UINT32 frame = 0; // 'A' + UINT8 angle = 0; + spritedef_t *sprdef; + spriteframe_t *sprframe; + HUDONLY + + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK + { + i = lua_tonumber(L, 1); + if (i >= NUMSPRITES) + return 0; + } + else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK" + { + const char *name = lua_tostring(L, 1); + for (i = 0; i < NUMSPRITES; i++) + if (fastcmp(name, sprnames[i])) + break; + if (i >= NUMSPRITES) + return 0; + } + else + return 0; + + if (i == SPR_PLAY) // Use getSprite2Patch instead! + return 0; + + sprdef = &sprites[i]; + + // set frame number + frame = (luaL_optinteger(L, 2, 0); + frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case + if (frame >= sprdef->numframes) + return 0; + // set angle number + sprframe = sprdef->spriteframes[frame]; + angle = luaL_optinteger(L, 3, 0); + if (angle >= 8) + return 0; + + // push both the patch and it's "flip" value + LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH); + lua_pushboolean(L, (sprframe->flip & (1<= MAXSKINS) + return luaL_error(L, "skin number %d out of range (0 - %d)", i, MAXSKINS-1); + if (i >= numskins) + return 0; + } + else // find skin by name + { + const char *name = luaL_checkstring(L, 1); + for (i = 0; i < numskins; i++) + if (fastcmp(skins[i].name, field)) + break; + if (i >= numskins) + return 0; + } + + lua_remove(L, 1); // remove skin now + + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR2_STND + { + j = lua_tonumber(L, 1); + if (j >= free_spr2) + return 0; + } + else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "STND" + { + const char *name = lua_tostring(L, 1); + for (j = 0; j < free_spr2; j++) + if (fastcmp(name, sprnames[j])) + break; + if (j >= free_spr2) + return 0; + } + else + return 0; + + sprdef = &skins[i].sprites[j]; + + // set frame number + frame = (luaL_optinteger(L, 2, 0); + frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case + if (frame >= sprdef->numframes) + return 0; + // set angle number + sprframe = sprdef->spriteframes[frame]; + angle = luaL_optinteger(L, 3, 0); + if (angle >= 8) + return 0; + + // push both the patch and it's "flip" value + LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH); + lua_pushboolean(L, (sprframe->flip & (1< Date: Sat, 13 May 2017 21:28:44 +0100 Subject: [PATCH 2/6] Fix compiler errors --- src/lua_hudlib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 128a54dc8..9fcfcdd2e 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -377,12 +377,12 @@ static int libd_getSpritePatch(lua_State *L) sprdef = &sprites[i]; // set frame number - frame = (luaL_optinteger(L, 2, 0); + frame = luaL_optinteger(L, 2, 0); frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case if (frame >= sprdef->numframes) return 0; // set angle number - sprframe = sprdef->spriteframes[frame]; + sprframe = &sprdef->spriteframes[frame]; angle = luaL_optinteger(L, 3, 0); if (angle >= 8) return 0; @@ -395,7 +395,8 @@ static int libd_getSpritePatch(lua_State *L) static int libd_getSprite2Patch(lua_State *L) { - UINT32 i, j; // skin number, sprite2 prefix + INT32 i; // skin number + UINT32 j; // sprite2 prefix UINT32 frame = 0; // 'A' UINT8 angle = 0; spritedef_t *sprdef; @@ -406,7 +407,7 @@ static int libd_getSprite2Patch(lua_State *L) if (lua_isnumber(L, 1)) // find skin by number { i = lua_tonumber(L, 1); - if (i >= MAXSKINS) + if (i < 0 || i >= MAXSKINS) return luaL_error(L, "skin number %d out of range (0 - %d)", i, MAXSKINS-1); if (i >= numskins) return 0; @@ -415,7 +416,7 @@ static int libd_getSprite2Patch(lua_State *L) { const char *name = luaL_checkstring(L, 1); for (i = 0; i < numskins; i++) - if (fastcmp(skins[i].name, field)) + if (fastcmp(skins[i].name, name)) break; if (i >= numskins) return 0; @@ -444,12 +445,12 @@ static int libd_getSprite2Patch(lua_State *L) sprdef = &skins[i].sprites[j]; // set frame number - frame = (luaL_optinteger(L, 2, 0); + frame = luaL_optinteger(L, 2, 0); frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case if (frame >= sprdef->numframes) return 0; // set angle number - sprframe = sprdef->spriteframes[frame]; + sprframe = &sprdef->spriteframes[frame]; angle = luaL_optinteger(L, 3, 0); if (angle >= 8) return 0; From d91471b053852b6b67ef6f67a55797d39b477468 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 May 2017 21:43:04 +0100 Subject: [PATCH 3/6] check spr2names not sprnames, whoops --- src/lua_hudlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 9fcfcdd2e..4735d93d1 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -434,7 +434,7 @@ static int libd_getSprite2Patch(lua_State *L) { const char *name = lua_tostring(L, 1); for (j = 0; j < free_spr2; j++) - if (fastcmp(name, sprnames[j])) + if (fastcmp(name, spr2names[j])) break; if (j >= free_spr2) return 0; From e485ac3a7eb4155251349ae4d9049705e0a69297 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 9 Jul 2017 16:33:43 +0100 Subject: [PATCH 4/6] Add support for getting super sprites with v.getSprite2Patch You can either add FF_SPR2SUPER directly to the sprite2 arg if it's a number, or you can use the new (optional) boolean arg between sprite2 and frame, where as you'd expect false = normal and true = super. --- src/lua_hudlib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 4735d93d1..de923ab17 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -344,6 +344,7 @@ static int libd_cachePatch(lua_State *L) return 1; } +// v.getSpritePatch(sprite, [frame, [angle]]) static int libd_getSpritePatch(lua_State *L) { UINT32 i; // sprite prefix @@ -393,6 +394,7 @@ static int libd_getSpritePatch(lua_State *L) return 2; } +// v.getSprite2Patch(skin, sprite, [super?,] [frame, [angle]]) static int libd_getSprite2Patch(lua_State *L) { INT32 i; // skin number @@ -401,6 +403,7 @@ static int libd_getSprite2Patch(lua_State *L) UINT8 angle = 0; spritedef_t *sprdef; spriteframe_t *sprframe; + boolean super = false; // add FF_SPR2SUPER to sprite2 if true HUDONLY // get skin first! @@ -427,6 +430,11 @@ static int libd_getSprite2Patch(lua_State *L) if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR2_STND { j = lua_tonumber(L, 1); + if (j & FF_SPR2SUPER) // e.g. SPR2_STND|FF_SPR2SUPER + { + super = true; + j &= ~FF_SPR2SUPER; // remove flag so the next check doesn't fail + } if (j >= free_spr2) return 0; } @@ -436,12 +444,23 @@ static int libd_getSprite2Patch(lua_State *L) for (j = 0; j < free_spr2; j++) if (fastcmp(name, spr2names[j])) break; + // if you want super flags you'll have to use the optional boolean following this if (j >= free_spr2) return 0; } else return 0; + if (lua_isboolean(L, 2)) // optional boolean for superness + { + super = lua_toboolean(L, 2); // note: this can override FF_SPR2SUPER from sprite number + lua_remove(L, 2); // remove + } + // if it's not boolean then just assume it's the frame number + + if (super) + j |= FF_SPR2SUPER; + sprdef = &skins[i].sprites[j]; // set frame number From 4d740ff7836b01ece3e8a35d33f1e64a0ad5250e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 17 Jul 2017 21:31:33 +0100 Subject: [PATCH 5/6] Change getSpritePatch and getSpritePatch to accept angles 1-8 instead of 0-7, and just decrement the numbers internally 0 now just defaults to front angle (1, or 0 internally), in case people thought it was a separate angle from 1-8 for some reason --- src/lua_hudlib.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index de923ab17..0a6415697 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -384,8 +384,15 @@ static int libd_getSpritePatch(lua_State *L) return 0; // set angle number sprframe = &sprdef->spriteframes[frame]; - angle = luaL_optinteger(L, 3, 0); - if (angle >= 8) + angle = luaL_optinteger(L, 3, 1); + + // convert WAD editor angle numbers (1-8) to internal angle numbers (0-7) + // keep 0 the same since we'll make it default to angle 1 (which is internally 0) + // in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch + if (angle != 0) + angle--; + + if (angle >= 8) // out of range? return 0; // push both the patch and it's "flip" value @@ -470,8 +477,15 @@ static int libd_getSprite2Patch(lua_State *L) return 0; // set angle number sprframe = &sprdef->spriteframes[frame]; - angle = luaL_optinteger(L, 3, 0); - if (angle >= 8) + angle = luaL_optinteger(L, 3, 1); + + // convert WAD editor angle numbers (1-8) to internal angle numbers (0-7) + // keep 0 the same since we'll make it default to angle 1 (which is internally 0) + // in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch + if (angle != 0) + angle--; + + if (angle >= 8) // out of range? return 0; // push both the patch and it's "flip" value From 9703aa2864f6fe693697fa1e939cf1280a8de05a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 16 Aug 2017 21:00:18 +0100 Subject: [PATCH 6/6] Feed skin and sprite2 through P_GetSkinSprite2 to change sprite2 if necessary (if for instance the supplied sprite2 didn't actually exist) --- src/lua_hudlib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 3cdedc3d7..8175f1b9b 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -468,6 +468,8 @@ static int libd_getSprite2Patch(lua_State *L) if (super) j |= FF_SPR2SUPER; + j = P_GetSkinSprite2(&skins[i], j, NULL); // feed skin and current sprite2 through to change sprite2 used if necessary + sprdef = &skins[i].sprites[j]; // set frame number