Merge branch 'stringargs' into 'udmf-next'

Add string-based linedef arguments to UDMF

See merge request STJr/SRB2!672
This commit is contained in:
MascaraSnake 2020-01-12 08:31:11 -05:00
commit 73eb13da02
8 changed files with 125 additions and 15 deletions

View file

@ -176,6 +176,7 @@ static const struct {
{META_SECTORLINES, "sector_t.lines"}, {META_SECTORLINES, "sector_t.lines"},
{META_SIDENUM, "line_t.sidenum"}, {META_SIDENUM, "line_t.sidenum"},
{META_LINEARGS, "line_t.args"}, {META_LINEARGS, "line_t.args"},
{META_LINESTRINGARGS, "line_t.stringargs"},
#ifdef HAVE_LUA_SEGS #ifdef HAVE_LUA_SEGS
{META_NODEBBOX, "node_t.bbox"}, {META_NODEBBOX, "node_t.bbox"},
{META_NODECHILDREN, "node_t.children"}, {META_NODECHILDREN, "node_t.children"},

View file

@ -1134,7 +1134,7 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next) for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next)
{ {
if (strcmp(hookp->s.funcname, line->text)) if (strcmp(hookp->s.funcname, line->stringargs[0]))
continue; continue;
if (lua_gettop(gL) == 0) if (lua_gettop(gL) == 0)

View file

@ -57,6 +57,7 @@ extern lua_State *gL;
#define META_SECTORLINES "SECTOR_T*LINES" #define META_SECTORLINES "SECTOR_T*LINES"
#define META_SIDENUM "LINE_T*SIDENUM" #define META_SIDENUM "LINE_T*SIDENUM"
#define META_LINEARGS "LINE_T*ARGS" #define META_LINEARGS "LINE_T*ARGS"
#define META_LINESTRINGARGS "LINE_T*STRINGARGS"
#ifdef HAVE_LUA_SEGS #ifdef HAVE_LUA_SEGS
#define META_NODEBBOX "NODE_T*BBOX" #define META_NODEBBOX "NODE_T*BBOX"
#define META_NODECHILDREN "NODE_T*CHILDREN" #define META_NODECHILDREN "NODE_T*CHILDREN"

View file

@ -95,6 +95,7 @@ enum line_e {
line_special, line_special,
line_tag, line_tag,
line_args, line_args,
line_stringargs,
line_sidenum, line_sidenum,
line_frontside, line_frontside,
line_backside, line_backside,
@ -117,6 +118,7 @@ static const char *const line_opt[] = {
"special", "special",
"tag", "tag",
"args", "args",
"stringargs",
"sidenum", "sidenum",
"frontside", "frontside",
"backside", "backside",
@ -729,6 +731,24 @@ static int lineargs_len(lua_State* L)
return 1; return 1;
} }
// stringargs, i -> stringargs[i]
static int linestringargs_get(lua_State *L)
{
char **stringargs = *((char***)luaL_checkudata(L, 1, META_LINESTRINGARGS));
int i = luaL_checkinteger(L, 2);
if (i < 0 || i >= NUMLINESTRINGARGS)
return luaL_error(L, LUA_QL("line_t.stringargs") " index cannot be %d", i);
lua_pushstring(L, stringargs[i]);
return 1;
}
// #stringargs -> NUMLINESTRINGARGS
static int linestringargs_len(lua_State *L)
{
lua_pushinteger(L, NUMLINESTRINGARGS);
return 1;
}
static int line_get(lua_State *L) static int line_get(lua_State *L)
{ {
line_t *line = *((line_t **)luaL_checkudata(L, 1, META_LINE)); line_t *line = *((line_t **)luaL_checkudata(L, 1, META_LINE));
@ -772,6 +792,9 @@ static int line_get(lua_State *L)
case line_args: case line_args:
LUA_PushUserdata(L, line->args, META_LINEARGS); LUA_PushUserdata(L, line->args, META_LINEARGS);
return 1; return 1;
case line_stringargs:
LUA_PushUserdata(L, line->stringargs, META_LINESTRINGARGS);
return 1;
case line_sidenum: case line_sidenum:
LUA_PushUserdata(L, line->sidenum, META_SIDENUM); LUA_PushUserdata(L, line->sidenum, META_SIDENUM);
return 1; return 1;
@ -2188,6 +2211,14 @@ int LUA_MapLib(lua_State *L)
lua_setfield(L, -2, "__len"); lua_setfield(L, -2, "__len");
lua_pop(L, 1); lua_pop(L, 1);
luaL_newmetatable(L, META_LINESTRINGARGS);
lua_pushcfunction(L, linestringargs_get);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, linestringargs_len);
lua_setfield(L, -2, "__len");
lua_pop(L, 1);
luaL_newmetatable(L, META_SIDENUM); luaL_newmetatable(L, META_SIDENUM);
lua_pushcfunction(L, sidenum_get); lua_pushcfunction(L, sidenum_get);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");

View file

@ -769,12 +769,23 @@ static void P_NetUnArchiveColormaps(void)
#define LD_S2BOTTEX 0x04 #define LD_S2BOTTEX 0x04
#define LD_S2MIDTEX 0x08 #define LD_S2MIDTEX 0x08
#define LD_ARGS 0x10 #define LD_ARGS 0x10
#define LD_STRINGARGS 0x20
static boolean P_AreArgsEqual(const INT32 args[NUMLINEARGS], const INT32 spawnargs[NUMLINEARGS]) static boolean P_AreArgsEqual(const line_t *li, const line_t *spawnli)
{ {
UINT8 i; UINT8 i;
for (i = 0; i < NUMLINEARGS; i++) for (i = 0; i < NUMLINEARGS; i++)
if (args[i] != spawnargs[i]) if (li->args[i] != spawnli->args[i])
return false;
return true;
}
static boolean P_AreStringArgsEqual(const line_t *li, const line_t *spawnli)
{
UINT8 i;
for (i = 0; i < NUMLINESTRINGARGS; i++)
if (strcmp(li->stringargs[i], spawnli->stringargs[i]))
return false; return false;
return true; return true;
@ -955,9 +966,12 @@ 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 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; diff |= LD_CLLCOUNT;
if (!P_AreArgsEqual(li->args, spawnli->args)) if (!P_AreArgsEqual(li, spawnli))
diff2 |= LD_ARGS; diff2 |= LD_ARGS;
if (!P_AreStringArgsEqual(li, spawnli))
diff2 |= LD_STRINGARGS;
if (li->sidenum[0] != 0xffff) if (li->sidenum[0] != 0xffff)
{ {
si = &sides[li->sidenum[0]]; si = &sides[li->sidenum[0]];
@ -1028,6 +1042,25 @@ static void P_NetArchiveWorld(void)
for (j = 0; j < NUMLINEARGS; j++) for (j = 0; j < NUMLINEARGS; j++)
WRITEINT32(put, li->args[j]); WRITEINT32(put, li->args[j]);
} }
if (diff2 & LD_STRINGARGS)
{
UINT8 j;
for (j = 0; j < NUMLINESTRINGARGS; j++)
{
size_t len, k;
if (!li->stringargs[j])
{
WRITEINT32(put, 0);
continue;
}
len = strlen(li->stringargs[j]);
WRITEINT32(put, len);
for (k = 0; k < len; k++)
WRITECHAR(put, li->stringargs[j][k]);
}
}
} }
} }
WRITEUINT16(put, 0xffff); WRITEUINT16(put, 0xffff);
@ -1217,7 +1250,27 @@ static void P_NetUnArchiveWorld(void)
for (j = 0; j < NUMLINEARGS; j++) for (j = 0; j < NUMLINEARGS; j++)
li->args[j] = READINT32(get); li->args[j] = READINT32(get);
} }
if (diff2 & LD_STRINGARGS)
{
UINT8 j;
for (j = 0; j < NUMLINESTRINGARGS; j++)
{
size_t len = READINT32(get);
size_t k;
if (!len)
{
Z_Free(li->stringargs[j]);
li->stringargs[j] = NULL;
continue;
}
li->stringargs[j] = Z_Realloc(li->stringargs[j], len + 1, PU_LEVEL, NULL);
for (k = 0; k < len; k++)
li->stringargs[j][k] = READCHAR(get);
li->stringargs[j][len] = '\0';
}
}
} }
save_p = get; save_p = get;

View file

@ -1055,6 +1055,7 @@ static void P_LoadLinedefs(UINT8 *data)
ld->special = SHORT(mld->special); ld->special = SHORT(mld->special);
ld->tag = SHORT(mld->tag); ld->tag = SHORT(mld->tag);
memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args));
memset(ld->stringargs, (int)NULL, NUMLINESTRINGARGS*sizeof(*ld->stringargs));
P_SetLinedefV1(i, SHORT(mld->v1)); P_SetLinedefV1(i, SHORT(mld->v1));
P_SetLinedefV2(i, SHORT(mld->v2)); P_SetLinedefV2(i, SHORT(mld->v2));
@ -1440,12 +1441,23 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val)
else if (fastcmp(param, "v2")) else if (fastcmp(param, "v2"))
P_SetLinedefV2(i, atol(val)); P_SetLinedefV2(i, atol(val));
else if (fastncmp(param, "arg", 3) && strlen(param) > 3) else if (fastncmp(param, "arg", 3) && strlen(param) > 3)
{
if (fastcmp(param + 4, "str"))
{
size_t argnum = param[3] - '0';
if (argnum >= NUMLINESTRINGARGS)
return;
lines[i].stringargs[argnum] = Z_Malloc(strlen(val) + 1, PU_LEVEL, NULL);
M_Memcpy(lines[i].stringargs[argnum], val, strlen(val) + 1);
}
else
{ {
size_t argnum = atol(param + 3); size_t argnum = atol(param + 3);
if (argnum >= NUMLINEARGS) if (argnum >= NUMLINEARGS)
return; return;
lines[i].args[argnum] = atol(val); lines[i].args[argnum] = atol(val);
} }
}
else if (fastcmp(param, "sidefront")) else if (fastcmp(param, "sidefront"))
lines[i].sidenum[0] = atol(val); lines[i].sidenum[0] = atol(val);
else if (fastcmp(param, "sideback")) else if (fastcmp(param, "sideback"))
@ -1636,6 +1648,7 @@ static void P_LoadTextmap(void)
ld->special = 0; ld->special = 0;
ld->tag = 0; ld->tag = 0;
memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args));
memset(ld->stringargs, (int)NULL, NUMLINESTRINGARGS*sizeof(*ld->stringargs));
ld->sidenum[0] = 0xffff; ld->sidenum[0] = 0xffff;
ld->sidenum[1] = 0xffff; ld->sidenum[1] = 0xffff;
@ -2666,6 +2679,15 @@ static void P_ConvertBinaryMap(void)
{ {
switch (lines[i].special) switch (lines[i].special)
{ {
case 443: //Call Lua function
if (lines[i].text)
{
lines[i].stringargs[0] = Z_Malloc(strlen(lines[i].text) + 1, PU_LEVEL, NULL);
M_Memcpy(lines[i].stringargs[0], lines[i].text, strlen(lines[i].text) + 1);
}
else
CONS_Alert(CONS_WARNING, "Linedef %s is missing the hook name of the Lua function to call! (This should be given in the front texture fields)\n", sizeu1(i));
break;
case 700: //Slope front sector floor case 700: //Slope front sector floor
case 701: //Slope front sector ceiling case 701: //Slope front sector ceiling
case 702: //Slope front sector floor and ceiling case 702: //Slope front sector floor and ceiling

View file

@ -3367,10 +3367,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
case 443: // Calls a named Lua function case 443: // Calls a named Lua function
#ifdef HAVE_BLUA #ifdef HAVE_BLUA
if (line->text) if (line->stringargs[0])
LUAh_LinedefExecute(line, mo, callsec); LUAh_LinedefExecute(line, mo, callsec);
else else
CONS_Alert(CONS_WARNING, "Linedef %s is missing the hook name of the Lua function to call! (This should be given in the front texture fields)\n", sizeu1(line-lines)); CONS_Alert(CONS_WARNING, "Linedef %s is missing the hook name of the Lua function to call! (This should be given in arg0str)\n", sizeu1(line-lines));
#else #else
CONS_Alert(CONS_ERROR, "The map is trying to run a Lua script, but this exe was not compiled with Lua support!\n"); CONS_Alert(CONS_ERROR, "The map is trying to run a Lua script, but this exe was not compiled with Lua support!\n");
#endif #endif

View file

@ -404,6 +404,7 @@ typedef enum
#define HORIZONSPECIAL 41 #define HORIZONSPECIAL 41
#define NUMLINEARGS 6 #define NUMLINEARGS 6
#define NUMLINESTRINGARGS 2
typedef struct line_s typedef struct line_s
{ {
@ -418,6 +419,7 @@ typedef struct line_s
INT16 special; INT16 special;
INT16 tag; INT16 tag;
INT32 args[NUMLINEARGS]; INT32 args[NUMLINEARGS];
char *stringargs[NUMLINESTRINGARGS];
// Visual appearance: sidedefs. // Visual appearance: sidedefs.
UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided