From 195920acdcffca94bb335bc06d3dea5cd238da43 Mon Sep 17 00:00:00 2001 From: Sryder Date: Thu, 21 May 2020 17:15:50 +0100 Subject: [PATCH] Update light offset on polyobjects when they rotate --- src/p_polyobj.c | 3 +++ src/p_setup.c | 31 +++++++++++++++++++++---------- src/p_setup.h | 1 + 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 03fb10d0f..12708a44b 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1407,7 +1407,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 f56b2f4ea..259d8f5ff 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -446,6 +446,26 @@ 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. * * \param lump Lump number of the SEGS resource. @@ -494,16 +514,7 @@ static void P_LoadRawSegs(UINT8 *data, size_t i) 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 9abcfe5f6..c0b30ca6a 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -66,6 +66,7 @@ boolean P_DelWadFile(void); #endif 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);