mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 13:01:47 +00:00
Fixed: Light levels outside the range [0,255] really do matter.
SVN r3223 (trunk)
This commit is contained in:
parent
f69181f851
commit
ee8ca0de87
11 changed files with 97 additions and 48 deletions
|
@ -21,7 +21,7 @@ DLightningThinker::DLightningThinker ()
|
|||
LightningFlashCount = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ DLightningThinker::~DLightningThinker ()
|
|||
void DLightningThinker::Serialize (FArchive &arc)
|
||||
{
|
||||
int i;
|
||||
BYTE *lights;
|
||||
short *lights;
|
||||
|
||||
Super::Serialize (arc);
|
||||
|
||||
|
@ -48,13 +48,22 @@ void DLightningThinker::Serialize (FArchive &arc)
|
|||
{
|
||||
delete[] LightningLightLevels;
|
||||
}
|
||||
LightningLightLevels = new BYTE[numsectors + (numsectors+7)/8];
|
||||
LightningLightLevels = new short[numsectors + (numsectors+7)/8];
|
||||
}
|
||||
lights = LightningLightLevels;
|
||||
for (i = (numsectors + (numsectors+7)/8); i > 0; ++lights, --i)
|
||||
{
|
||||
if (SaveVersion < 3223)
|
||||
{
|
||||
BYTE bytelight;
|
||||
arc << bytelight;
|
||||
*lights = bytelight;
|
||||
}
|
||||
else
|
||||
{
|
||||
arc << *lights;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DLightningThinker::Tick ()
|
||||
|
|
|
@ -24,7 +24,7 @@ protected:
|
|||
int NextLightningFlash;
|
||||
int LightningFlashCount;
|
||||
bool Stopped;
|
||||
BYTE *LightningLightLevels;
|
||||
short *LightningLightLevels;
|
||||
};
|
||||
|
||||
void P_StartLightning ();
|
||||
|
|
|
@ -82,7 +82,7 @@ struct F3DFloor
|
|||
planeref bottom;
|
||||
planeref top;
|
||||
|
||||
unsigned char *toplightlevel;
|
||||
short *toplightlevel;
|
||||
|
||||
fixed_t delta;
|
||||
|
||||
|
@ -110,7 +110,7 @@ struct F3DFloor
|
|||
struct lightlist_t
|
||||
{
|
||||
secplane_t plane;
|
||||
unsigned char * p_lightlevel;
|
||||
short * p_lightlevel;
|
||||
FDynamicColormap * extra_colormap;
|
||||
PalEntry blend;
|
||||
int flags;
|
||||
|
|
|
@ -110,15 +110,15 @@ DFireFlicker::DFireFlicker (sector_t *sector)
|
|||
: DLighting (sector)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
DFireFlicker::DFireFlicker (sector_t *sector, int upper, int lower)
|
||||
: DLighting (sector)
|
||||
{
|
||||
m_MaxLight = clamp (upper, 0, 255);
|
||||
m_MinLight = clamp (lower, 0, 255);
|
||||
m_MaxLight = sector_t::ClampLight(upper);
|
||||
m_MinLight = sector_t::ClampLight(lower);
|
||||
m_Count = 4;
|
||||
}
|
||||
|
||||
|
@ -260,8 +260,8 @@ DLightFlash::DLightFlash (sector_t *sector, int min, int max)
|
|||
: DLighting (sector)
|
||||
{
|
||||
// Use specified light levels.
|
||||
m_MaxLight = clamp (max, 0, 255);
|
||||
m_MinLight = clamp (min, 0, 255);
|
||||
m_MaxLight = sector_t::ClampLight(max);
|
||||
m_MinLight = sector_t::ClampLight(min);
|
||||
m_MaxTime = 64;
|
||||
m_MinTime = 7;
|
||||
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_BrightTime = utics;
|
||||
m_MaxLight = clamp (upper, 0, 255);
|
||||
m_MinLight = clamp (lower, 0, 255);
|
||||
m_MaxLight = sector_t::ClampLight(upper);
|
||||
m_MinLight = sector_t::ClampLight(lower);
|
||||
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
|
||||
// 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)
|
||||
{
|
||||
int newlight = sectors[secnum].lightlevel + value;
|
||||
sectors[secnum].SetLightLevel(newlight);
|
||||
sectors[secnum].SetLightLevel(sectors[secnum].lightlevel + value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -651,8 +650,8 @@ void DGlow2::Tick ()
|
|||
DGlow2::DGlow2 (sector_t *sector, int start, int end, int tics, bool oneshot)
|
||||
: DLighting (sector)
|
||||
{
|
||||
m_Start = clamp (start, 0, 255);
|
||||
m_End = clamp (end, 0, 255);
|
||||
m_Start = sector_t::ClampLight(start);
|
||||
m_End = sector_t::ClampLight(end);
|
||||
m_MaxTics = tics;
|
||||
m_Tics = -1;
|
||||
m_OneShot = oneshot;
|
||||
|
|
|
@ -315,9 +315,18 @@ void P_SerializeWorld (FArchive &arc)
|
|||
for (i = 0, sec = sectors; i < numsectors; i++, sec++)
|
||||
{
|
||||
arc << sec->floorplane
|
||||
<< sec->ceilingplane
|
||||
<< sec->lightlevel
|
||||
<< sec->special
|
||||
<< sec->ceilingplane;
|
||||
if (SaveVersion < 3223)
|
||||
{
|
||||
BYTE bytelight;
|
||||
arc << bytelight;
|
||||
sec->lightlevel = bytelight;
|
||||
}
|
||||
else
|
||||
{
|
||||
arc << sec->lightlevel;
|
||||
}
|
||||
arc << sec->special
|
||||
<< sec->tag
|
||||
<< sec->soundtraversed
|
||||
<< sec->seqType
|
||||
|
|
|
@ -1483,7 +1483,7 @@ void P_LoadSectors (MapData *map, FMissingTextureTracker &missingtex)
|
|||
ss->ceilingplane.ic = -FRACUNIT;
|
||||
SetTexture(ss, i, sector_t::floor, ms->floorpic, 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)
|
||||
ss->special = LittleShort(ms->special);
|
||||
else // [RH] Translate to new sector special
|
||||
|
|
|
@ -695,12 +695,12 @@ public:
|
|||
void Tick ();
|
||||
|
||||
protected:
|
||||
static void DoTransfer (BYTE level, int target, bool floor);
|
||||
static void DoTransfer (int level, int target, bool floor);
|
||||
|
||||
BYTE LastLight;
|
||||
sector_t *Source;
|
||||
int TargetTag;
|
||||
bool CopyFloor;
|
||||
short LastLight;
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS (DLightTransfer)
|
||||
|
@ -708,7 +708,17 @@ IMPLEMENT_CLASS (DLightTransfer)
|
|||
void DLightTransfer::Serialize (FArchive &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)
|
||||
|
@ -735,7 +745,7 @@ DLightTransfer::DLightTransfer (sector_t *srcSec, int target, bool copyFloor)
|
|||
|
||||
void DLightTransfer::Tick ()
|
||||
{
|
||||
BYTE light = Source->lightlevel;
|
||||
int light = Source->lightlevel;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -778,12 +788,12 @@ public:
|
|||
void Tick ();
|
||||
|
||||
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;
|
||||
int TargetID;
|
||||
short LastLight;
|
||||
BYTE Flags;
|
||||
};
|
||||
|
||||
IMPLEMENT_CLASS (DWallLightTransfer)
|
||||
|
@ -791,7 +801,17 @@ IMPLEMENT_CLASS (DWallLightTransfer)
|
|||
void DWallLightTransfer::Serialize (FArchive &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)
|
||||
|
@ -802,10 +822,16 @@ DWallLightTransfer::DWallLightTransfer (sector_t *srcSec, int target, BYTE flags
|
|||
Source = srcSec;
|
||||
TargetID = target;
|
||||
Flags = flags;
|
||||
DoTransfer (LastLight = srcSec->lightlevel, target, Flags);
|
||||
DoTransfer (LastLight = srcSec->GetLightLevel(), target, Flags);
|
||||
|
||||
if (!(flags&WLF_NOFAKECONTRAST)) wallflags = WALLF_ABSLIGHTING;
|
||||
else wallflags = WALLF_NOFAKECONTRAST|WALLF_ABSLIGHTING;
|
||||
if (!(flags & WLF_NOFAKECONTRAST))
|
||||
{
|
||||
wallflags = WALLF_ABSLIGHTING;
|
||||
}
|
||||
else
|
||||
{
|
||||
wallflags = WALLF_ABSLIGHTING | WALLF_NOFAKECONTRAST;
|
||||
}
|
||||
|
||||
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 ()
|
||||
{
|
||||
BYTE light = Source->lightlevel;
|
||||
short light = sector_t::ClampLight(Source->lightlevel);
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -1122,7 +1122,7 @@ public:
|
|||
continue;
|
||||
|
||||
case NAME_Lightlevel:
|
||||
sec->lightlevel = (BYTE)clamp<int>(CheckInt(key), 0, 255);
|
||||
sec->lightlevel = sector_t::ClampLight(CheckInt(key));
|
||||
continue;
|
||||
|
||||
case NAME_Special:
|
||||
|
|
|
@ -320,7 +320,7 @@ int GetFloorLight (const sector_t *sec)
|
|||
}
|
||||
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
|
||||
{
|
||||
return clamp (sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling), 0, 255);
|
||||
return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
src/r_defs.h
16
src/r_defs.h
|
@ -611,14 +611,19 @@ struct sector_t
|
|||
)? heightsec : NULL;
|
||||
}
|
||||
|
||||
static inline short ClampLight(int level)
|
||||
{
|
||||
return (short)clamp(level, SHRT_MIN, SHRT_MAX);
|
||||
}
|
||||
|
||||
void ChangeLightLevel(int newval)
|
||||
{
|
||||
lightlevel = (BYTE)clamp(lightlevel + newval, 0, 255);
|
||||
lightlevel = ClampLight(lightlevel + newval);
|
||||
}
|
||||
|
||||
void SetLightLevel(int newval)
|
||||
{
|
||||
lightlevel = (BYTE)clamp(newval, 0, 255);
|
||||
lightlevel = ClampLight(newval);
|
||||
}
|
||||
|
||||
int GetLightLevel() const
|
||||
|
@ -644,17 +649,17 @@ struct sector_t
|
|||
// [RH] give floor and ceiling even more properties
|
||||
FDynamicColormap *ColorMap; // [RH] Per-sector colormap
|
||||
|
||||
BYTE lightlevel;
|
||||
|
||||
TObjPtr<AActor> SoundTarget;
|
||||
BYTE soundtraversed; // 0 = untraversed, 1,2 = sndlines -1
|
||||
|
||||
short special;
|
||||
short tag;
|
||||
short lightlevel;
|
||||
short seqType; // this sector's sound sequence
|
||||
|
||||
int nexttag,firsttag; // killough 1/30/98: improves searches for tags.
|
||||
|
||||
int sky;
|
||||
short seqType; // this sector's sound sequence
|
||||
FNameNoInit SeqName; // Sound sequence name. Setting seqType non-negative will override this.
|
||||
|
||||
fixed_t soundorg[2]; // origin for any sounds played by the sector
|
||||
|
@ -680,6 +685,7 @@ struct sector_t
|
|||
};
|
||||
TObjPtr<DInterpolation> interpolations[4];
|
||||
|
||||
BYTE soundtraversed; // 0 = untraversed, 1,2 = sndlines -1
|
||||
// jff 2/26/98 lockout machinery for stairbuilding
|
||||
SBYTE stairlock; // -2 on first locked -1 after thinker done 0 normally
|
||||
SWORD prevsec; // -1 or number of sector for previous step
|
||||
|
|
|
@ -2056,7 +2056,7 @@ int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const
|
|||
{
|
||||
if (Flags & WALLF_ABSLIGHTING)
|
||||
{
|
||||
baselight = (BYTE)Light;
|
||||
baselight = Light;
|
||||
}
|
||||
|
||||
if (pfakecontrast != NULL)
|
||||
|
@ -2098,7 +2098,7 @@ int side_t::GetLightLevel (bool foggy, int baselight, int *pfakecontrast) const
|
|||
baselight += this->Light;
|
||||
}
|
||||
}
|
||||
return clamp(baselight, 0, 255);
|
||||
return baselight;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue