mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-29 20:50:58 +00:00
Merge branch 'next' into linedef-args
This commit is contained in:
commit
031e3d93b2
10 changed files with 205 additions and 83 deletions
|
@ -20,9 +20,12 @@ enum hook {
|
|||
hook_MapChange,
|
||||
hook_MapLoad,
|
||||
hook_PlayerJoin,
|
||||
hook_PreThinkFrame,
|
||||
hook_ThinkFrame,
|
||||
hook_PostThinkFrame,
|
||||
hook_MobjSpawn,
|
||||
hook_MobjCollide,
|
||||
hook_MobjLineCollide,
|
||||
hook_MobjMoveCollide,
|
||||
hook_TouchSpecial,
|
||||
hook_MobjFuse,
|
||||
|
@ -62,12 +65,16 @@ extern const char *const hookNames[];
|
|||
void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load)
|
||||
void LUAh_MapLoad(void); // Hook for map load
|
||||
void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer
|
||||
void LUAh_PreThinkFrame(void); // Hook for frame (before mobj and player thinkers)
|
||||
void LUAh_ThinkFrame(void); // Hook for frame (after mobj and player thinkers)
|
||||
void LUAh_PostThinkFrame(void); // Hook for frame (at end of tick, ie after overlays, precipitation, specials)
|
||||
boolean LUAh_MobjHook(mobj_t *mo, enum hook which);
|
||||
boolean LUAh_PlayerHook(player_t *plr, enum hook which);
|
||||
#define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type
|
||||
UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which);
|
||||
UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which);
|
||||
#define LUAh_MobjCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjCollide) // Hook for PIT_CheckThing by (thing) mobj type
|
||||
#define LUAh_MobjLineCollide(thing, line) LUAh_MobjLineCollideHook(thing, line, hook_MobjLineCollide) // Hook for PIT_CheckThing by (thing) mobj type
|
||||
#define LUAh_MobjMoveCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjMoveCollide) // Hook for PIT_CheckThing by (tmthing) mobj type
|
||||
boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher); // Hook for P_TouchSpecialThing by mobj type
|
||||
#define LUAh_MobjFuse(mo) LUAh_MobjHook(mo, hook_MobjFuse) // Hook for mobj->fuse == 0 by mobj type
|
||||
|
|
|
@ -31,9 +31,12 @@ const char *const hookNames[hook_MAX+1] = {
|
|||
"MapChange",
|
||||
"MapLoad",
|
||||
"PlayerJoin",
|
||||
"PreThinkFrame",
|
||||
"ThinkFrame",
|
||||
"PostThinkFrame",
|
||||
"MobjSpawn",
|
||||
"MobjCollide",
|
||||
"MobjLineCollide",
|
||||
"MobjMoveCollide",
|
||||
"TouchSpecial",
|
||||
"MobjFuse",
|
||||
|
@ -124,6 +127,7 @@ static int lib_addHook(lua_State *L)
|
|||
// Take a mobjtype enum which this hook is specifically for.
|
||||
case hook_MobjSpawn:
|
||||
case hook_MobjCollide:
|
||||
case hook_MobjLineCollide:
|
||||
case hook_MobjMoveCollide:
|
||||
case hook_TouchSpecial:
|
||||
case hook_MobjFuse:
|
||||
|
@ -183,6 +187,7 @@ static int lib_addHook(lua_State *L)
|
|||
lastp = &mobjthinkerhooks[hook.s.mt];
|
||||
break;
|
||||
case hook_MobjCollide:
|
||||
case hook_MobjLineCollide:
|
||||
case hook_MobjMoveCollide:
|
||||
lastp = &mobjcollidehooks[hook.s.mt];
|
||||
break;
|
||||
|
@ -413,6 +418,29 @@ void LUAh_PlayerJoin(int playernum)
|
|||
lua_settop(gL, 0);
|
||||
}
|
||||
|
||||
// Hook for frame (before mobj and player thinkers)
|
||||
void LUAh_PreThinkFrame(void)
|
||||
{
|
||||
hook_p hookp;
|
||||
if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8))))
|
||||
return;
|
||||
|
||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != hook_PreThinkFrame)
|
||||
continue;
|
||||
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
if (lua_pcall(gL, 0, 0, 0)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hook for frame (after mobj and player thinkers)
|
||||
void LUAh_ThinkFrame(void)
|
||||
{
|
||||
|
@ -436,6 +464,30 @@ void LUAh_ThinkFrame(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Hook for frame (at end of tick, ie after overlays, precipitation, specials)
|
||||
void LUAh_PostThinkFrame(void)
|
||||
{
|
||||
hook_p hookp;
|
||||
if (!gL || !(hooksAvailable[hook_PostThinkFrame/8] & (1<<(hook_PostThinkFrame%8))))
|
||||
return;
|
||||
|
||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != hook_PostThinkFrame)
|
||||
continue;
|
||||
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
if (lua_pcall(gL, 0, 0, 0)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hook for mobj collisions
|
||||
UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
|
||||
{
|
||||
|
@ -515,6 +567,84 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
|
|||
return shouldCollide;
|
||||
}
|
||||
|
||||
UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which)
|
||||
{
|
||||
hook_p hookp;
|
||||
UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
|
||||
if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
|
||||
return 0;
|
||||
|
||||
I_Assert(thing->type < NUMMOBJTYPES);
|
||||
|
||||
lua_settop(gL, 0);
|
||||
|
||||
// Look for all generic mobj collision hooks
|
||||
for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != which)
|
||||
continue;
|
||||
|
||||
if (lua_gettop(gL) == 0)
|
||||
{
|
||||
LUA_PushUserdata(gL, thing, META_MOBJ);
|
||||
LUA_PushUserdata(gL, line, META_LINE);
|
||||
}
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushvalue(gL, -3);
|
||||
lua_pushvalue(gL, -3);
|
||||
if (lua_pcall(gL, 2, 1, 0)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
continue;
|
||||
}
|
||||
if (!lua_isnil(gL, -1))
|
||||
{ // if nil, leave shouldCollide = 0.
|
||||
if (lua_toboolean(gL, -1))
|
||||
shouldCollide = 1; // Force yes
|
||||
else
|
||||
shouldCollide = 2; // Force no
|
||||
}
|
||||
lua_pop(gL, 1);
|
||||
}
|
||||
|
||||
for (hookp = mobjcollidehooks[thing->type]; hookp; hookp = hookp->next)
|
||||
{
|
||||
if (hookp->type != which)
|
||||
continue;
|
||||
|
||||
if (lua_gettop(gL) == 0)
|
||||
{
|
||||
LUA_PushUserdata(gL, thing, META_MOBJ);
|
||||
LUA_PushUserdata(gL, line, META_LINE);
|
||||
}
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushvalue(gL, -3);
|
||||
lua_pushvalue(gL, -3);
|
||||
if (lua_pcall(gL, 2, 1, 0)) {
|
||||
if (!hookp->error || cv_debug & DBG_LUA)
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||
lua_pop(gL, 1);
|
||||
hookp->error = true;
|
||||
continue;
|
||||
}
|
||||
if (!lua_isnil(gL, -1))
|
||||
{ // if nil, leave shouldCollide = 0.
|
||||
if (lua_toboolean(gL, -1))
|
||||
shouldCollide = 1; // Force yes
|
||||
else
|
||||
shouldCollide = 2; // Force no
|
||||
}
|
||||
lua_pop(gL, 1);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
return shouldCollide;
|
||||
}
|
||||
|
||||
// Hook for mobj thinkers
|
||||
boolean LUAh_MobjThinker(mobj_t *mo)
|
||||
{
|
||||
|
|
|
@ -159,15 +159,13 @@ static const char *const side_opt[] = {
|
|||
enum vertex_e {
|
||||
vertex_valid = 0,
|
||||
vertex_x,
|
||||
vertex_y,
|
||||
vertex_z
|
||||
vertex_y
|
||||
};
|
||||
|
||||
static const char *const vertex_opt[] = {
|
||||
"valid",
|
||||
"x",
|
||||
"y",
|
||||
"z",
|
||||
NULL};
|
||||
|
||||
enum ffloor_e {
|
||||
|
@ -993,9 +991,6 @@ static int vertex_get(lua_State *L)
|
|||
case vertex_y:
|
||||
lua_pushfixed(L, vertex->y);
|
||||
return 1;
|
||||
case vertex_z:
|
||||
lua_pushfixed(L, vertex->z);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
15
src/p_map.c
15
src/p_map.c
|
@ -1948,6 +1948,19 @@ static boolean PIT_CheckLine(line_t *ld)
|
|||
|
||||
// this line is out of the if so upper and lower textures can be hit by a splat
|
||||
blockingline = ld;
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
{
|
||||
UINT8 shouldCollide = LUAh_MobjLineCollide(tmthing, blockingline); // checks hook for thing's type
|
||||
if (P_MobjWasRemoved(tmthing))
|
||||
return true; // one of them was removed???
|
||||
if (shouldCollide == 1)
|
||||
return false; // force collide
|
||||
else if (shouldCollide == 2)
|
||||
return true; // force no collide
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!ld->backsector) // one sided line
|
||||
{
|
||||
if (P_PointOnLineSide(tmthing->x, tmthing->y, ld))
|
||||
|
@ -1992,7 +2005,7 @@ static boolean PIT_CheckLine(line_t *ld)
|
|||
|
||||
if (lowfloor < tmdropoffz)
|
||||
tmdropoffz = lowfloor;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,68 +78,37 @@ void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result)
|
|||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// P_ClosestPointOnLine3D
|
||||
// Finds the closest point on a given line to the supplied point IN 3D!!!
|
||||
//
|
||||
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result)
|
||||
/// Similar to FV3_ClosestPointOnLine() except it actually works.
|
||||
void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *Line, vector3_t *result)
|
||||
{
|
||||
fixed_t startx = line->v1->x;
|
||||
fixed_t starty = line->v1->y;
|
||||
fixed_t startz = line->v1->z;
|
||||
fixed_t dx = line->dx;
|
||||
fixed_t dy = line->dy;
|
||||
fixed_t dz = line->v2->z - line->v1->z;
|
||||
const vector3_t* v1 = &Line[0];
|
||||
const vector3_t* v2 = &Line[1];
|
||||
vector3_t c, V, n;
|
||||
fixed_t t, d;
|
||||
FV3_SubEx(v2, v1, &V);
|
||||
FV3_SubEx(p, v1, &c);
|
||||
|
||||
// Determine t (the length of the vector from <20>Line[0]<5D> to <20>p<EFBFBD>)
|
||||
fixed_t cx, cy, cz;
|
||||
fixed_t vx, vy, vz;
|
||||
fixed_t magnitude;
|
||||
fixed_t t;
|
||||
d = R_PointToDist2(0, v2->z, R_PointToDist2(v2->x, v2->y, v1->x, v1->y), v1->z);
|
||||
FV3_Copy(&n, &V);
|
||||
FV3_Divide(&n, d);
|
||||
|
||||
//Sub (p, &Line[0], &c);
|
||||
cx = x - startx;
|
||||
cy = y - starty;
|
||||
cz = z - startz;
|
||||
|
||||
//Sub (&Line[1], &Line[0], &V);
|
||||
vx = dx;
|
||||
vy = dy;
|
||||
vz = dz;
|
||||
|
||||
//Normalize (&V, &V);
|
||||
magnitude = R_PointToDist2(0, line->v2->z, R_PointToDist2(line->v2->x, line->v2->y, startx, starty), startz);
|
||||
vx = FixedDiv(vx, magnitude);
|
||||
vy = FixedDiv(vy, magnitude);
|
||||
vz = FixedDiv(vz, magnitude);
|
||||
|
||||
t = (FixedMul(vx, cx) + FixedMul(vy, cy) + FixedMul(vz, cz));
|
||||
t = FV3_Dot(&n, &c);
|
||||
|
||||
// Set closest point to the end if it extends past -Red
|
||||
if (t <= 0)
|
||||
{
|
||||
result->x = line->v1->x;
|
||||
result->y = line->v1->y;
|
||||
result->z = line->v1->z;
|
||||
FV3_Copy(result, v1);
|
||||
return;
|
||||
}
|
||||
else if (t >= magnitude)
|
||||
else if (t >= d)
|
||||
{
|
||||
result->x = line->v2->x;
|
||||
result->y = line->v2->y;
|
||||
result->z = line->v2->z;
|
||||
FV3_Copy(result, v2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the point between <20>Line[0]<5D> and <20>Line[1]<5D>
|
||||
vx = FixedMul(vx, t);
|
||||
vy = FixedMul(vy, t);
|
||||
vz = FixedMul(vz, t);
|
||||
FV3_Mul(&n, t);
|
||||
|
||||
//Add (&Line[0], &V, out);
|
||||
result->x = startx + vx;
|
||||
result->y = starty + vy;
|
||||
result->z = startz + vz;
|
||||
FV3_AddEx(v1, &n, result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ boolean P_PathTraverse(fixed_t px1, fixed_t py1, fixed_t px2, fixed_t py2,
|
|||
|
||||
FUNCMATH fixed_t P_AproxDistance(fixed_t dx, fixed_t dy);
|
||||
void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result);
|
||||
void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, vertex_t *result);
|
||||
void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *line, vector3_t *result);
|
||||
INT32 P_PointOnLineSide(fixed_t x, fixed_t y, line_t *line);
|
||||
void P_MakeDivline(line_t *li, divline_t *dl);
|
||||
void P_CameraLineOpening(line_t *plinedef);
|
||||
|
|
|
@ -846,7 +846,6 @@ static void P_LoadVertices(UINT8 *data)
|
|||
{
|
||||
v->x = SHORT(mv->x)<<FRACBITS;
|
||||
v->y = SHORT(mv->y)<<FRACBITS;
|
||||
v->z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1583,7 +1582,6 @@ static void P_LoadTextmap(void)
|
|||
{
|
||||
// Defaults.
|
||||
vt->x = vt->y = INT32_MAX;
|
||||
vt->z = 0;
|
||||
|
||||
TextmapParse(vertexesPos[i], i, ParseTextmapVertexParameter);
|
||||
|
||||
|
|
43
src/p_spec.c
43
src/p_spec.c
|
@ -5038,8 +5038,7 @@ DoneSection2:
|
|||
mobj_t *waypointlow = NULL;
|
||||
mobj_t *mo2;
|
||||
mobj_t *closest = NULL;
|
||||
line_t junk;
|
||||
vertex_t v1, v2, resulthigh, resultlow;
|
||||
vector3_t p, line[2], resulthigh, resultlow;
|
||||
mobj_t *highest = NULL;
|
||||
|
||||
if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT && player->powers[pw_carry] == CR_ROPEHANG)
|
||||
|
@ -5186,38 +5185,34 @@ DoneSection2:
|
|||
// Next, we need to find the closest point on the line between each set, and determine which one we're
|
||||
// closest to.
|
||||
|
||||
p.x = player->mo->x;
|
||||
p.y = player->mo->y;
|
||||
p.z = player->mo->z;
|
||||
|
||||
// Waypointmid and Waypointlow:
|
||||
if (waypointlow)
|
||||
{
|
||||
v1.x = waypointmid->x;
|
||||
v1.y = waypointmid->y;
|
||||
v1.z = waypointmid->z;
|
||||
v2.x = waypointlow->x;
|
||||
v2.y = waypointlow->y;
|
||||
v2.z = waypointlow->z;
|
||||
junk.v1 = &v1;
|
||||
junk.v2 = &v2;
|
||||
junk.dx = v2.x - v1.x;
|
||||
junk.dy = v2.y - v1.y;
|
||||
line[0].x = waypointmid->x;
|
||||
line[0].y = waypointmid->y;
|
||||
line[0].z = waypointmid->z;
|
||||
line[1].x = waypointlow->x;
|
||||
line[1].y = waypointlow->y;
|
||||
line[1].z = waypointlow->z;
|
||||
|
||||
P_ClosestPointOnLine3D(player->mo->x, player->mo->y, player->mo->z, &junk, &resultlow);
|
||||
P_ClosestPointOnLine3D(&p, line, &resultlow);
|
||||
}
|
||||
|
||||
// Waypointmid and Waypointhigh:
|
||||
if (waypointhigh)
|
||||
{
|
||||
v1.x = waypointmid->x;
|
||||
v1.y = waypointmid->y;
|
||||
v1.z = waypointmid->z;
|
||||
v2.x = waypointhigh->x;
|
||||
v2.y = waypointhigh->y;
|
||||
v2.z = waypointhigh->z;
|
||||
junk.v1 = &v1;
|
||||
junk.v2 = &v2;
|
||||
junk.dx = v2.x - v1.x;
|
||||
junk.dy = v2.y - v1.y;
|
||||
line[0].x = waypointmid->x;
|
||||
line[0].y = waypointmid->y;
|
||||
line[0].z = waypointmid->z;
|
||||
line[1].x = waypointhigh->x;
|
||||
line[1].y = waypointhigh->y;
|
||||
line[1].z = waypointhigh->z;
|
||||
|
||||
P_ClosestPointOnLine3D(player->mo->x, player->mo->y, player->mo->z, &junk, &resulthigh);
|
||||
P_ClosestPointOnLine3D(&p, line, &resulthigh);
|
||||
}
|
||||
|
||||
// 3D support now available. Disregard the previous notice here. -Red
|
||||
|
|
15
src/p_tick.c
15
src/p_tick.c
|
@ -629,6 +629,10 @@ void P_Ticker(boolean run)
|
|||
if (demoplayback)
|
||||
G_ReadDemoTiccmd(&players[consoleplayer].cmd, 0);
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PreThinkFrame();
|
||||
#endif
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
|
||||
P_PlayerThink(&players[i]);
|
||||
|
@ -726,6 +730,10 @@ void P_Ticker(boolean run)
|
|||
G_ConsGhostTic();
|
||||
if (modeattacking)
|
||||
G_GhostTicker();
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PostThinkFrame();
|
||||
#endif
|
||||
}
|
||||
|
||||
P_MapEnd();
|
||||
|
@ -745,6 +753,9 @@ void P_PreTicker(INT32 frames)
|
|||
{
|
||||
P_MapStart();
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PreThinkFrame();
|
||||
#endif
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
|
||||
{
|
||||
|
@ -779,6 +790,10 @@ void P_PreTicker(INT32 frames)
|
|||
P_UpdateSpecials();
|
||||
P_RespawnSpecials();
|
||||
|
||||
#ifdef HAVE_BLUA
|
||||
LUAh_PostThinkFrame();
|
||||
#endif
|
||||
|
||||
P_MapEnd();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ typedef struct extracolormap_s
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
fixed_t x, y, z;
|
||||
fixed_t x, y;
|
||||
} vertex_t;
|
||||
|
||||
// Forward of linedefs, for sectors.
|
||||
|
|
Loading…
Reference in a new issue