Add mapthing arg support.

This commit is contained in:
Nev3r 2020-04-11 12:54:34 +02:00
parent ab133e50c9
commit 21de33bd08
5 changed files with 93 additions and 0 deletions

View file

@ -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;

View file

@ -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"},

View file

@ -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"

View file

@ -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");

View file

@ -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);