From 21de33bd0878f2433461d2041feb9f964180c268 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 11 Apr 2020 12:54:34 +0200 Subject: [PATCH 1/4] Add mapthing arg support. --- src/doomdata.h | 6 +++++ src/lua_baselib.c | 3 +++ src/lua_libs.h | 2 ++ src/lua_mobjlib.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ src/p_setup.c | 20 +++++++++++++++ 5 files changed, 93 insertions(+) diff --git a/src/doomdata.h b/src/doomdata.h index d9bfb43b1..f8ace2948 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -193,6 +193,9 @@ typedef struct #pragma pack() #endif +#define NUMMAPTHINGARGS 6 +#define NUMMAPTHINGSTRINGARGS 2 + // Thing definition, position, orientation and type, // plus visibility flags and attributes. typedef struct @@ -204,6 +207,9 @@ typedef struct INT16 z; UINT8 extrainfo; INT16 tag; + INT32 args[NUMMAPTHINGARGS]; + char *stringargs[NUMMAPTHINGSTRINGARGS]; + struct mobj_s *mobj; } mapthing_t; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 7a99d1b0b..e24753aff 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -175,6 +175,9 @@ static const struct { {META_SIDENUM, "line_t.sidenum"}, {META_LINEARGS, "line_t.args"}, {META_LINESTRINGARGS, "line_t.stringargs"}, + + {META_THINGARGS, "mapthing.args"}, + {META_THINGSTRINGARGS, "mapthing.stringargs"}, #ifdef HAVE_LUA_SEGS {META_NODEBBOX, "node_t.bbox"}, {META_NODECHILDREN, "node_t.children"}, diff --git a/src/lua_libs.h b/src/lua_libs.h index 375041506..5bcb36b42 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -54,6 +54,8 @@ extern lua_State *gL; #define META_SIDENUM "LINE_T*SIDENUM" #define META_LINEARGS "LINE_T*ARGS" #define META_LINESTRINGARGS "LINE_T*STRINGARGS" +#define META_THINGARGS "MAPTHING_T*ARGS" +#define META_THINGSTRINGARGS "MAPTHING_T*STRINGARGS" #ifdef HAVE_LUA_SEGS #define META_NODEBBOX "NODE_T*BBOX" #define META_NODECHILDREN "NODE_T*CHILDREN" diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 8d2aad91e..53a02fb19 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -746,6 +746,42 @@ static int mobj_set(lua_State *L) #undef NOSETPOS #undef NOFIELD +// args, i -> args[i] +static int thingargs_get(lua_State *L) +{ + INT32 *args = *((INT32**)luaL_checkudata(L, 1, META_THINGARGS)); + int i = luaL_checkinteger(L, 2); + if (i < 0 || i >= NUMMAPTHINGARGS) + return luaL_error(L, LUA_QL("mapthing_t.args") " index cannot be %d", i); + lua_pushinteger(L, args[i]); + return 1; +} + +// #args -> NUMMAPTHINGARGS +static int thingargs_len(lua_State* L) +{ + lua_pushinteger(L, NUMMAPTHINGARGS); + return 1; +} + +// stringargs, i -> stringargs[i] +static int thingstringargs_get(lua_State *L) +{ + char **stringargs = *((char***)luaL_checkudata(L, 1, META_THINGSTRINGARGS)); + int i = luaL_checkinteger(L, 2); + if (i < 0 || i >= NUMMAPTHINGSTRINGARGS) + return luaL_error(L, LUA_QL("mapthing_t.stringargs") " index cannot be %d", i); + lua_pushstring(L, stringargs[i]); + return 1; +} + +// #stringargs -> NUMMAPTHINGSTRINGARGS +static int thingstringargs_len(lua_State *L) +{ + lua_pushinteger(L, NUMMAPTHINGSTRINGARGS); + return 1; +} + static int mapthing_get(lua_State *L) { mapthing_t *mt = *((mapthing_t **)luaL_checkudata(L, 1, META_MAPTHING)); @@ -781,6 +817,16 @@ static int mapthing_get(lua_State *L) number = mt->extrainfo; else if(fastcmp(field,"tag")) number = mt->tag; + else if(fastcmp(field,"args")) + { + LUA_PushUserdata(L, mt->args, META_THINGARGS); + return 1; + } + else if(fastcmp(field,"stringargs")) + { + LUA_PushUserdata(L, mt->args, META_THINGSTRINGARGS); + return 1; + } else if(fastcmp(field,"mobj")) { LUA_PushUserdata(L, mt->mobj, META_MOBJ); return 1; @@ -891,6 +937,22 @@ int LUA_MobjLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L,1); + luaL_newmetatable(L, META_THINGARGS); + lua_pushcfunction(L, thingargs_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, thingargs_len); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + + luaL_newmetatable(L, META_THINGSTRINGARGS); + lua_pushcfunction(L, thingstringargs_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, thingstringargs_len); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + luaL_newmetatable(L, META_MAPTHING); lua_pushcfunction(L, mapthing_get); lua_setfield(L, -2, "__index"); diff --git a/src/p_setup.c b/src/p_setup.c index edf904e1d..7b57b3800 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1275,6 +1275,8 @@ static void P_LoadThings(UINT8 *data) mt->options = READUINT16(data); mt->extrainfo = (UINT8)(mt->type >> 12); mt->tag = 0; + memset(mt->args, 0, NUMMAPTHINGARGS*sizeof(*mt->args)); + memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs)); mt->type &= 4095; @@ -1518,6 +1520,22 @@ static void ParseTextmapThingParameter(UINT32 i, char *param, char *val) mapthings[i].options |= MTF_OBJECTSPECIAL; else if (fastcmp(param, "ambush") && fastcmp("true", val)) mapthings[i].options |= MTF_AMBUSH; + + else if (fastncmp(param, "arg", 3) && strlen(param) > 3) + { + size_t argnum = atol(param + 3); + if (argnum >= NUMMAPTHINGARGS) + return; + mapthings[i].args[argnum] = atol(val); + } + else if (fastncmp(param, "stringarg", 9) && strlen(param) > 9) + { + size_t argnum = param[9] - '0'; + if (argnum >= NUMMAPTHINGSTRINGARGS) + return; + mapthings[i].stringargs[argnum] = Z_Malloc(strlen(val) + 1, PU_LEVEL, NULL); + M_Memcpy(mapthings[i].stringargs[argnum], val, strlen(val) + 1); + } } /** From a given position table, run a specified parser function through a {}-encapsuled text. @@ -1692,6 +1710,8 @@ static void P_LoadTextmap(void) mt->z = 0; mt->extrainfo = 0; mt->tag = 0; + memset(mt->args, 0, NUMMAPTHINGARGS*sizeof(*mt->args)); + memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs)); mt->mobj = NULL; TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter); From 5e20e9e27ec12c03862662c092824d27a949b7e1 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 13 Apr 2020 10:21:32 +0200 Subject: [PATCH 2/4] Fix typo involving the stringargs exposure. --- src/lua_mobjlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 53a02fb19..1df955b4a 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -819,12 +819,12 @@ static int mapthing_get(lua_State *L) number = mt->tag; else if(fastcmp(field,"args")) { - LUA_PushUserdata(L, mt->args, META_THINGARGS); + LUA_PushUserdata(L, mt->stringargs, META_THINGARGS); return 1; } else if(fastcmp(field,"stringargs")) { - LUA_PushUserdata(L, mt->args, META_THINGSTRINGARGS); + LUA_PushUserdata(L, mt->stringargs, META_THINGSTRINGARGS); return 1; } else if(fastcmp(field,"mobj")) { From cde14c1d9f2e8888d874e328f51859bbc1d7e665 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 19 Apr 2020 12:23:51 +0200 Subject: [PATCH 3/4] Fix an outrageous typo which didn't get pushed for some reason. --- src/lua_mobjlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 1df955b4a..f294355ac 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -819,7 +819,7 @@ static int mapthing_get(lua_State *L) number = mt->tag; else if(fastcmp(field,"args")) { - LUA_PushUserdata(L, mt->stringargs, META_THINGARGS); + LUA_PushUserdata(L, mt->args, META_THINGARGS); return 1; } else if(fastcmp(field,"stringargs")) From 1afb0eb79fdcc92d60cbcc3b14b2675ea571dd93 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 22 Apr 2020 09:00:29 +0200 Subject: [PATCH 4/4] Initialize pitch and roll on textmap mapthings too. --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index aa3e094f7..b0cb4f543 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1797,7 +1797,7 @@ static void P_LoadTextmap(void) { // Defaults. mt->x = mt->y = 0; - mt->angle = 0; + mt->angle = mt->pitch = mt->roll = 0; mt->type = 0; mt->options = 0; mt->z = 0;