From 72bf2a9897dece88f523995917c0080129467a7f Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 24 Aug 2021 03:13:18 -0500 Subject: [PATCH] Add angle field to linedef_t --- src/lua_maplib.c | 5 +++++ src/p_map.c | 6 +++--- src/p_polyobj.c | 4 +++- src/p_setup.c | 2 ++ src/p_spec.c | 2 +- src/r_defs.h | 1 + 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 9031c99f1..84caec591 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -88,6 +88,7 @@ enum line_e { line_v2, line_dx, line_dy, + line_angle, line_flags, line_special, line_tag, @@ -113,6 +114,7 @@ static const char *const line_opt[] = { "v2", "dx", "dy", + "angle", "flags", "special", "tag", @@ -821,6 +823,9 @@ static int line_get(lua_State *L) case line_dy: lua_pushfixed(L, line->dy); return 1; + case line_angle: + lua_pushangle(L, line->angle); + return 1; case line_flags: lua_pushinteger(L, line->flags); return 1; diff --git a/src/p_map.c b/src/p_map.c index e55bebb9a..b852cb393 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3060,7 +3060,7 @@ static void P_HitCameraSlideLine(line_t *ld, camera_t *thiscam) } side = P_PointOnLineSide(thiscam->x, thiscam->y, ld); - lineangle = R_PointToAngle2(0, 0, ld->dx, ld->dy); + lineangle = ld->angle; if (side == 1) lineangle += ANGLE_180; @@ -3106,7 +3106,7 @@ static void P_HitSlideLine(line_t *ld) side = P_PointOnLineSide(slidemo->x, slidemo->y, ld); - lineangle = R_PointToAngle2(0, 0, ld->dx, ld->dy); + lineangle = ld->angle; if (side == 1) lineangle += ANGLE_180; @@ -3149,7 +3149,7 @@ static void P_HitBounceLine(line_t *ld) return; } - lineangle = R_PointToAngle2(0, 0, ld->dx, ld->dy); + lineangle = ld->angle; if (lineangle >= ANGLE_180) lineangle -= ANGLE_180; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 6431e4624..5e3cf9d8e 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -785,7 +785,7 @@ static void Polyobj_pushThing(polyobj_t *po, line_t *line, mobj_t *mo) vertex_t closest; // calculate angle of line and subtract 90 degrees to get normal - lineangle = R_PointToAngle2(0, 0, line->dx, line->dy) - ANGLE_90; + lineangle = line->angle - ANGLE_90; lineangle >>= ANGLETOFINESHIFT; momx = FixedMul(po->thrust, FINECOSINE(lineangle)); momy = FixedMul(po->thrust, FINESINE(lineangle)); @@ -1060,6 +1060,8 @@ static void Polyobj_rotateLine(line_t *ld) ld->dx = v2->x - v1->x; ld->dy = v2->y - v1->y; + ld->angle = R_PointToAngle2(0, 0, ld->dx, ld->dy); + // determine slopetype ld->slopetype = !ld->dx ? ST_VERTICAL : !ld->dy ? ST_HORIZONTAL : ((ld->dy > 0) == (ld->dx > 0)) ? ST_POSITIVE : ST_NEGATIVE; diff --git a/src/p_setup.c b/src/p_setup.c index 498759b73..53fc281a9 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1058,6 +1058,8 @@ static void P_InitializeLinedef(line_t *ld) ld->dx = v2->x - v1->x; ld->dy = v2->y - v1->y; + ld->angle = R_PointToAngle2(0, 0, ld->dx, ld->dy); + ld->bbox[BOXLEFT] = min(v1->x, v2->x); ld->bbox[BOXRIGHT] = max(v1->x, v2->x); ld->bbox[BOXBOTTOM] = min(v1->y, v2->y); diff --git a/src/p_spec.c b/src/p_spec.c index 4b566acfb..f955ffbf4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1241,7 +1241,7 @@ static boolean PolyFlag(line_t *line) pfd.polyObjNum = Tag_FGet(&line->tags); pfd.speed = P_AproxDistance(line->dx, line->dy) >> FRACBITS; - pfd.angle = R_PointToAngle2(line->v1->x, line->v1->y, line->v2->x, line->v2->y) >> ANGLETOFINESHIFT; + pfd.angle = line->angle >> ANGLETOFINESHIFT; pfd.momx = sides[line->sidenum[0]].textureoffset >> FRACBITS; return EV_DoPolyObjFlag(&pfd); diff --git a/src/r_defs.h b/src/r_defs.h index 1be3a1b8c..6567921b4 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -386,6 +386,7 @@ typedef struct line_s vertex_t *v2; fixed_t dx, dy; // Precalculated v2 - v1 for side checking. + angle_t angle; // Precalculated angle between dx and dy // Animation related. INT16 flags;