diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c70b6dd01..f395a8390 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -309,39 +309,39 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) return (FUINT)finallight; } -static FUINT HWR_SideLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 HWR_SideLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light + - ((side->lightabsolute) ? 0 : base_lightlevel); + return max(0, min(255, side->light + + ((side->lightabsolute) ? 0 : base_lightlevel))); } /* TODO: implement per-texture lighting -static FUINT HWR_TopLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 HWR_TopLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_top + - ((side->lightabsolute_top) ? 0 : HWR_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_top + + ((side->lightabsolute_top) ? 0 : HWR_SideLightLevel(side, base_lightlevel)))); } -static FUINT HWR_MidLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 HWR_MidLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_mid + - ((side->lightabsolute_mid) ? 0 : HWR_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_mid + + ((side->lightabsolute_mid) ? 0 : HWR_SideLightLevel(side, base_lightlevel)))); } -static FUINT HWR_BottomLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 HWR_BottomLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_bottom + - ((side->lightabsolute_bottom) ? 0 : HWR_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_bottom + + ((side->lightabsolute_bottom) ? 0 : HWR_SideLightLevel(side, base_lightlevel)))); } */ -static UINT8 HWR_FloorLightLevel(sector_t *sector, UINT8 base_lightlevel) +static UINT8 HWR_FloorLightLevel(sector_t *sector, INT16 base_lightlevel) { return max(0, min(255, sector->floorlightlevel + ((sector->floorlightabsolute) ? 0 : base_lightlevel))); } -static UINT8 HWR_CeilingLightLevel(sector_t *sector, UINT8 base_lightlevel) +static UINT8 HWR_CeilingLightLevel(sector_t *sector, INT16 base_lightlevel) { return max(0, min(255, sector->ceilinglightlevel + ((sector->ceilinglightabsolute) ? 0 : base_lightlevel))); diff --git a/src/r_bsp.c b/src/r_bsp.c index 4b4c81b88..373a170c9 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -230,13 +230,13 @@ static INT32 R_DoorClosed(void) && (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture); } -static UINT8 R_FloorLightLevel(sector_t *sector, UINT8 base_lightlevel) +static UINT8 R_FloorLightLevel(sector_t *sector, INT16 base_lightlevel) { return max(0, min(255, sector->floorlightlevel + ((sector->floorlightabsolute) ? 0 : base_lightlevel))); } -static UINT8 R_CeilingLightLevel(sector_t *sector, UINT8 base_lightlevel) +static UINT8 R_CeilingLightLevel(sector_t *sector, INT16 base_lightlevel) { return max(0, min(255, sector->ceilinglightlevel + ((sector->ceilinglightabsolute) ? 0 : base_lightlevel))); diff --git a/src/r_segs.c b/src/r_segs.c index 637e528fe..a8a065c9b 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -94,29 +94,29 @@ transnum_t R_GetLinedefTransTable(fixed_t alpha) return (20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1); } -static INT16 R_SideLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 R_SideLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light + - ((side->lightabsolute) ? 0 : base_lightlevel); + return max(0, min(255, side->light + + ((side->lightabsolute) ? 0 : base_lightlevel))); } /* TODO: implement per-texture lighting -static INT16 R_TopLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 R_TopLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_top + - ((side->lightabsolute_top) ? 0 : R_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_top + + ((side->lightabsolute_top) ? 0 : R_SideLightLevel(side, base_lightlevel)))); } -static INT16 R_MidLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 R_MidLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_mid + - ((side->lightabsolute_mid) ? 0 : R_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_mid + + ((side->lightabsolute_mid) ? 0 : R_SideLightLevel(side, base_lightlevel)))); } -static INT16 R_BottomLightLevel(side_t *side, UINT8 base_lightlevel) +static UINT8 R_BottomLightLevel(side_t *side, INT16 base_lightlevel) { - return side->light_bottom + - ((side->lightabsolute_bottom) ? 0 : R_SideLightLevel(side, base_lightlevel)); + return max(0, min(255, side->light_bottom + + ((side->lightabsolute_bottom) ? 0 : R_SideLightLevel(side, base_lightlevel)))); } */