mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
Merge branch 'lua-sector-lines' into 'next'
Lua sector lines Adds support for "sector.lines" in Lua, an array containing all the linedefs in a particular sector variable: #sector.lines returns the number of lines in the sector. sector.lines\[ _i_ \] (e.g. sector.lines[0], sector.lines[1], sector.lines[2], etc ....) gives you individual linedefs in the sector. If the number you supply is equal to or greater than #sector.lines, this returns nil. Test script for your benefit: (see comments) Type "luatest" in console in any level and you'll get a few print messages that tests these features for sectors[0] See merge request !32
This commit is contained in:
commit
e769b7882c
2 changed files with 75 additions and 0 deletions
|
@ -42,6 +42,7 @@ extern lua_State *gL;
|
||||||
|
|
||||||
#define META_CVAR "CONSVAR_T*"
|
#define META_CVAR "CONSVAR_T*"
|
||||||
|
|
||||||
|
#define META_SECTORLINES "SECTOR_T*LINES"
|
||||||
#define META_SIDENUM "LINE_T*SIDENUM"
|
#define META_SIDENUM "LINE_T*SIDENUM"
|
||||||
|
|
||||||
#define META_HUDINFO "HUDINFO_T*"
|
#define META_HUDINFO "HUDINFO_T*"
|
||||||
|
|
|
@ -37,6 +37,7 @@ enum sector_e {
|
||||||
sector_thinglist,
|
sector_thinglist,
|
||||||
sector_heightsec,
|
sector_heightsec,
|
||||||
sector_camsec,
|
sector_camsec,
|
||||||
|
sector_lines,
|
||||||
sector_ffloors
|
sector_ffloors
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ static const char *const sector_opt[] = {
|
||||||
"thinglist",
|
"thinglist",
|
||||||
"heightsec",
|
"heightsec",
|
||||||
"camsec",
|
"camsec",
|
||||||
|
"lines",
|
||||||
"ffloors",
|
"ffloors",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
|
@ -260,6 +262,67 @@ static int sector_iterate(lua_State *L)
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sector.lines, i -> sector.lines[i]
|
||||||
|
// sector.lines.valid, for validity checking
|
||||||
|
static int sectorlines_get(lua_State *L)
|
||||||
|
{
|
||||||
|
line_t **seclines = *((line_t ***)luaL_checkudata(L, 1, META_SECTORLINES));
|
||||||
|
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 (!seclines)
|
||||||
|
{
|
||||||
|
if (field == 0) {
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return luaL_error(L, "accessed sector_t doesn't exist anymore.");
|
||||||
|
} else if (field == 0) {
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
||||||
|
// then check that sector's linecount to get a maximum index
|
||||||
|
//if (!seclines[0])
|
||||||
|
//return luaL_error(L, "no lines found!"); // no first linedef?????
|
||||||
|
if (seclines[0]->frontsector->lines == seclines)
|
||||||
|
numoflines = seclines[0]->frontsector->linecount;
|
||||||
|
else if (seclines[0]->backsector && seclines[0]->backsector->lines == seclines) // check backsector exists first
|
||||||
|
numoflines = seclines[0]->backsector->linecount;
|
||||||
|
//if neither sector has it then ???
|
||||||
|
|
||||||
|
if (!numoflines)
|
||||||
|
return luaL_error(L, "no lines found!");
|
||||||
|
|
||||||
|
i = (size_t)lua_tointeger(L, 2);
|
||||||
|
if (i >= numoflines)
|
||||||
|
return 0;
|
||||||
|
LUA_PushUserdata(L, seclines[i], META_LINE);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sectorlines_num(lua_State *L)
|
||||||
|
{
|
||||||
|
line_t **seclines = *((line_t ***)luaL_checkudata(L, 1, META_SECTORLINES));
|
||||||
|
size_t numoflines = 0;
|
||||||
|
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
||||||
|
// then check that sector's linecount to get a maximum index
|
||||||
|
//if (!seclines[0])
|
||||||
|
//return luaL_error(L, "no lines found!"); // no first linedef?????
|
||||||
|
if (seclines[0]->frontsector->lines == seclines)
|
||||||
|
numoflines = seclines[0]->frontsector->linecount;
|
||||||
|
else if (seclines[0]->backsector && seclines[0]->backsector->lines == seclines) // check backsector exists first
|
||||||
|
numoflines = seclines[0]->backsector->linecount;
|
||||||
|
//if neither sector has it then ???
|
||||||
|
lua_pushinteger(L, numoflines);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int sector_get(lua_State *L)
|
static int sector_get(lua_State *L)
|
||||||
{
|
{
|
||||||
sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
||||||
|
@ -325,6 +388,9 @@ static int sector_get(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
LUA_PushUserdata(L, §ors[sector->camsec], META_SECTOR);
|
LUA_PushUserdata(L, §ors[sector->camsec], META_SECTOR);
|
||||||
return 1;
|
return 1;
|
||||||
|
case sector_lines: // lines
|
||||||
|
LUA_PushUserdata(L, sector->lines, META_SECTORLINES);
|
||||||
|
return 1;
|
||||||
case sector_ffloors: // ffloors
|
case sector_ffloors: // ffloors
|
||||||
lua_pushcfunction(L, lib_iterateSectorFFloors);
|
lua_pushcfunction(L, lib_iterateSectorFFloors);
|
||||||
LUA_PushUserdata(L, sector->ffloors, META_FFLOOR);
|
LUA_PushUserdata(L, sector->ffloors, META_FFLOOR);
|
||||||
|
@ -1234,6 +1300,14 @@ static int mapheaderinfo_get(lua_State *L)
|
||||||
|
|
||||||
int LUA_MapLib(lua_State *L)
|
int LUA_MapLib(lua_State *L)
|
||||||
{
|
{
|
||||||
|
luaL_newmetatable(L, META_SECTORLINES);
|
||||||
|
lua_pushcfunction(L, sectorlines_get);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lua_pushcfunction(L, sectorlines_num);
|
||||||
|
lua_setfield(L, -2, "__len");
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
luaL_newmetatable(L, META_SECTOR);
|
luaL_newmetatable(L, META_SECTOR);
|
||||||
lua_pushcfunction(L, sector_get);
|
lua_pushcfunction(L, sector_get);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
Loading…
Reference in a new issue