Added ability to use custom-defined lines with P_PointOnLineSide such as with P_ClosestPointOnLine

This commit is contained in:
Monster Iestyn 2016-11-24 22:01:51 +00:00
parent aa146dee41
commit 38f7af9281

View file

@ -206,11 +206,36 @@ static int lib_pClosestPointOnLine(lua_State *L)
static int lib_pPointOnLineSide(lua_State *L)
{
int n = lua_gettop(L);
fixed_t x = luaL_checkfixed(L, 1);
fixed_t y = luaL_checkfixed(L, 2);
line_t *line = *((line_t **)luaL_checkudata(L, 3, META_LINE));
//HUDSAFE
lua_pushinteger(L, P_PointOnLineSide(x, y, line));
if (lua_isuserdata(L, 3)) // use a real linedef to get our points
{
line_t *line = *((line_t **)luaL_checkudata(L, 3, META_LINE));
if (!line)
return LUA_ErrInvalid(L, "line_t");
lua_pushinteger(L, P_PointOnLineSide(x, y, line));
}
else // use custom coordinates of our own!
{
vertex_t v1, v2; // fake vertexes
line_t junk; // fake linedef
if (n < 6)
return luaL_error(L, "arguments 3 to 6 not all given (expected 4 fixed-point integers)");
v1.x = luaL_checkfixed(L, 3);
v1.y = luaL_checkfixed(L, 4);
v2.x = luaL_checkfixed(L, 5);
v2.y = luaL_checkfixed(L, 6);
junk.v1 = &v1;
junk.v2 = &v2;
junk.dx = v2.x - v1.x;
junk.dy = v2.y - v1.y;
lua_pushinteger(L, P_PointOnLineSide(x, y, &junk));
}
return 1;
}