mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-29 20:50:58 +00:00
lua_maplib.c changes now that polyobj_t is supported:
* added line.polyobj for line_t * added subsector.polyList iteration function, for iterating polyobjs in a subsector * added seg.polyseg for seg_t, in case we ever reenable support for segs/nodes
This commit is contained in:
parent
89e989d6b1
commit
5f91833701
1 changed files with 56 additions and 3 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "p_setup.h"
|
||||
#include "z_zone.h"
|
||||
#include "p_slopes.h"
|
||||
#include "p_polyobj.h"
|
||||
#include "r_main.h"
|
||||
|
||||
#include "lua_script.h"
|
||||
|
@ -67,6 +68,7 @@ enum subsector_e {
|
|||
subsector_sector,
|
||||
subsector_numlines,
|
||||
subsector_firstline,
|
||||
subsector_polyList
|
||||
};
|
||||
|
||||
static const char *const subsector_opt[] = {
|
||||
|
@ -74,6 +76,7 @@ static const char *const subsector_opt[] = {
|
|||
"sector",
|
||||
"numlines",
|
||||
"firstline",
|
||||
"polyList",
|
||||
NULL};
|
||||
|
||||
enum line_e {
|
||||
|
@ -97,6 +100,7 @@ enum line_e {
|
|||
line_backsector,
|
||||
line_firsttag,
|
||||
line_nexttag,
|
||||
line_polyobj,
|
||||
line_text,
|
||||
line_callcount
|
||||
};
|
||||
|
@ -122,6 +126,7 @@ static const char *const line_opt[] = {
|
|||
"backsector",
|
||||
"firsttag",
|
||||
"nexttag",
|
||||
"polyobj",
|
||||
"text",
|
||||
"callcount",
|
||||
NULL};
|
||||
|
@ -222,6 +227,7 @@ enum seg_e {
|
|||
seg_linedef,
|
||||
seg_frontsector,
|
||||
seg_backsector,
|
||||
seg_polyseg
|
||||
};
|
||||
|
||||
static const char *const seg_opt[] = {
|
||||
|
@ -235,6 +241,7 @@ static const char *const seg_opt[] = {
|
|||
"linedef",
|
||||
"frontsector",
|
||||
"backsector",
|
||||
"polyseg",
|
||||
NULL};
|
||||
|
||||
enum node_e {
|
||||
|
@ -324,9 +331,9 @@ static const char *const vector_opt[] = {
|
|||
static const char *const array_opt[] ={"iterate",NULL};
|
||||
static const char *const valid_opt[] ={"valid",NULL};
|
||||
|
||||
///////////////////////////////////
|
||||
// sector list iterate functions //
|
||||
///////////////////////////////////
|
||||
/////////////////////////////////////////////
|
||||
// sector/subsector list iterate functions //
|
||||
/////////////////////////////////////////////
|
||||
|
||||
// iterates through a sector's thinglist!
|
||||
static int lib_iterateSectorThinglist(lua_State *L)
|
||||
|
@ -398,6 +405,41 @@ static int lib_iterateSectorFFloors(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// iterates through a subsector's polyList! (for polyobj_t)
|
||||
static int lib_iterateSubSectorPolylist(lua_State *L)
|
||||
{
|
||||
polyobj_t *state = NULL;
|
||||
polyobj_t *po = NULL;
|
||||
|
||||
INLEVEL
|
||||
|
||||
if (lua_gettop(L) < 2)
|
||||
return luaL_error(L, "Don't call subsector.polyList() directly, use it as 'for polyobj in subsector.polyList do <block> end'.");
|
||||
|
||||
if (!lua_isnil(L, 1))
|
||||
state = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
|
||||
else
|
||||
return 0; // no polylist to iterate through sorry!
|
||||
|
||||
lua_settop(L, 2);
|
||||
lua_remove(L, 1); // remove state now.
|
||||
|
||||
if (!lua_isnil(L, 1))
|
||||
{
|
||||
po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
|
||||
po = (polyobj_t *)(po->link.next);
|
||||
}
|
||||
else
|
||||
po = state; // state is used as the "start" of the polylist
|
||||
|
||||
if (po)
|
||||
{
|
||||
LUA_PushUserdata(L, po, META_POLYOBJ);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sector_iterate(lua_State *L)
|
||||
{
|
||||
lua_pushvalue(L, lua_upvalueindex(1)); // iterator function, or the "generator"
|
||||
|
@ -684,6 +726,11 @@ static int subsector_get(lua_State *L)
|
|||
case subsector_firstline:
|
||||
lua_pushinteger(L, subsector->firstline);
|
||||
return 1;
|
||||
case subsector_polyList: // polyList
|
||||
lua_pushcfunction(L, lib_iterateSubSectorPolylist);
|
||||
LUA_PushUserdata(L, subsector->polyList, META_POLYOBJ);
|
||||
lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateSubSectorPolylist and subsector->polyList as upvalues for the function
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -827,6 +874,9 @@ static int line_get(lua_State *L)
|
|||
case line_nexttag:
|
||||
lua_pushinteger(L, line->nexttag);
|
||||
return 1;
|
||||
case line_polyobj:
|
||||
LUA_PushUserdata(L, line->polyobj, META_POLYOBJ);
|
||||
return 1;
|
||||
case line_text:
|
||||
lua_pushstring(L, line->text);
|
||||
return 1;
|
||||
|
@ -1089,6 +1139,9 @@ static int seg_get(lua_State *L)
|
|||
case seg_backsector:
|
||||
LUA_PushUserdata(L, seg->backsector, META_SECTOR);
|
||||
return 1;
|
||||
case seg_polyseg:
|
||||
LUA_PushUserdata(L, seg->polyseg, META_POLYOBJ);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue