Update light offset on polyobjects when they rotate

This commit is contained in:
Sryder 2020-05-21 17:15:50 +01:00
parent d4080e94f7
commit 195920acdc
3 changed files with 25 additions and 10 deletions

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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);