From cd95473d57debe649018fd39474548eab683940f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 8 Aug 2009 20:03:43 +0000 Subject: [PATCH] - replaced all code that changed a sector's light level with a setter function. SVN r1762 (trunk) --- src/g_shared/a_lightning.cpp | 12 +++++----- src/g_strife/a_thingstoblowup.cpp | 2 +- src/p_lights.cpp | 40 +++++++++++++++---------------- src/r_defs.h | 15 ++++++++++++ 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/g_shared/a_lightning.cpp b/src/g_shared/a_lightning.cpp index 1d0cbadd2..99de24c20 100644 --- a/src/g_shared/a_lightning.cpp +++ b/src/g_shared/a_lightning.cpp @@ -92,7 +92,7 @@ void DLightningThinker::LightningFlash () if (LightningLightLevels[numsectors+(j>>3)] & (1<<(j&7)) && LightningLightLevels[j] < tempSec->lightlevel-4) { - tempSec->lightlevel -= 4; + tempSec->ChangeLightLevel(-4); } } } @@ -103,7 +103,7 @@ void DLightningThinker::LightningFlash () { if (LightningLightLevels[numsectors+(j>>3)] & (1<<(j&7))) { - tempSec->lightlevel = LightningLightLevels[j]; + tempSec->SetLightLevel(LightningLightLevels[j]); } } memset (&LightningLightLevels[numsectors], 0, (numsectors+7)/8); @@ -128,19 +128,19 @@ void DLightningThinker::LightningFlash () LightningLightLevels[numsectors+(j>>3)] |= 1<<(j&7); if (special == Light_IndoorLightning1) { - tempSec->lightlevel = MIN (tempSec->lightlevel+64, flashLight); + tempSec->SetLightLevel(MIN (tempSec->lightlevel+64, flashLight)); } else if (special == Light_IndoorLightning2) { - tempSec->lightlevel = MIN (tempSec->lightlevel+32, flashLight); + tempSec->SetLightLevel(MIN (tempSec->lightlevel+32, flashLight)); } else { - tempSec->lightlevel = flashLight; + tempSec->SetLightLevel(flashLight); } if (tempSec->lightlevel < LightningLightLevels[j]) { - tempSec->lightlevel = LightningLightLevels[j]; + tempSec->SetLightLevel(LightningLightLevels[j]); } } } diff --git a/src/g_strife/a_thingstoblowup.cpp b/src/g_strife/a_thingstoblowup.cpp index 95348600a..52cb1d3e5 100644 --- a/src/g_strife/a_thingstoblowup.cpp +++ b/src/g_strife/a_thingstoblowup.cpp @@ -90,7 +90,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_LightGoesOut) vertex_t *spot; fixed_t newheight; - sec->lightlevel = 0; + sec->SetLightLevel(0); newheight = sec->FindLowestFloorSurrounding (&spot); sec->floorplane.d = sec->floorplane.PointToDist (spot, newheight); diff --git a/src/p_lights.cpp b/src/p_lights.cpp index 3901bc232..c33e27466 100644 --- a/src/p_lights.cpp +++ b/src/p_lights.cpp @@ -81,9 +81,9 @@ void DFireFlicker::Tick () // [RH] Shouldn't this be (m_MaxLight - amount < m_MinLight)? if (m_Sector->lightlevel - amount < m_MinLight) - m_Sector->lightlevel = m_MinLight; + m_Sector->SetLightLevel(m_MinLight); else - m_Sector->lightlevel = m_MaxLight - amount; + m_Sector->SetLightLevel(m_MaxLight - amount); m_Count = 4; } @@ -132,12 +132,12 @@ void DFlicker::Tick () } else if (m_Sector->lightlevel == m_MaxLight) { - m_Sector->lightlevel = m_MinLight; + m_Sector->SetLightLevel(m_MinLight); m_Count = (pr_flicker()&7)+1; } else { - m_Sector->lightlevel = m_MaxLight; + m_Sector->SetLightLevel(m_MaxLight); m_Count = (pr_flicker()&31)+1; } } @@ -189,12 +189,12 @@ void DLightFlash::Tick () { if (m_Sector->lightlevel == m_MaxLight) { - m_Sector->lightlevel = m_MinLight; + m_Sector->SetLightLevel(m_MinLight); m_Count = (pr_lightflash() & m_MinTime) + 1; } else { - m_Sector->lightlevel = m_MaxLight; + m_Sector->SetLightLevel(m_MaxLight); m_Count = (pr_lightflash() & m_MaxTime) + 1; } } @@ -251,12 +251,12 @@ void DStrobe::Tick () { if (m_Sector->lightlevel == m_MinLight) { - m_Sector->lightlevel = m_MaxLight; + m_Sector->SetLightLevel(m_MaxLight); m_Count = m_BrightTime; } else { - m_Sector->lightlevel = m_MinLight; + m_Sector->SetLightLevel(m_MinLight); m_Count = m_DarkTime; } } @@ -353,7 +353,7 @@ void EV_TurnTagLightsOff (int tag) if (tsec->lightlevel < min) min = tsec->lightlevel; } - sector->lightlevel = min; + sector->SetLightLevel(min); } } @@ -390,7 +390,7 @@ void EV_LightTurnOn (int tag, int bright) bright = temp->lightlevel; } } - sector->lightlevel = clamp (bright, 0, 255); + sector->SetLightLevel(bright); } } @@ -433,7 +433,7 @@ void EV_LightTurnOnPartway (int tag, fixed_t frac) } } } - sector->lightlevel = (BYTE)DMulScale16 (frac, bright, FRACUNIT-frac, min); + sector->SetLightLevel(DMulScale16 (frac, bright, FRACUNIT-frac, min)); } } @@ -450,7 +450,7 @@ void EV_LightChange (int tag, int value) while ((secnum = P_FindSectorFromTag (tag, secnum)) >= 0) { int newlight = sectors[secnum].lightlevel + value; - sectors[secnum].lightlevel = clamp (newlight, 0, 255); + sectors[secnum].SetLightLevel(newlight); } } @@ -496,7 +496,7 @@ void DGlow::Tick () } break; } - m_Sector->lightlevel = newlight; + m_Sector->SetLightLevel(newlight); } @@ -530,7 +530,7 @@ void DGlow2::Tick () { if (m_OneShot) { - m_Sector->lightlevel = m_End; + m_Sector->SetLightLevel(m_End); Destroy (); return; } @@ -543,7 +543,7 @@ void DGlow2::Tick () } } - m_Sector->lightlevel = ((m_End - m_Start) * m_Tics) / m_MaxTics + m_Start; + m_Sector->SetLightLevel(((m_End - m_Start) * m_Tics) / m_MaxTics + m_Start); } DGlow2::DGlow2 (sector_t *sector, int start, int end, int tics, bool oneshot) @@ -597,7 +597,7 @@ void EV_StartLightFading (int tag, int value, int tics) if (tics <= 0) { - sec->lightlevel = value; + sec->SetLightLevel(value); } else { @@ -631,12 +631,12 @@ void DPhased::Tick () const int steps = 12; if (m_Phase < steps) - m_Sector->lightlevel = ((255 - m_BaseLevel) * m_Phase) / steps + m_BaseLevel; + m_Sector->SetLightLevel( ((255 - m_BaseLevel) * m_Phase) / steps + m_BaseLevel); else if (m_Phase < 2*steps) - m_Sector->lightlevel = ((255 - m_BaseLevel) * (2*steps - m_Phase - 1) / steps - + m_BaseLevel); + m_Sector->SetLightLevel( ((255 - m_BaseLevel) * (2*steps - m_Phase - 1) / steps + + m_BaseLevel)); else - m_Sector->lightlevel = m_BaseLevel; + m_Sector->SetLightLevel(m_BaseLevel); if (m_Phase == 0) m_Phase = 63; diff --git a/src/r_defs.h b/src/r_defs.h index 5679e463f..090e25a20 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -590,6 +590,21 @@ struct sector_t return (MoreFlags & SECF_IGNOREHEIGHTSEC)? NULL : heightsec; } + void ChangeLightLevel(int newval) + { + lightlevel = (BYTE)clamp(lightlevel + newval, 0, 255); + } + + void SetLightLevel(int newval) + { + lightlevel = (BYTE)clamp(newval, 0, 255); + } + + int GetLightLevel() const + { + return lightlevel; + } + // Member variables fixed_t CenterFloor () const { return floorplane.ZatPoint (soundorg[0], soundorg[1]); }