From 4ce161f9c30b302188fc6f405e873c2cadfe3239 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 9 Sep 2020 19:38:56 +0100 Subject: [PATCH] Added the functions Polyobj_moveXY and Polyobj_rotate to Lua as polyobj.moveXY and polyobj.rotate --- src/lua_polyobjlib.c | 55 ++++++++++++++++++++++++++++++++++++++++---- src/p_polyobj.c | 4 ++-- src/p_polyobj.h | 2 ++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index 605780d2f..c43cac665 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -16,6 +16,10 @@ #include "p_polyobj.h" #include "lua_script.h" #include "lua_libs.h" +#include "lua_hud.h" // hud_running errors + +#define NOHUD if (hud_running)\ +return luaL_error(L, "HUD rendering code should not call this function!"); enum polyobj_e { // properties @@ -29,10 +33,13 @@ enum polyobj_e { polyobj_flags, polyobj_translucency, polyobj_triggertag, - // special functions + // special functions - utility polyobj_pointInside, polyobj_mobjTouching, - polyobj_mobjInside + polyobj_mobjInside, + // special functions - manipulation + polyobj_moveXY, + polyobj_rotate }; static const char *const polyobj_opt[] = { // properties @@ -46,12 +53,16 @@ static const char *const polyobj_opt[] = { "flags", "translucency", "triggertag", - // special functions + // special functions - utility "pointInside", "mobjTouching", "mobjInside", + // special functions - manipulation + "moveXY", + "rotate", NULL}; +// special functions - utility static int lib_polyobj_PointInside(lua_State *L) { polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -90,6 +101,35 @@ static int lib_polyobj_MobjInside(lua_State *L) return 1; } +// special functions - manipulation +static int lib_polyobj_moveXY(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + fixed_t x = luaL_checkfixed(L, 2); + fixed_t y = luaL_checkfixed(L, 3); + boolean checkmobjs = lua_opttrueboolean(L, 4); + NOHUD + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + lua_pushboolean(L, Polyobj_moveXY(po, x, y, checkmobjs)); + return 1; +} + +static int lib_polyobj_rotate(lua_State *L) +{ + polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); + angle_t delta = luaL_checkangle(L, 2); + UINT8 turnthings = (UINT8)luaL_optinteger(L, 3, 0); // don't turn anything by default? (could change this if not desired) + boolean checkmobjs = lua_opttrueboolean(L, 4); + NOHUD + INLEVEL + if (!po) + return LUA_ErrInvalid(L, "polyobj_t"); + lua_pushboolean(L, Polyobj_rotate(po, delta, turnthings, checkmobjs)); + return 1; +} + static int polyobj_get(lua_State *L) { polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ)); @@ -136,7 +176,7 @@ static int polyobj_get(lua_State *L) case polyobj_triggertag: lua_pushinteger(L, polyobj->triggertag); break; - // special functions + // special functions - utility case polyobj_pointInside: lua_pushcfunction(L, lib_polyobj_PointInside); break; @@ -146,6 +186,13 @@ static int polyobj_get(lua_State *L) case polyobj_mobjInside: lua_pushcfunction(L, lib_polyobj_MobjInside); break; + // special functions - manipulation + case polyobj_moveXY: + lua_pushcfunction(L, lib_polyobj_moveXY); + break; + case polyobj_rotate: + lua_pushcfunction(L, lib_polyobj_rotate); + break; } return 1; } diff --git a/src/p_polyobj.c b/src/p_polyobj.c index b0a794ddf..63d062c22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -976,7 +976,7 @@ static INT32 Polyobj_clipThings(polyobj_t *po, line_t *line) // Moves a polyobject on the x-y plane. -static boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs) +boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs) { size_t i; vertex_t vec; @@ -1162,7 +1162,7 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, } // Rotates a polyobject around its start point. -static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs) +boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs) { size_t i; angle_t angle; diff --git a/src/p_polyobj.h b/src/p_polyobj.h index f24caca4e..8c2946965 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -336,6 +336,8 @@ typedef struct polyfadedata_s // Functions // +boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean checkmobjs); +boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, boolean checkmobjs); polyobj_t *Polyobj_GetForNum(INT32 id); void Polyobj_InitLevel(void); void Polyobj_MoveOnLoad(polyobj_t *po, angle_t angle, fixed_t x, fixed_t y);