Fixed: Light levels outside the range [0,255] really do matter.

SVN r3223 (trunk)
This commit is contained in:
Randy Heit 2011-06-11 23:58:33 +00:00
parent f69181f851
commit ee8ca0de87
11 changed files with 97 additions and 48 deletions

View file

@ -21,7 +21,7 @@ DLightningThinker::DLightningThinker ()
LightningFlashCount = 0; LightningFlashCount = 0;
NextLightningFlash = ((pr_lightning()&15)+5)*35; // don't flash at level start NextLightningFlash = ((pr_lightning()&15)+5)*35; // don't flash at level start
LightningLightLevels = new BYTE[numsectors + (numsectors+7)/8]; LightningLightLevels = new short[numsectors + (numsectors+7)/8];
memset (LightningLightLevels, 0, numsectors + (numsectors+7)/8); memset (LightningLightLevels, 0, numsectors + (numsectors+7)/8);
} }
@ -36,7 +36,7 @@ DLightningThinker::~DLightningThinker ()
void DLightningThinker::Serialize (FArchive &arc) void DLightningThinker::Serialize (FArchive &arc)
{ {
int i; int i;
BYTE *lights; short *lights;
Super::Serialize (arc); Super::Serialize (arc);
@ -48,12 +48,21 @@ void DLightningThinker::Serialize (FArchive &arc)
{ {
delete[] LightningLightLevels; delete[] LightningLightLevels;
} }
LightningLightLevels = new BYTE[numsectors + (numsectors+7)/8]; LightningLightLevels = new short[numsectors + (numsectors+7)/8];
} }
lights = LightningLightLevels; lights = LightningLightLevels;
for (i = (numsectors + (numsectors+7)/8); i > 0; ++lights, --i) for (i = (numsectors + (numsectors+7)/8); i > 0; ++lights, --i)
{ {
arc << *lights; if (SaveVersion < 3223)
{
BYTE bytelight;
arc << bytelight;
*lights = bytelight;
}
else
{
arc << *lights;
}
} }
} }

View file

@ -24,7 +24,7 @@ protected:
int NextLightningFlash; int NextLightningFlash;
int LightningFlashCount; int LightningFlashCount;
bool Stopped; bool Stopped;
BYTE *LightningLightLevels; short *LightningLightLevels;
}; };
void P_StartLightning (); void P_StartLightning ();

View file

@ -82,7 +82,7 @@ struct F3DFloor
planeref bottom; planeref bottom;
planeref top; planeref top;
unsigned char *toplightlevel; short *toplightlevel;
fixed_t delta; fixed_t delta;
@ -110,7 +110,7 @@ struct F3DFloor
struct lightlist_t struct lightlist_t
{ {
secplane_t plane; secplane_t plane;
unsigned char * p_lightlevel; short * p_lightlevel;
FDynamicColormap * extra_colormap; FDynamicColormap * extra_colormap;
PalEntry blend; PalEntry blend;
int flags; int flags;

View file

@ -110,15 +110,15 @@ DFireFlicker::DFireFlicker (sector_t *sector)
: DLighting (sector) : DLighting (sector)
{ {
m_MaxLight = sector->lightlevel; m_MaxLight = sector->lightlevel;
m_MinLight = MIN (sector->FindMinSurroundingLight (sector->lightlevel)+16, 255); m_MinLight = sector_t::ClampLight(sector->FindMinSurroundingLight(sector->lightlevel) + 16);
m_Count = 4; m_Count = 4;
} }
DFireFlicker::DFireFlicker (sector_t *sector, int upper, int lower) DFireFlicker::DFireFlicker (sector_t *sector, int upper, int lower)
: DLighting (sector) : DLighting (sector)
{ {
m_MaxLight = clamp (upper, 0, 255); m_MaxLight = sector_t::ClampLight(upper);
m_MinLight = clamp (lower, 0, 255); m_MinLight = sector_t::ClampLight(lower);
m_Count = 4; m_Count = 4;
} }
@ -260,8 +260,8 @@ DLightFlash::DLightFlash (sector_t *sector, int min, int max)
: DLighting (sector) : DLighting (sector)
{ {
// Use specified light levels. // Use specified light levels.
m_MaxLight = clamp (max, 0, 255); m_MaxLight = sector_t::ClampLight(max);
m_MinLight = clamp (min, 0, 255); m_MinLight = sector_t::ClampLight(min);
m_MaxTime = 64; m_MaxTime = 64;
m_MinTime = 7; m_MinTime = 7;
m_Count = (pr_lightflash() & m_MaxTime) + 1; m_Count = (pr_lightflash() & m_MaxTime) + 1;
@ -320,8 +320,8 @@ DStrobe::DStrobe (sector_t *sector, int upper, int lower, int utics, int ltics)
{ {
m_DarkTime = ltics; m_DarkTime = ltics;
m_BrightTime = utics; m_BrightTime = utics;
m_MaxLight = clamp (upper, 0, 255); m_MaxLight = sector_t::ClampLight(upper);
m_MinLight = clamp (lower, 0, 255); m_MinLight = sector_t::ClampLight(lower);
m_Count = 1; // Hexen-style is always in sync m_Count = 1; // Hexen-style is always in sync
} }
@ -513,7 +513,7 @@ void EV_LightTurnOnPartway (int tag, fixed_t frac)
// //
// [RH] New function to adjust tagged sectors' light levels // [RH] New function to adjust tagged sectors' light levels
// by a relative amount. Light levels are clipped to // by a relative amount. Light levels are clipped to
// within the range 0-255 inclusive. // be within range for sector_t::lightlevel.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -523,8 +523,7 @@ void EV_LightChange (int tag, int value)
while ((secnum = P_FindSectorFromTag (tag, secnum)) >= 0) while ((secnum = P_FindSectorFromTag (tag, secnum)) >= 0)
{ {
int newlight = sectors[secnum].lightlevel + value; sectors[secnum].SetLightLevel(sectors[secnum].lightlevel + value);
sectors[secnum].SetLightLevel(newlight);
} }
} }
@ -651,8 +650,8 @@ void DGlow2::Tick ()
DGlow2::DGlow2 (sector_t *sector, int start, int end, int tics, bool oneshot) DGlow2::DGlow2 (sector_t *sector, int start, int end, int tics, bool oneshot)
: DLighting (sector) : DLighting (sector)
{ {
m_Start = clamp (start, 0, 255); m_Start = sector_t::ClampLight(start);
m_End = clamp (end, 0, 255); m_End = sector_t::ClampLight(end);
m_MaxTics = tics; m_MaxTics = tics;
m_Tics = -1; m_Tics = -1;
m_OneShot = oneshot; m_OneShot = oneshot;

View file

@ -315,9 +315,18 @@ void P_SerializeWorld (FArchive &arc)
for (i = 0, sec = sectors; i < numsectors; i++, sec++) for (i = 0, sec = sectors; i < numsectors; i++, sec++)
{ {
arc << sec->floorplane arc << sec->floorplane
<< sec->ceilingplane << sec->ceilingplane;
<< sec->lightlevel if (SaveVersion < 3223)
<< sec->special {
BYTE bytelight;
arc << bytelight;
sec->lightlevel = bytelight;
}
else
{
arc << sec->lightlevel;
}
arc << sec->special
<< sec->tag << sec->tag
<< sec->soundtraversed << sec->soundtraversed
<< sec->seqType << sec->seqType

View file

@ -1483,7 +1483,7 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex)
ss->ceilingplane.ic = -FRACUNIT; ss->ceilingplane.ic = -FRACUNIT;
SetTexture(ss, i, sector_t::floor, ms->floorpic, missingtex); SetTexture(ss, i, sector_t::floor, ms->floorpic, missingtex);
SetTexture(ss, i, sector_t::ceiling, ms->ceilingpic, missingtex); SetTexture(ss, i, sector_t::ceiling, ms->ceilingpic, missingtex);
ss->lightlevel = (BYTE)clamp (LittleShort(ms->lightlevel), (short)0, (short)255); ss->lightlevel = LittleShort(ms->lightlevel);
if (map->HasBehavior) if (map->HasBehavior)
ss->special = LittleShort(ms->special); ss->special = LittleShort(ms->special);
else // [RH] Translate to new sector special else // [RH] Translate to new sector special

View file

@ -695,12 +695,12 @@ public:
void Tick (); void Tick ();
protected: protected:
static void DoTransfer (BYTE level, int target, bool floor); static void DoTransfer (int level, int target, bool floor);
BYTE LastLight;
sector_t *Source; sector_t *Source;
int TargetTag; int TargetTag;
bool CopyFloor; bool CopyFloor;
short LastLight;
}; };
IMPLEMENT_CLASS (DLightTransfer) IMPLEMENT_CLASS (DLightTransfer)
@ -708,7 +708,17 @@ IMPLEMENT_CLASS (DLightTransfer)
void DLightTransfer::Serialize (FArchive &arc) void DLightTransfer::Serialize (FArchive &arc)
{ {
Super::Serialize (arc); Super::Serialize (arc);
arc << LastLight << Source << TargetTag << CopyFloor; if (SaveVersion < 3223)
{
BYTE bytelight;
arc << bytelight;
LastLight = bytelight;
}
else
{
arc << LastLight;
}
arc << Source << TargetTag << CopyFloor;
} }
DLightTransfer::DLightTransfer (sector_t *srcSec, int target, bool copyFloor) DLightTransfer::DLightTransfer (sector_t *srcSec, int target, bool copyFloor)
@ -735,7 +745,7 @@ DLightTransfer::DLightTransfer (sector_t *srcSec, int target, bool copyFloor)
void DLightTransfer::Tick () void DLightTransfer::Tick ()
{ {
BYTE light = Source->lightlevel; int light = Source->lightlevel;
if (light != LastLight) if (light != LastLight)
{ {
@ -744,7 +754,7 @@ void DLightTransfer::Tick ()
} }
} }
void DLightTransfer::DoTransfer (BYTE level, int target, bool floor) void DLightTransfer::DoTransfer (int level, int target, bool floor)
{ {
int secnum; int secnum;
@ -778,12 +788,12 @@ public:
void Tick (); void Tick ();
protected: protected:
static void DoTransfer (BYTE level, int target, BYTE flags); static void DoTransfer (short level, int target, BYTE flags);
BYTE LastLight;
BYTE Flags;
sector_t *Source; sector_t *Source;
int TargetID; int TargetID;
short LastLight;
BYTE Flags;
}; };
IMPLEMENT_CLASS (DWallLightTransfer) IMPLEMENT_CLASS (DWallLightTransfer)
@ -791,7 +801,17 @@ IMPLEMENT_CLASS (DWallLightTransfer)
void DWallLightTransfer::Serialize (FArchive &arc) void DWallLightTransfer::Serialize (FArchive &arc)
{ {
Super::Serialize (arc); Super::Serialize (arc);
arc << LastLight << Source << TargetID << Flags; if (SaveVersion < 3223)
{
BYTE bytelight;
arc << bytelight;
LastLight = bytelight;
}
else
{
arc << LastLight;
}
arc << Source << TargetID << Flags;
} }
DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags) DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags)
@ -802,10 +822,16 @@ DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags
Source = srcSec; Source = srcSec;
TargetID = target; TargetID = target;
Flags = flags; Flags = flags;
DoTransfer (LastLight = srcSec->lightlevel, target, Flags); DoTransfer (LastLight = srcSec->GetLightLevel(), target, Flags);
if (!(flags&WLF_NOFAKECONTRAST)) wallflags = WALLF_ABSLIGHTING; if (!(flags & WLF_NOFAKECONTRAST))
else wallflags = WALLF_NOFAKECONTRAST|WALLF_ABSLIGHTING; {
wallflags = WALLF_ABSLIGHTING;
}
else
{
wallflags = WALLF_ABSLIGHTING | WALLF_NOFAKECONTRAST;
}
for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; ) for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; )
{ {
@ -824,7 +850,7 @@ DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags
void DWallLightTransfer::Tick () void DWallLightTransfer::Tick ()
{ {
BYTE light = Source->lightlevel; short light = sector_t::ClampLight(Source->lightlevel);
if (light != LastLight) if (light != LastLight)
{ {
@ -833,13 +859,13 @@ void DWallLightTransfer::Tick ()
} }
} }
void DWallLightTransfer::DoTransfer (BYTE lightlevel, int target, BYTE flags) void DWallLightTransfer::DoTransfer (short lightlevel, int target, BYTE flags)
{ {
int linenum; int linenum;
for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; ) for (linenum = -1; (linenum = P_FindLineFromID (target, linenum)) >= 0; )
{ {
line_t * line = &lines[linenum]; line_t *line = &lines[linenum];
if (flags & WLF_SIDE1 && line->sidedef[0] != NULL) if (flags & WLF_SIDE1 && line->sidedef[0] != NULL)
{ {

View file

@ -1122,7 +1122,7 @@ public:
continue; continue;
case NAME_Lightlevel: case NAME_Lightlevel:
sec->lightlevel = (BYTE)clamp<int>(CheckInt(key), 0, 255); sec->lightlevel = sector_t::ClampLight(CheckInt(key));
continue; continue;
case NAME_Special: case NAME_Special:

View file

@ -320,7 +320,7 @@ int GetFloorLight (const sector_t *sec)
} }
else else
{ {
return clamp (sec->lightlevel + sec->GetPlaneLight(sector_t::floor), 0, 255); return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::floor));
} }
} }
@ -332,7 +332,7 @@ int GetCeilingLight (const sector_t *sec)
} }
else else
{ {
return clamp (sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling), 0, 255); return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling));
} }
} }

View file

@ -611,14 +611,19 @@ struct sector_t
)? heightsec : NULL; )? heightsec : NULL;
} }
static inline short ClampLight(int level)
{
return (short)clamp(level, SHRT_MIN, SHRT_MAX);
}
void ChangeLightLevel(int newval) void ChangeLightLevel(int newval)
{ {
lightlevel = (BYTE)clamp(lightlevel + newval, 0, 255); lightlevel = ClampLight(lightlevel + newval);
} }
void SetLightLevel(int newval) void SetLightLevel(int newval)
{ {
lightlevel = (BYTE)clamp(newval, 0, 255); lightlevel = ClampLight(newval);
} }
int GetLightLevel() const int GetLightLevel() const
@ -644,17 +649,17 @@ struct sector_t
// [RH] give floor and ceiling even more properties // [RH] give floor and ceiling even more properties
FDynamicColormap *ColorMap; // [RH] Per-sector colormap FDynamicColormap *ColorMap; // [RH] Per-sector colormap
BYTE lightlevel;
TObjPtr<AActor> SoundTarget; TObjPtr<AActor> SoundTarget;
BYTE soundtraversed; // 0 = untraversed, 1,2 = sndlines -1
short special; short special;
short tag; short tag;
short lightlevel;
short seqType; // this sector's sound sequence
int nexttag,firsttag; // killough 1/30/98: improves searches for tags. int nexttag,firsttag; // killough 1/30/98: improves searches for tags.
int sky; int sky;
short seqType; // this sector's sound sequence
FNameNoInit SeqName; // Sound sequence name. Setting seqType non-negative will override this. FNameNoInit SeqName; // Sound sequence name. Setting seqType non-negative will override this.
fixed_t soundorg[2]; // origin for any sounds played by the sector fixed_t soundorg[2]; // origin for any sounds played by the sector
@ -680,6 +685,7 @@ struct sector_t
}; };
TObjPtr<DInterpolation> interpolations[4]; TObjPtr<DInterpolation> interpolations[4];
BYTE soundtraversed; // 0 = untraversed, 1,2 = sndlines -1
// jff 2/26/98 lockout machinery for stairbuilding // jff 2/26/98 lockout machinery for stairbuilding
SBYTE stairlock; // -2 on first locked -1 after thinker done 0 normally SBYTE stairlock; // -2 on first locked -1 after thinker done 0 normally
SWORD prevsec; // -1 or number of sector for previous step SWORD prevsec; // -1 or number of sector for previous step

View file

@ -2056,7 +2056,7 @@ int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const
{ {
if (Flags & WALLF_ABSLIGHTING) if (Flags & WALLF_ABSLIGHTING)
{ {
baselight = (BYTE)Light; baselight = Light;
} }
if (pfakecontrast != NULL) if (pfakecontrast != NULL)
@ -2098,7 +2098,7 @@ int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const
baselight += this->Light; baselight += this->Light;
} }
} }
return clamp(baselight, 0, 255); return baselight;
} }