From 68da1856dad55002f9c1004bec1484e154f9df7e Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Thu, 2 Jan 2020 12:23:14 +0100 Subject: [PATCH] Implement linedef args (unused and untested so far) --- src/lua_baselib.c | 1 + src/lua_libs.h | 1 + src/lua_maplib.c | 31 +++++++++++++++++++++++++++++++ src/p_saveg.c | 32 ++++++++++++++++++++++++++++++-- src/p_setup.c | 9 +++++++++ src/r_defs.h | 3 +++ 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 695e9367e..6798ac8b8 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -175,6 +175,7 @@ static const struct { {META_SECTORLINES, "sector_t.lines"}, {META_SIDENUM, "line_t.sidenum"}, + {META_LINEARGS, "line_t.args"}, #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 6a908d03d..155c34eaa 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -56,6 +56,7 @@ extern lua_State *gL; #define META_SECTORLINES "SECTOR_T*LINES" #define META_SIDENUM "LINE_T*SIDENUM" +#define META_LINEARGS "LINE_T*ARGS" #ifdef HAVE_LUA_SEGS #define META_NODEBBOX "NODE_T*BBOX" #define META_NODECHILDREN "NODE_T*CHILDREN" diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 8ce6551f7..26ab71823 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -94,6 +94,7 @@ enum line_e { line_flags, line_special, line_tag, + line_args, line_sidenum, line_frontside, line_backside, @@ -115,6 +116,7 @@ static const char *const line_opt[] = { "flags", "special", "tag", + "args", "sidenum", "frontside", "backside", @@ -703,6 +705,24 @@ static int subsector_num(lua_State *L) // line_t // //////////// +// args, i -> args[i] +static int lineargs_get(lua_State *L) +{ + INT32 *args = *((INT32**)luaL_checkudata(L, 1, META_LINEARGS)); + int i = luaL_checkinteger(L, 2); + if (i < 0 || i >= NUMLINEARGS) + return luaL_error(L, LUA_QL("line_t.args") " index cannot be %d", i); + lua_pushinteger(L, args[i]); + return 1; +} + +// #args -> NUMLINEARGS +static int lineargs_len(lua_State* L) +{ + lua_pushinteger(L, NUMLINEARGS); + return 1; +} + static int line_get(lua_State *L) { line_t *line = *((line_t **)luaL_checkudata(L, 1, META_LINE)); @@ -743,6 +763,9 @@ static int line_get(lua_State *L) case line_tag: lua_pushinteger(L, line->tag); return 1; + case line_args: + LUA_PushUserdata(L, line->args, META_LINEARGS); + return 1; case line_sidenum: LUA_PushUserdata(L, line->sidenum, META_SIDENUM); return 1; @@ -2142,6 +2165,14 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + luaL_newmetatable(L, META_LINEARGS); + lua_pushcfunction(L, lineargs_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lineargs_len); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + luaL_newmetatable(L, META_SIDENUM); lua_pushcfunction(L, sidenum_get); lua_setfield(L, -2, "__index"); diff --git a/src/p_saveg.c b/src/p_saveg.c index 4cfeab6f8..3dd6bac0f 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -768,6 +768,17 @@ static void P_NetUnArchiveColormaps(void) #define LD_S2TOPTEX 0x02 #define LD_S2BOTTEX 0x04 #define LD_S2MIDTEX 0x08 +#define LD_ARGS 0x10 + +static boolean P_AreArgsEqual(const INT32 args[NUMLINEARGS], const INT32 spawnargs[NUMLINEARGS]) +{ + UINT8 i; + for (i = 0; i < NUMLINEARGS; i++) + if (args[i] != spawnargs[i]) + return false; + + return true; +} // // P_NetArchiveWorld @@ -944,6 +955,9 @@ static void P_NetArchiveWorld(void) if (spawnli->special == 321 || spawnli->special == 322) // only reason li->callcount would be non-zero is if either of these are involved diff |= LD_CLLCOUNT; + if (!P_AreArgsEqual(li->args, spawnli->args)) + diff2 |= LD_ARGS; + if (li->sidenum[0] != 0xffff) { si = &sides[li->sidenum[0]]; @@ -970,10 +984,11 @@ static void P_NetArchiveWorld(void) diff2 |= LD_S2BOTTEX; if (si->midtexture != spawnsi->midtexture) diff2 |= LD_S2MIDTEX; - if (diff2) - diff |= LD_DIFF2; } + if (diff2) + diff |= LD_DIFF2; + if (diff) { statline++; @@ -1007,6 +1022,12 @@ static void P_NetArchiveWorld(void) WRITEINT32(put, si->bottomtexture); if (diff2 & LD_S2MIDTEX) WRITEINT32(put, si->midtexture); + if (diff2 & LD_ARGS) + { + UINT8 j; + for (j = 0; j < NUMLINEARGS; j++) + WRITEINT32(put, li->args[j]); + } } } WRITEUINT16(put, 0xffff); @@ -1190,6 +1211,13 @@ static void P_NetUnArchiveWorld(void) si->bottomtexture = READINT32(get); if (diff2 & LD_S2MIDTEX) si->midtexture = READINT32(get); + if (diff2 & LD_ARGS) + { + UINT8 j; + for (j = 0; j < NUMLINEARGS; j++) + li->args[j] = READINT32(get); + } + } save_p = get; diff --git a/src/p_setup.c b/src/p_setup.c index 4de5fedc8..585799cba 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1053,6 +1053,7 @@ static void P_LoadLinedefs(UINT8 *data) ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); ld->tag = SHORT(mld->tag); + memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); P_SetLinedefV1(i, SHORT(mld->v1)); P_SetLinedefV2(i, SHORT(mld->v2)); @@ -1428,6 +1429,13 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) P_SetLinedefV1(i, atol(val)); else if (fastcmp(param, "v2")) P_SetLinedefV2(i, atol(val)); + else if (fastncmp(param, "arg", 3) && strlen(param) > 3) + { + size_t argnum = atol(param + 3); + if (argnum >= NUMLINEARGS) + return; + lines[i].args[argnum] = atol(val); + } else if (fastcmp(param, "sidefront")) lines[i].sidenum[0] = atol(val); else if (fastcmp(param, "sideback")) @@ -1616,6 +1624,7 @@ static void P_LoadTextmap(void) ld->flags = 0; ld->special = 0; ld->tag = 0; + memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); ld->sidenum[0] = 0xffff; ld->sidenum[1] = 0xffff; diff --git a/src/r_defs.h b/src/r_defs.h index ceb694c57..8e9e96920 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -401,6 +401,8 @@ typedef enum #define HORIZONSPECIAL 41 +#define NUMLINEARGS 6 + typedef struct line_s { // Vertices, from v1 to v2. @@ -413,6 +415,7 @@ typedef struct line_s INT16 flags; INT16 special; INT16 tag; + INT32 args[NUMLINEARGS]; // Visual appearance: sidedefs. UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided