From d5beae97382027750992d6a18615cab49b9020f0 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 18:08:08 +0100 Subject: [PATCH 01/15] Begin work on adding access to polyobjects in Lua: * create new file lua_polyobjlib.c * made a stub LUA_PolyObjLib function * added META_POLYOBJ to lua_libs.h * updated makefile, CMake and MSVC project files for lua_polyobjlib.c --- src/CMakeLists.txt | 1 + src/blua/Makefile.cfg | 1 + src/lua_libs.h | 3 +++ src/lua_polyobjlib.c | 22 ++++++++++++++++++++++ src/lua_script.c | 1 + src/sdl/Srb2SDL-vc10.vcxproj | 1 + src/sdl/Srb2SDL-vc10.vcxproj.filters | 3 +++ 7 files changed, 32 insertions(+) create mode 100644 src/lua_polyobjlib.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e3da126b..0eb13c690 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -261,6 +261,7 @@ set(SRB2_LUA_SOURCES lua_mathlib.c lua_mobjlib.c lua_playerlib.c + lua_polyobjlib.c lua_script.c lua_skinlib.c lua_thinkerlib.c diff --git a/src/blua/Makefile.cfg b/src/blua/Makefile.cfg index 12ea064b4..eae95ba3a 100644 --- a/src/blua/Makefile.cfg +++ b/src/blua/Makefile.cfg @@ -47,5 +47,6 @@ OBJS:=$(OBJS) \ $(OBJDIR)/lua_skinlib.o \ $(OBJDIR)/lua_thinkerlib.o \ $(OBJDIR)/lua_maplib.o \ + $(OBJDIR)/lua_polyobjlib.o \ $(OBJDIR)/lua_blockmaplib.o \ $(OBJDIR)/lua_hudlib.o diff --git a/src/lua_libs.h b/src/lua_libs.h index f987c79fd..b25e18a47 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -50,6 +50,8 @@ extern lua_State *gL; #define META_VECTOR3 "VECTOR3_T" #define META_MAPHEADER "MAPHEADER_T*" +#define META_POLYOBJ "POLYOBJ_T*" + #define META_CVAR "CONSVAR_T*" #define META_SECTORLINES "SECTOR_T*LINES" @@ -88,5 +90,6 @@ int LUA_PlayerLib(lua_State *L); int LUA_SkinLib(lua_State *L); int LUA_ThinkerLib(lua_State *L); int LUA_MapLib(lua_State *L); +int LUA_PolyObjLib(lua_State *L); int LUA_BlockmapLib(lua_State *L); int LUA_HudLib(lua_State *L); diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c new file mode 100644 index 000000000..682288258 --- /dev/null +++ b/src/lua_polyobjlib.c @@ -0,0 +1,22 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020 by Iestyn "Monster Iestyn" Jealous. +// Copyright (C) 2016-2020 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file lua_polyobjlib.c +/// \brief polyobject library for Lua scripting + +#include "doomdef.h" +#include "p_local.h" +#include "p_polyobj.h" +#include "lua_script.h" +#include "lua_libs.h" + +int LUA_PolyObjLib(lua_State *L) +{ + return 0; +} diff --git a/src/lua_script.c b/src/lua_script.c index 0260f018a..9562c89d2 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -50,6 +50,7 @@ static lua_CFunction liblist[] = { LUA_SkinLib, // skin_t, skins[] LUA_ThinkerLib, // thinker_t LUA_MapLib, // line_t, side_t, sector_t, subsector_t + LUA_PolyObjLib, // polyobj_t LUA_BlockmapLib, // blockmap stuff LUA_HudLib, // HUD stuff NULL diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj index c6cef56de..43aa003b9 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj +++ b/src/sdl/Srb2SDL-vc10.vcxproj @@ -400,6 +400,7 @@ + diff --git a/src/sdl/Srb2SDL-vc10.vcxproj.filters b/src/sdl/Srb2SDL-vc10.vcxproj.filters index 04a1b5fa5..592b9f80c 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj.filters +++ b/src/sdl/Srb2SDL-vc10.vcxproj.filters @@ -720,6 +720,9 @@ LUA + + LUA + LUA From 05fe86ffdcbf0e33d72be1366645c00e0b2b33ad Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 18:29:10 +0100 Subject: [PATCH 02/15] * started functions for accessing/editing META_POLYOBJ (bare minimum atm) * added the "PolyObjects" array as a global var, with index and len functions, as well as its own iterate function --- src/lua_polyobjlib.c | 108 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 682288258..6778b4240 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -16,7 +16,113 @@ #include "lua_script.h" #include "lua_libs.h" -int LUA_PolyObjLib(lua_State *L) +enum polyobj_e { + polyobj_valid = 0, +}; +static const char *const polyobj_opt[] = { + "valid", + NULL}; + +static int polyobj_get(lua_State *L) { + polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + enum polyobj_e field = luaL_checkoption(L, 2, NULL, polyobj_opt); + + if (!polyobj) { + if (field == polyobj_valid) { + lua_pushboolean(L, false); + return 1; + } + return LUA_ErrInvalid(L, "polyobj_t"); + } + + switch (field) + { + case polyobj_valid: + lua_pushboolean(L, true); + break; + } + return 1; +}; + +static int polyobj_set(lua_State *L) +{ + return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary +} + +static int lib_iteratePolyObjects(lua_State *L) +{ + INT32 i = -1; + if (lua_gettop(L) < 2) + { + //return luaL_error(L, "Don't call PolyObjects.iterate() directly, use it as 'for polyobj in PolyObjects.iterate do end'."); + lua_pushcfunction(L, lib_iteratePolyObjects); + return 1; + } + lua_settop(L, 2); + lua_remove(L, 1); // state is unused. + if (!lua_isnil(L, 1)) + i = (INT32)(*((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)) - PolyObjects); + for (i++; i < numPolyObjects; i++) + { + LUA_PushUserdata(L, &PolyObjects[i], META_POLYOBJ); + return 1; + } + return 0; +} + +static int lib_getPolyObject(lua_State *L) +{ + const char *field; + INT32 i; + + // find PolyObject by number + if (lua_type(L, 2) == LUA_TNUMBER) + { + i = luaL_checkinteger(L, 2); + if (i < 0 || i >= numPolyObjects) + return luaL_error(L, "PolyObjects[] index %d out of range (0 - %d)", i, numPolyObjects-1); + LUA_PushUserdata(L, &PolyObjects[i], META_POLYOBJ); + return 1; + } + + field = luaL_checkstring(L, 2); + // special function iterate + if (fastcmp(field,"iterate")) + { + lua_pushcfunction(L, lib_iteratePolyObjects); + return 1; + } + return 0; +} + +static int lib_numPolyObjects(lua_State *L) +{ + lua_pushinteger(L, numPolyObjects); + return 1; +} + +int LUA_PolyObjLib(lua_State *L) +{ + luaL_newmetatable(L, META_POLYOBJ); + lua_pushcfunction(L, polyobj_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, polyobj_set); + lua_setfield(L, -2, "__newindex"); + + //lua_pushcfunction(L, polyobj_num); + //lua_setfield(L, -2, "__len"); + lua_pop(L,1); + + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getPolyObject); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_numPolyObjects); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_setglobal(L, "PolyObjects"); return 0; } From 0bc7eb32e9df89719ecc5004d9b060ded31b663c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 18:55:16 +0100 Subject: [PATCH 03/15] make sure to include fastcmp.h, whoops --- src/lua_polyobjlib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 6778b4240..9adaf1270 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -11,6 +11,7 @@ /// \brief polyobject library for Lua scripting #include "doomdef.h" +#include "fastcmp.h" #include "p_local.h" #include "p_polyobj.h" #include "lua_script.h" From 60b49b5ecd9a8aa5c41eab65914bfba45bee0193 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 18:56:00 +0100 Subject: [PATCH 04/15] Fix STJr copyright years, this file was obviously only created today, not 4 years ago! --- src/lua_polyobjlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 9adaf1270..2fef43e76 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -1,7 +1,7 @@ // SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2020 by Iestyn "Monster Iestyn" Jealous. -// Copyright (C) 2016-2020 by Sonic Team Junior. +// Copyright (C) 2020 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. From 33c96ab1aa1f84750dd0abaaf6082535584a5a80 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 21:42:51 +0100 Subject: [PATCH 05/15] * added access to id, parent, angle, damage, thrust, flags in polyobj_t * #polyobj now returns the index id for the polyobj in PolyObjects * Polyobj_GetForNum is implemented in Lua as PolyObjects.GetForNum() --- src/lua_polyobjlib.c | 62 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 2fef43e76..ab1467265 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -19,9 +19,21 @@ enum polyobj_e { polyobj_valid = 0, + polyobj_id, + polyobj_parent, + polyobj_angle, + polyobj_damage, + polyobj_thrust, + polyobj_flags }; static const char *const polyobj_opt[] = { "valid", + "id", + "parent", + "angle", + "damage", + "thrust", + "flags", NULL}; static int polyobj_get(lua_State *L) @@ -42,15 +54,42 @@ static int polyobj_get(lua_State *L) case polyobj_valid: lua_pushboolean(L, true); break; + case polyobj_id: + lua_pushinteger(L, polyobj->id); + break; + case polyobj_parent: + lua_pushinteger(L, polyobj->parent); + break; + case polyobj_angle: + lua_pushangle(L, polyobj->angle); + break; + case polyobj_damage: + lua_pushinteger(L, polyobj->damage); + break; + case polyobj_thrust: + lua_pushfixed(L, polyobj->thrust); + break; + case polyobj_flags: + lua_pushinteger(L, polyobj->flags); + break; } return 1; -}; +} static int polyobj_set(lua_State *L) { return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary } +static int polyobj_num(lua_State *L) +{ + polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + if (!polyobj) + return luaL_error(L, "accessed polyobj_t doesn't exist anymore."); + lua_pushinteger(L, polyobj-PolyObjects); + return 1; +} + static int lib_iteratePolyObjects(lua_State *L) { INT32 i = -1; @@ -72,6 +111,17 @@ static int lib_iteratePolyObjects(lua_State *L) return 0; } +static int lib_PolyObject_getfornum(lua_State *L) +{ + INT32 id = (INT32)luaL_checkinteger(L, 1); + + if (!numPolyObjects) + return 0; // if there's no PolyObjects then bail out here + + LUA_PushUserdata(L, Polyobj_GetForNum(id), META_POLYOBJ); + return 1; +} + static int lib_getPolyObject(lua_State *L) { const char *field; @@ -94,6 +144,12 @@ static int lib_getPolyObject(lua_State *L) lua_pushcfunction(L, lib_iteratePolyObjects); return 1; } + // find PolyObject by ID + else if (fastcmp(field,"GetForNum")) // name could probably be better + { + lua_pushcfunction(L, lib_PolyObject_getfornum); + return 1; + } return 0; } @@ -112,8 +168,8 @@ int LUA_PolyObjLib(lua_State *L) lua_pushcfunction(L, polyobj_set); lua_setfield(L, -2, "__newindex"); - //lua_pushcfunction(L, polyobj_num); - //lua_setfield(L, -2, "__len"); + lua_pushcfunction(L, polyobj_num); + lua_setfield(L, -2, "__len"); lua_pop(L,1); lua_newuserdata(L, 0); From 5fc58de94f77963c6905f26c3b096dd186192817 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 8 Sep 2020 22:10:11 +0100 Subject: [PATCH 06/15] * added access to translucency and triggertag in polyobj_t * added POF_ flags to INT_CONST in dehacked.c --- src/dehacked.c | 19 +++++++++++++++++++ src/lua_polyobjlib.c | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/dehacked.c b/src/dehacked.c index 4c7ffaa96..5be7dbbc9 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9906,6 +9906,25 @@ struct { {"FF_COLORMAPONLY",FF_COLORMAPONLY}, ///< Only copy the colormap, not the lightlevel {"FF_GOOWATER",FF_GOOWATER}, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. + // PolyObject flags + {"POF_CLIPLINES",POF_CLIPLINES}, ///< Test against lines for collision + {"POF_CLIPPLANES",POF_CLIPPLANES}, ///< Test against tops and bottoms for collision + {"POF_SOLID",POF_SOLID}, ///< Clips things. + {"POF_TESTHEIGHT",POF_TESTHEIGHT}, ///< Test line collision with heights + {"POF_RENDERSIDES",POF_RENDERSIDES}, ///< Renders the sides. + {"POF_RENDERTOP",POF_RENDERTOP}, ///< Renders the top. + {"POF_RENDERBOTTOM",POF_RENDERBOTTOM}, ///< Renders the bottom. + {"POF_RENDERPLANES",POF_RENDERPLANES}, ///< Renders top and bottom. + {"POF_RENDERALL",POF_RENDERALL}, ///< Renders everything. + {"POF_INVERT",POF_INVERT}, ///< Inverts collision (like a cage). + {"POF_INVERTPLANES",POF_INVERTPLANES}, ///< Render inside planes. + {"POF_INVERTPLANESONLY",POF_INVERTPLANESONLY}, ///< Only render inside planes. + {"POF_PUSHABLESTOP",POF_PUSHABLESTOP}, ///< Pushables will stop movement. + {"POF_LDEXEC",POF_LDEXEC}, ///< This PO triggers a linedef executor. + {"POF_ONESIDE",POF_ONESIDE}, ///< Only use the first side of the linedef. + {"POF_NOSPECIALS",POF_NOSPECIALS}, ///< Don't apply sector specials. + {"POF_SPLAT",POF_SPLAT}, ///< Use splat flat renderer (treat cyan pixels as invisible). + #ifdef HAVE_LUA_SEGS // Node flags {"NF_SUBSECTOR",NF_SUBSECTOR}, // Indicate a leaf. diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index ab1467265..85cb8fc69 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -24,7 +24,9 @@ enum polyobj_e { polyobj_angle, polyobj_damage, polyobj_thrust, - polyobj_flags + polyobj_flags, + polyobj_translucency, + polyobj_triggertag }; static const char *const polyobj_opt[] = { "valid", @@ -34,6 +36,8 @@ static const char *const polyobj_opt[] = { "damage", "thrust", "flags", + "translucency", + "triggertag", NULL}; static int polyobj_get(lua_State *L) @@ -72,6 +76,12 @@ static int polyobj_get(lua_State *L) case polyobj_flags: lua_pushinteger(L, polyobj->flags); break; + case polyobj_translucency: + lua_pushinteger(L, polyobj->translucency); + break; + case polyobj_triggertag: + lua_pushinteger(L, polyobj->triggertag); + break; } return 1; } From 625aeb1560ae60a55129be647e67ec00eff56d2e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 16:09:08 +0100 Subject: [PATCH 07/15] lua_script.c fixes: * make sure polyobj_t userdata is invalidated at level load * add support for syncing polyobj_t Lua variables in netgames --- src/lua_script.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lua_script.c b/src/lua_script.c index 9562c89d2..f94a88473 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -24,6 +24,7 @@ #include "p_saveg.h" #include "p_local.h" #include "p_slopes.h" // for P_SlopeById +#include "p_polyobj.h" // polyobj_t, PolyObjects #ifdef LUA_ALLOW_BYTECODE #include "d_netfil.h" // for LUA_DumpFile #endif @@ -775,6 +776,8 @@ void LUA_InvalidateLevel(void) LUA_InvalidateUserdata(&sides[i]); for (i = 0; i < numvertexes; i++) LUA_InvalidateUserdata(&vertexes[i]); + for (i = 0; i < (size_t)numPolyObjects; i++) + LUA_InvalidateUserdata(&PolyObjects[i]); #ifdef HAVE_LUA_SEGS for (i = 0; i < numsegs; i++) LUA_InvalidateUserdata(&segs[i]); @@ -833,6 +836,7 @@ enum ARCH_NODE, #endif ARCH_FFLOOR, + ARCH_POLYOBJ, ARCH_SLOPE, ARCH_MAPHEADER, ARCH_SKINCOLOR, @@ -859,6 +863,7 @@ static const struct { {META_NODE, ARCH_NODE}, #endif {META_FFLOOR, ARCH_FFLOOR}, + {META_POLYOBJ, ARCH_POLYOBJ}, {META_SLOPE, ARCH_SLOPE}, {META_MAPHEADER, ARCH_MAPHEADER}, {META_SKINCOLOR, ARCH_SKINCOLOR}, @@ -1127,6 +1132,17 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) } break; } + case ARCH_POLYOBJ: + { + polyobj_t *polyobj = *((polyobj_t **)lua_touserdata(gL, myindex)); + if (!polyobj) + WRITEUINT8(save_p, ARCH_NULL); + else { + WRITEUINT8(save_p, ARCH_POLYOBJ); + WRITEUINT16(save_p, polyobj-PolyObjects); + } + break; + } case ARCH_SLOPE: { pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); @@ -1382,6 +1398,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) LUA_PushUserdata(gL, rover, META_FFLOOR); break; } + case ARCH_POLYOBJ: + LUA_PushUserdata(gL, &PolyObjects[READUINT16(save_p)], META_POLYOBJ); + break; case ARCH_SLOPE: LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE); break; From e6136eb113fd4a231b989a8e15626d0fc16af92a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 16:56:48 +0100 Subject: [PATCH 08/15] lua_blockmaplib.c: added "polyobjs" option to searchBlockmap function also updated my copyright years in this file B) --- src/lua_blockmaplib.c | 56 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 5aae73284..1949d56bb 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -1,6 +1,6 @@ // SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- -// Copyright (C) 2016 by Iestyn "Monster Iestyn" Jealous. +// Copyright (C) 2016-2020 by Iestyn "Monster Iestyn" Jealous. // Copyright (C) 2016-2020 by Sonic Team Junior. // // This program is free software distributed under the @@ -13,6 +13,7 @@ #include "doomdef.h" #include "p_local.h" #include "r_main.h" // validcount +#include "p_polyobj.h" #include "lua_script.h" #include "lua_libs.h" //#include "lua_hud.h" // hud_running errors @@ -20,6 +21,7 @@ static const char *const search_opt[] = { "objects", "lines", + "polyobjs", NULL}; // a quickly-made function pointer typedef used by lib_searchBlockmap... @@ -167,6 +169,55 @@ static UINT8 lib_searchBlockmap_Lines(lua_State *L, INT32 x, INT32 y, mobj_t *th return 0; // Everything was checked. } +// Helper function for "polyobjs" search +static UINT8 lib_searchBlockmap_PolyObjs(lua_State *L, INT32 x, INT32 y, mobj_t *thing) +{ + INT32 offset; + polymaplink_t *plink; // haleyjd 02/22/06 + + if (x < 0 || y < 0 || x >= bmapwidth || y >= bmapheight) + return 0; + + offset = y*bmapwidth + x; + + // haleyjd 02/22/06: consider polyobject lines + plink = polyblocklinks[offset]; + + while (plink) + { + polyobj_t *po = plink->po; + + if (po->validcount != validcount) // if polyobj hasn't been checked + { + po->validcount = validcount; + + lua_pushvalue(L, 1); + LUA_PushUserdata(L, thing, META_MOBJ); + LUA_PushUserdata(L, po, META_POLYOBJ); + if (lua_pcall(gL, 2, 1, 0)) { + if (!blockfuncerror || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + blockfuncerror = true; + return 0; // *shrugs* + } + if (!lua_isnil(gL, -1)) + { // if nil, continue + if (lua_toboolean(gL, -1)) + return 2; // stop whole search + else + return 1; // stop block search + } + lua_pop(gL, 1); + if (P_MobjWasRemoved(thing)) + return 2; + } + plink = (polymaplink_t *)(plink->link.next); + } + + return 0; // Everything was checked. +} + // The searchBlockmap function // arguments: searchBlockmap(searchtype, function, mobj, [x1, x2, y1, y2]) // return value: @@ -195,6 +246,9 @@ static int lib_searchBlockmap(lua_State *L) case 1: // "lines" searchFunc = lib_searchBlockmap_Lines; break; + case 2: // "polyobjs" + searchFunc = lib_searchBlockmap_PolyObjs; + break; } // the mobj we are searching around, the "calling" mobj we could say From 89e989d6b12ebdab714a7e9323e6fb14062470bd Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 17:06:36 +0100 Subject: [PATCH 09/15] added "sector" as a Lua-exclusive shortcut to polyobj->lines[0]->backsector in polyobj_t --- src/lua_polyobjlib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 85cb8fc69..4b583be26 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -21,6 +21,7 @@ enum polyobj_e { polyobj_valid = 0, polyobj_id, polyobj_parent, + polyobj_sector, polyobj_angle, polyobj_damage, polyobj_thrust, @@ -32,6 +33,7 @@ static const char *const polyobj_opt[] = { "valid", "id", "parent", + "sector", "angle", "damage", "thrust", @@ -64,6 +66,9 @@ static int polyobj_get(lua_State *L) case polyobj_parent: lua_pushinteger(L, polyobj->parent); break; + case polyobj_sector: // shortcut that exists only in Lua! + LUA_PushUserdata(L, polyobj->lines[0]->backsector, META_SECTOR); + break; case polyobj_angle: lua_pushangle(L, polyobj->angle); break; From 5f9183370125fcefbd4d70aeac709d45aa8136d5 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 17:31:44 +0100 Subject: [PATCH 10/15] lua_maplib.c changes now that polyobj_t is supported: * added line.polyobj for line_t * added subsector.polyList iteration function, for iterating polyobjs in a subsector * added seg.polyseg for seg_t, in case we ever reenable support for segs/nodes --- src/lua_maplib.c | 59 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 216818d29..6c83a16c5 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -16,6 +16,7 @@ #include "p_setup.h" #include "z_zone.h" #include "p_slopes.h" +#include "p_polyobj.h" #include "r_main.h" #include "lua_script.h" @@ -67,6 +68,7 @@ enum subsector_e { subsector_sector, subsector_numlines, subsector_firstline, + subsector_polyList }; static const char *const subsector_opt[] = { @@ -74,6 +76,7 @@ static const char *const subsector_opt[] = { "sector", "numlines", "firstline", + "polyList", NULL}; enum line_e { @@ -97,6 +100,7 @@ enum line_e { line_backsector, line_firsttag, line_nexttag, + line_polyobj, line_text, line_callcount }; @@ -122,6 +126,7 @@ static const char *const line_opt[] = { "backsector", "firsttag", "nexttag", + "polyobj", "text", "callcount", NULL}; @@ -222,6 +227,7 @@ enum seg_e { seg_linedef, seg_frontsector, seg_backsector, + seg_polyseg }; static const char *const seg_opt[] = { @@ -235,6 +241,7 @@ static const char *const seg_opt[] = { "linedef", "frontsector", "backsector", + "polyseg", NULL}; enum node_e { @@ -324,9 +331,9 @@ static const char *const vector_opt[] = { static const char *const array_opt[] ={"iterate",NULL}; static const char *const valid_opt[] ={"valid",NULL}; -/////////////////////////////////// -// sector list iterate functions // -/////////////////////////////////// +///////////////////////////////////////////// +// sector/subsector list iterate functions // +///////////////////////////////////////////// // iterates through a sector's thinglist! static int lib_iterateSectorThinglist(lua_State *L) @@ -398,6 +405,41 @@ static int lib_iterateSectorFFloors(lua_State *L) return 0; } +// iterates through a subsector's polyList! (for polyobj_t) +static int lib_iterateSubSectorPolylist(lua_State *L) +{ + polyobj_t *state = NULL; + polyobj_t *po = NULL; + + INLEVEL + + if (lua_gettop(L) < 2) + return luaL_error(L, "Don't call subsector.polyList() directly, use it as 'for polyobj in subsector.polyList do end'."); + + if (!lua_isnil(L, 1)) + state = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + else + return 0; // no polylist to iterate through sorry! + + lua_settop(L, 2); + lua_remove(L, 1); // remove state now. + + if (!lua_isnil(L, 1)) + { + po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + po = (polyobj_t *)(po->link.next); + } + else + po = state; // state is used as the "start" of the polylist + + if (po) + { + LUA_PushUserdata(L, po, META_POLYOBJ); + return 1; + } + return 0; +} + static int sector_iterate(lua_State *L) { lua_pushvalue(L, lua_upvalueindex(1)); // iterator function, or the "generator" @@ -684,6 +726,11 @@ static int subsector_get(lua_State *L) case subsector_firstline: lua_pushinteger(L, subsector->firstline); return 1; + case subsector_polyList: // polyList + lua_pushcfunction(L, lib_iterateSubSectorPolylist); + LUA_PushUserdata(L, subsector->polyList, META_POLYOBJ); + lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateSubSectorPolylist and subsector->polyList as upvalues for the function + return 1; } return 0; } @@ -827,6 +874,9 @@ static int line_get(lua_State *L) case line_nexttag: lua_pushinteger(L, line->nexttag); return 1; + case line_polyobj: + LUA_PushUserdata(L, line->polyobj, META_POLYOBJ); + return 1; case line_text: lua_pushstring(L, line->text); return 1; @@ -1089,6 +1139,9 @@ static int seg_get(lua_State *L) case seg_backsector: LUA_PushUserdata(L, seg->backsector, META_SECTOR); return 1; + case seg_polyseg: + LUA_PushUserdata(L, seg->polyseg, META_POLYOBJ); + return 1; } return 0; } From f86dad29791013969b5c43f913c94cece3285d0f Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 18:09:32 +0100 Subject: [PATCH 11/15] Added new functions as variables of polyobj_t: * po.pointInside(po, x, y) as a wrapper for P_PointInsidePolyobj * po.mobjTouching(po, mo) as a wrapper for P_MobjTouchingPolyobj * po.mobjInside(po, mo) as a wrapper for P_MobjInsidePolyobj I can confirm that ":" syntax works with all the above, e.g. po:mobjInside(mo) --- src/lua_polyobjlib.c | 61 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 4b583be26..605780d2f 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -18,6 +18,7 @@ #include "lua_libs.h" enum polyobj_e { + // properties polyobj_valid = 0, polyobj_id, polyobj_parent, @@ -27,9 +28,14 @@ enum polyobj_e { polyobj_thrust, polyobj_flags, polyobj_translucency, - polyobj_triggertag + polyobj_triggertag, + // special functions + polyobj_pointInside, + polyobj_mobjTouching, + polyobj_mobjInside }; static const char *const polyobj_opt[] = { + // properties "valid", "id", "parent", @@ -40,8 +46,50 @@ static const char *const polyobj_opt[] = { "flags", "translucency", "triggertag", + // special functions + "pointInside", + "mobjTouching", + "mobjInside", NULL}; +static int lib_polyobj_PointInside(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + fixed_t x = luaL_checkfixed(L, 2); + fixed_t y = luaL_checkfixed(L, 3); + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + lua_pushboolean(L, P_PointInsidePolyobj(po, x, y)); + return 1; +} + +static int lib_polyobj_MobjTouching(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + if (!mo) + return LUA_ErrInvalid(L, "mobj_t"); + lua_pushboolean(L, P_MobjTouchingPolyobj(po, mo)); + return 1; +} + +static int lib_polyobj_MobjInside(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + if (!mo) + return LUA_ErrInvalid(L, "mobj_t"); + lua_pushboolean(L, P_MobjInsidePolyobj(po, mo)); + return 1; +} + static int polyobj_get(lua_State *L) { polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -57,6 +105,7 @@ static int polyobj_get(lua_State *L) switch (field) { + // properties case polyobj_valid: lua_pushboolean(L, true); break; @@ -87,6 +136,16 @@ static int polyobj_get(lua_State *L) case polyobj_triggertag: lua_pushinteger(L, polyobj->triggertag); break; + // special functions + case polyobj_pointInside: + lua_pushcfunction(L, lib_polyobj_PointInside); + break; + case polyobj_mobjTouching: + lua_pushcfunction(L, lib_polyobj_MobjTouching); + break; + case polyobj_mobjInside: + lua_pushcfunction(L, lib_polyobj_MobjInside); + break; } return 1; } From 4ce161f9c30b302188fc6f405e873c2cadfe3239 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 19:38:56 +0100 Subject: [PATCH 12/15] Added the functions Polyobj_moveXY and Polyobj_rotate to Lua as polyobj.moveXY and polyobj.rotate --- src/lua_polyobjlib.c | 55 ++++++++++++++++++++++++++++++++++++++++---- src/p_polyobj.c | 4 ++-- src/p_polyobj.h | 2 ++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 605780d2f..c43cac665 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -16,6 +16,10 @@ #include "p_polyobj.h" #include "lua_script.h" #include "lua_libs.h" +#include "lua_hud.h" // hud_running errors + +#define NOHUD if (hud_running)\ +return luaL_error(L, "HUD rendering code should not call this function!"); enum polyobj_e { // properties @@ -29,10 +33,13 @@ enum polyobj_e { polyobj_flags, polyobj_translucency, polyobj_triggertag, - // special functions + // special functions - utility polyobj_pointInside, polyobj_mobjTouching, - polyobj_mobjInside + polyobj_mobjInside, + // special functions - manipulation + polyobj_moveXY, + polyobj_rotate }; static const char *const polyobj_opt[] = { // properties @@ -46,12 +53,16 @@ static const char *const polyobj_opt[] = { "flags", "translucency", "triggertag", - // special functions + // special functions - utility "pointInside", "mobjTouching", "mobjInside", + // special functions - manipulation + "moveXY", + "rotate", NULL}; +// special functions - utility static int lib_polyobj_PointInside(lua_State *L) { polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -90,6 +101,35 @@ static int lib_polyobj_MobjInside(lua_State *L) return 1; } +// special functions - manipulation +static int lib_polyobj_moveXY(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + fixed_t x = luaL_checkfixed(L, 2); + fixed_t y = luaL_checkfixed(L, 3); + boolean checkmobjs = lua_opttrueboolean(L, 4); + NOHUD + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + lua_pushboolean(L, Polyobj_moveXY(po, x, y, checkmobjs)); + return 1; +} + +static int lib_polyobj_rotate(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + angle_t delta = luaL_checkangle(L, 2); + UINT8 turnthings = (UINT8)luaL_optinteger(L, 3, 0); // don't turn anything by default? (could change this if not desired) + boolean checkmobjs = lua_opttrueboolean(L, 4); + NOHUD + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + lua_pushboolean(L, Polyobj_rotate(po, delta, turnthings, checkmobjs)); + return 1; +} + static int polyobj_get(lua_State *L) { polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -136,7 +176,7 @@ static int polyobj_get(lua_State *L) case polyobj_triggertag: lua_pushinteger(L, polyobj->triggertag); break; - // special functions + // special functions - utility case polyobj_pointInside: lua_pushcfunction(L, lib_polyobj_PointInside); break; @@ -146,6 +186,13 @@ static int polyobj_get(lua_State *L) case polyobj_mobjInside: lua_pushcfunction(L, lib_polyobj_MobjInside); break; + // special functions - manipulation + case polyobj_moveXY: + lua_pushcfunction(L, lib_polyobj_moveXY); + break; + case polyobj_rotate: + lua_pushcfunction(L, lib_polyobj_rotate); + break; } return 1; } diff --git a/src/p_polyobj.c b/src/p_polyobj.c index b0a794ddf..63d062c22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -976,7 +976,7 @@ static INT32 Polyobj_clipThings(polyobj_t *po, line_t *line) // Moves a polyobject on the x-y plane. -static boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs) +boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs) { size_t i; vertex_t vec; @@ -1162,7 +1162,7 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, } // Rotates a polyobject around its start point. -static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs) +boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs) { size_t i; angle_t angle; diff --git a/src/p_polyobj.h b/src/p_polyobj.h index f24caca4e..8c2946965 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -336,6 +336,8 @@ typedef struct polyfadedata_s // Functions // +boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs); +boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs); polyobj_t *Polyobj_GetForNum(INT32 id); void Polyobj_InitLevel(void); void Polyobj_MoveOnLoad(polyobj_t *po, angle_t angle, fixed_t x, fixed_t y); From 78f799861870188c42058a5e0ead7ea6e1095a8e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 21:15:02 +0100 Subject: [PATCH 13/15] Added polyobj.vertices and polyobj.lines to Lua --- src/lua_libs.h | 2 + src/lua_polyobjlib.c | 154 +++++++++++++++++++++++++++++++++++++++++++ src/lua_script.c | 4 ++ 3 files changed, 160 insertions(+) diff --git a/src/lua_libs.h b/src/lua_libs.h index b25e18a47..03bd99cd2 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -60,6 +60,8 @@ extern lua_State *gL; #define META_LINESTRINGARGS "LINE_T*STRINGARGS" #define META_THINGARGS "MAPTHING_T*ARGS" #define META_THINGSTRINGARGS "MAPTHING_T*STRINGARGS" +#define META_POLYOBJVERTICES "POLYOBJ_T*VERTICES" +#define META_POLYOBJLINES "POLYOBJ_T*LINES" #ifdef HAVE_LUA_SEGS #define META_NODEBBOX "NODE_T*BBOX" #define META_NODECHILDREN "NODE_T*CHILDREN" diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index c43cac665..b0f22e74f 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -26,6 +26,8 @@ enum polyobj_e { polyobj_valid = 0, polyobj_id, polyobj_parent, + polyobj_vertices, + polyobj_lines, polyobj_sector, polyobj_angle, polyobj_damage, @@ -46,6 +48,8 @@ static const char *const polyobj_opt[] = { "valid", "id", "parent", + "vertices", + "lines", "sector", "angle", "damage", @@ -62,6 +66,126 @@ static const char *const polyobj_opt[] = { "rotate", NULL}; +static const char *const valid_opt[] ={"valid",NULL}; + +//////////////////////// +// polyobj.vertices[] // +//////////////////////// + +// polyobj.vertices, i -> polyobj.vertices[i] +// polyobj.vertices.valid, for validity checking +// +// see sectorlines_get in lua_maplib.c +// +static int polyobjvertices_get(lua_State *L) +{ + vertex_t ***polyverts = *((vertex_t ****)luaL_checkudata(L, 1, META_POLYOBJVERTICES)); + size_t i; + size_t numofverts = 0; + lua_settop(L, 2); + if (!lua_isnumber(L, 2)) + { + int field = luaL_checkoption(L, 2, NULL, valid_opt); + if (!polyverts || !(*polyverts)) + { + if (field == 0) { + lua_pushboolean(L, 0); + return 1; + } + return luaL_error(L, "accessed polyobj_t.vertices doesn't exist anymore."); + } else if (field == 0) { + lua_pushboolean(L, 1); + return 1; + } + } + + numofverts = (size_t)(*(size_t *)(((size_t)polyverts) - (offsetof(polyobj_t, vertices) - offsetof(polyobj_t, numVertices)))); + + if (!numofverts) + return luaL_error(L, "no vertices found!"); + + i = (size_t)lua_tointeger(L, 2); + if (i >= numofverts) + return 0; + LUA_PushUserdata(L, (*polyverts)[i], META_VERTEX); + return 1; +} + +// #(polyobj.vertices) -> polyobj.numVertices +static int polyobjvertices_num(lua_State *L) +{ + vertex_t ***polyverts = *((vertex_t ****)luaL_checkudata(L, 1, META_POLYOBJVERTICES)); + size_t numofverts = 0; + + if (!polyverts || !(*polyverts)) + return luaL_error(L, "accessed polyobj_t.vertices doesn't exist anymore."); + + numofverts = (size_t)(*(size_t *)(((size_t)polyverts) - (offsetof(polyobj_t, vertices) - offsetof(polyobj_t, numVertices)))); + lua_pushinteger(L, numofverts); + return 1; +} + +///////////////////// +// polyobj.lines[] // +///////////////////// + +// polyobj.lines, i -> polyobj.lines[i] +// polyobj.lines.valid, for validity checking +// +// see sectorlines_get in lua_maplib.c +// +static int polyobjlines_get(lua_State *L) +{ + line_t ***polylines = *((line_t ****)luaL_checkudata(L, 1, META_POLYOBJLINES)); + size_t i; + size_t numoflines = 0; + lua_settop(L, 2); + if (!lua_isnumber(L, 2)) + { + int field = luaL_checkoption(L, 2, NULL, valid_opt); + if (!polylines || !(*polylines)) + { + if (field == 0) { + lua_pushboolean(L, 0); + return 1; + } + return luaL_error(L, "accessed polyobj_t.lines doesn't exist anymore."); + } else if (field == 0) { + lua_pushboolean(L, 1); + return 1; + } + } + + numoflines = (size_t)(*(size_t *)(((size_t)polylines) - (offsetof(polyobj_t, lines) - offsetof(polyobj_t, numLines)))); + + if (!numoflines) + return luaL_error(L, "no lines found!"); + + i = (size_t)lua_tointeger(L, 2); + if (i >= numoflines) + return 0; + LUA_PushUserdata(L, (*polylines)[i], META_LINE); + return 1; +} + +// #(polyobj.lines) -> polyobj.numLines +static int polyobjlines_num(lua_State *L) +{ + line_t ***polylines = *((line_t ****)luaL_checkudata(L, 1, META_POLYOBJLINES)); + size_t numoflines = 0; + + if (!polylines || !(*polylines)) + return luaL_error(L, "accessed polyobj_t.lines doesn't exist anymore."); + + numoflines = (size_t)(*(size_t *)(((size_t)polylines) - (offsetof(polyobj_t, lines) - offsetof(polyobj_t, numLines)))); + lua_pushinteger(L, numoflines); + return 1; +} + +///////////////////////////////// +// polyobj_t function wrappers // +///////////////////////////////// + // special functions - utility static int lib_polyobj_PointInside(lua_State *L) { @@ -130,6 +254,10 @@ static int lib_polyobj_rotate(lua_State *L) return 1; } +/////////////// +// polyobj_t // +/////////////// + static int polyobj_get(lua_State *L) { polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -155,6 +283,12 @@ static int polyobj_get(lua_State *L) case polyobj_parent: lua_pushinteger(L, polyobj->parent); break; + case polyobj_vertices: // vertices + LUA_PushUserdata(L, &polyobj->vertices, META_POLYOBJVERTICES); // push the address of the "vertices" member in the struct, to allow our hacks to work + break; + case polyobj_lines: // lines + LUA_PushUserdata(L, &polyobj->lines, META_POLYOBJLINES); // push the address of the "lines" member in the struct, to allow our hacks to work + break; case polyobj_sector: // shortcut that exists only in Lua! LUA_PushUserdata(L, polyobj->lines[0]->backsector, META_SECTOR); break; @@ -211,6 +345,10 @@ static int polyobj_num(lua_State *L) return 1; } +/////////////////// +// PolyObjects[] // +/////////////////// + static int lib_iteratePolyObjects(lua_State *L) { INT32 i = -1; @@ -282,6 +420,22 @@ static int lib_numPolyObjects(lua_State *L) int LUA_PolyObjLib(lua_State *L) { + luaL_newmetatable(L, META_POLYOBJVERTICES); + lua_pushcfunction(L, polyobjvertices_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, polyobjvertices_num); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + + luaL_newmetatable(L, META_POLYOBJLINES); + lua_pushcfunction(L, polyobjlines_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, polyobjlines_num); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + luaL_newmetatable(L, META_POLYOBJ); lua_pushcfunction(L, polyobj_get); lua_setfield(L, -2, "__index"); diff --git a/src/lua_script.c b/src/lua_script.c index f94a88473..ae7f479f6 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -777,7 +777,11 @@ void LUA_InvalidateLevel(void) for (i = 0; i < numvertexes; i++) LUA_InvalidateUserdata(&vertexes[i]); for (i = 0; i < (size_t)numPolyObjects; i++) + { LUA_InvalidateUserdata(&PolyObjects[i]); + LUA_InvalidateUserdata(&PolyObjects[i].vertices); + LUA_InvalidateUserdata(&PolyObjects[i].lines); + } #ifdef HAVE_LUA_SEGS for (i = 0; i < numsegs; i++) LUA_InvalidateUserdata(&segs[i]); From 097986b1d9b1ec2247851d945f45e5b86427e756 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 21:24:07 +0100 Subject: [PATCH 14/15] added polyobj_t to userdataType list (also added slope_t, vector2_t and vector3_t since they were all missing from here) --- src/lua_baselib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 6b25e32ea..1b576eebb 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -170,8 +170,13 @@ static const struct { {META_SEG, "seg_t"}, {META_NODE, "node_t"}, #endif + {META_SLOPE, "slope_t"}, + {META_VECTOR2, "vector2_t"}, + {META_VECTOR3, "vector3_t"}, {META_MAPHEADER, "mapheader_t"}, + {META_POLYOBJ, "polyobj_t"}, + {META_CVAR, "consvar_t"}, {META_SECTORLINES, "sector_t.lines"}, From 0f2e063de018ab40502a438afcb52e791669a9f4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 13 Sep 2020 21:38:16 +0100 Subject: [PATCH 15/15] Added the ability to modify parent, flags, translucency in polyobj_t (attempting to edit polyobj.angle just gives you an error message saying to use polyobj:rotate() instead) --- src/lua_polyobjlib.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index b0f22e74f..c4dfa8ae4 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -333,7 +333,33 @@ static int polyobj_get(lua_State *L) static int polyobj_set(lua_State *L) { - return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary + polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + enum polyobj_e field = luaL_checkoption(L, 2, NULL, polyobj_opt); + + if (!polyobj) + return LUA_ErrInvalid(L, "polyobj_t"); + + if (hud_running) + return luaL_error(L, "Do not alter polyobj_t in HUD rendering code!"); + + switch (field) + { + default: + return luaL_error(L, LUA_QL("polyobj_t") " field " LUA_QS " cannot be modified.", polyobj_opt[field]); + case polyobj_angle: + return luaL_error(L, LUA_QL("polyobj_t") " field " LUA_QS " should not be set directly. Use the function " LUA_QL("polyobj:rotate(angle)") " instead.", polyobj_opt[field]); + case polyobj_parent: + polyobj->parent = luaL_checkinteger(L, 3); + break; + case polyobj_flags: + polyobj->flags = luaL_checkinteger(L, 3); + break; + case polyobj_translucency: + polyobj->translucency = luaL_checkinteger(L, 3); + break; + } + + return 0; } static int polyobj_num(lua_State *L)