From 7d4b1d0852e90cf7f5a9237aaa6efa594e0a9aa8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 17 Aug 2024 15:28:37 +0200 Subject: [PATCH] Update light offset on polyobjects when they rotate --- src/p_polyobj.c | 3 +++ src/p_setup.c | 30 ++++++++++++++++++++---------- src/p_setup.h | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 9a3376595..a56753e98 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1415,7 +1415,10 @@ static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings) { // update seg angles (used only by renderer) for (i = 0; i < po->segCount; ++i) + { po->segs[i]->angle += delta; + P_UpdateSegLightOffset(po->segs[i]); + } // update polyobject's angle po->angle += delta; diff --git a/src/p_setup.c b/src/p_setup.c index 449fcface..512b4a0e5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -427,6 +427,25 @@ static inline float P_SegLengthFloat(seg_t *seg) } #endif +/** Updates the light offset + * + * \param li Seg to update the light offsets of + */ +void P_UpdateSegLightOffset(seg_t *li) +{ + fixed_t extralight = 0; + + extralight = -(8*FRACUNIT) + + FixedDiv(AngleFixed(R_PointToAngle2(0, 0, + abs(li->v1->x - li->v2->x), + abs(li->v1->y - li->v2->y))), 90*FRACUNIT) * 16; + + // Between -1 and 1 for software, -8 and 8 for hardware + li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT; +#ifdef HWRENDER + li->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT; +#endif +} // Loads the SEGS resource from a level. static void P_LoadRawSegs(UINT8 *data) @@ -466,16 +485,7 @@ static void P_LoadRawSegs(UINT8 *data) li->numlights = 0; li->rlights = NULL; - extralight = -(8*FRACUNIT) + - FixedDiv(AngleFixed(R_PointToAngle2(0, 0, - abs(li->v1->x - li->v2->x), - abs(li->v1->y - li->v2->y))), 90*FRACUNIT) * 16; - - // Between -1 and 1 for software, -8 and 8 for hardware - li->lightOffset = FixedFloor((extralight / 8) + (FRACUNIT / 2)) / FRACUNIT; -#ifdef HWRENDER - li->hwLightOffset = FixedFloor(extralight + (FRACUNIT / 2)) / FRACUNIT; -#endif + P_UpdateSegLightOffset(li); } } diff --git a/src/p_setup.h b/src/p_setup.h index 8a77c690b..36f2089aa 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -88,6 +88,7 @@ SINT8 P_PartialAddGetStage(void); boolean P_RunSOC(const char *socfilename); void P_WriteThings(lumpnum_t lump); +void P_UpdateSegLightOffset(seg_t *li); size_t P_PrecacheLevelFlats(void); void P_AllocMapHeader(INT16 i);