- use symbolic constants for the light modes.

This commit is contained in:
Christoph Oelckers 2018-12-15 09:40:39 +01:00
parent 15949102da
commit 1187906a61
10 changed files with 62 additions and 34 deletions

View File

@ -127,7 +127,7 @@ CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL)
else if (newself > 4) newself = 8;
else if (newself < 0) newself = 0;
if (self != newself) self = newself;
else if ((level.info == nullptr || level.info->lightmode == -1)) level.lightmode = self;
else if ((level.info == nullptr || level.info->lightmode == ELightMode::NotSet)) level.lightmode = (ELightMode)*self;
}
@ -1523,7 +1523,7 @@ void G_InitLevelLocals ()
level.DefaultEnvironment = info->DefaultEnvironment;
level.lightmode = info->lightmode < 0? gl_lightmode : info->lightmode;
level.lightmode = info->lightmode == ELightMode::NotSet? (ELightMode)*gl_lightmode : info->lightmode;
level.brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog;
level.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces;
level.notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill;

View File

@ -314,6 +314,19 @@ struct FExitText
}
};
enum class ELightMode : int8_t
{
NotSet = -1,
LinearStandard = 0,
DoomBright = 1,
Doom = 2,
DoomDark = 3,
DoomLegacy = 4,
ZDoomSoftware = 8,
DoomSoftware = 16
};
struct level_info_t
{
int levelnum;
@ -395,7 +408,7 @@ struct level_info_t
TArray<FString> EventHandlers;
int8_t lightmode;
ELightMode lightmode;
int8_t brightfog;
int8_t lightadditivesurfaces;
int8_t notexturefill;

View File

@ -181,7 +181,7 @@ struct FLevelLocals
float MusicVolume;
// Hardware render stuff that can either be set via CVAR or MAPINFO
int lightmode;
ELightMode lightmode;
bool brightfog;
bool lightadditivesurfaces;
bool notexturefill;
@ -205,6 +205,21 @@ struct FLevelLocals
return savegamerestore
|| (info != nullptr && info->Snapshot.mBuffer != nullptr && info->isValid());
}
bool isSoftwareLighting() const
{
return lightmode >= ELightMode::ZDoomSoftware;
}
bool isDarkLightMode() const
{
return !!((int)lightmode & (int)ELightMode::Doom);
}
void SetFallbackLightMode()
{
lightmode = ELightMode::Doom;
}
};
extern FLevelLocals level;

View File

@ -284,7 +284,7 @@ void level_info_t::Reset()
PrecacheSounds.Clear();
brightfog = -1;
lightmode = -1;
lightmode = ELightMode::NotSet;
notexturefill = -1;
lightadditivesurfaces = -1;
skyrotatevector = FVector3(0, 0, 1);
@ -1381,9 +1381,9 @@ DEFINE_MAP_OPTION(lightmode, false)
parse.ParseAssign();
parse.sc.MustGetNumber();
if ((parse.sc.Number >= 0 && parse.sc.Number <= 4) || parse.sc.Number == 8)
if ((parse.sc.Number >= 0 && parse.sc.Number <= 4) || parse.sc.Number == 8 || parse.sc.Number == 16)
{
info->lightmode = uint8_t(parse.sc.Number);
info->lightmode = ELightMode(parse.sc.Number);
}
else
{

View File

@ -127,7 +127,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
}
else
{
if ((level.lightmode == 2 || (level.lightmode >= 8 && cmap->BlendFactor > 0)) && fogcolor == 0)
if ((level.lightmode == ELightMode::Doom || (level.isSoftwareLighting() && cmap->BlendFactor > 0)) && fogcolor == 0)
{
float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(light, lightlevel);
@ -148,7 +148,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer.
if (level.lightmode >= 8 && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
if (level.isSoftwareLighting() && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
{
SetSoftLightLevel(255);
}

View File

@ -326,7 +326,7 @@ public:
void SetSoftLightLevel(int llevel, int blendfactor = 0)
{
if (level.lightmode >= 8 && blendfactor == 0) mLightParms[3] = llevel / 255.f;
if (level.isSoftwareLighting() && blendfactor == 0) mLightParms[3] = llevel / 255.f;
else mLightParms[3] = -1.f;
}

View File

@ -164,10 +164,10 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
auto &vp = di->Viewpoint;
// We have no use for Doom lighting special handling here, so disable it for this function.
int oldlightmode = ::level.lightmode;
if (::level.lightmode >= 8)
auto oldlightmode = ::level.lightmode;
if (::level.isSoftwareLighting())
{
::level.lightmode = 2;
::level.SetFallbackLightMode();
state.SetSoftLightLevel(-1);
}

View File

@ -106,8 +106,8 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state)
{
int oldlightmode = level.lightmode;
if (!hudModelStep && level.lightmode >= 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that.
auto oldlightmode = level.lightmode;
if (!hudModelStep && level.isSoftwareLighting()) level.SetFallbackLightMode(); // Software lighting cannot handle 2D content.
for (auto &hudsprite : hudsprites)
{
if ((!!hudsprite.mframe) == hudModelStep)
@ -260,7 +260,7 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po
l.lightlevel = hw_CalcLightLevel(l.lightlevel, getExtraLight(), true, 0);
if (level.lightmode >= 8 || l.lightlevel < 92)
if (level.isSoftwareLighting() || l.lightlevel < 92)
{
// Korshun: the way based on max possible light level for sector like in software renderer.
double min_L = 36.0 / 31.0 - ((l.lightlevel / 255.0) * (63.0 / 31.0)); // Lightlevel in range 0-63
@ -498,8 +498,8 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite.
int oldlightmode = level.lightmode;
if (level.lightmode >= 8) level.lightmode = 2;
auto oldlightmode = level.lightmode;
if (level.isSoftwareLighting()) level.SetFallbackLightMode();
for (DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext())
{

View File

@ -88,7 +88,7 @@ int hw_CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor
if (lightlevel == 0) return 0;
bool darklightmode = (level.lightmode & 2) || (level.lightmode >= 8 && blendfactor > 0);
bool darklightmode = (level.isDarkLightMode()) || (level.isSoftwareLighting() && blendfactor > 0);
if (darklightmode && lightlevel < 192 && !weapon)
{
@ -130,7 +130,7 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor)
if (blendfactor == 0)
{
if (level.lightmode >= 8)
if (level.isSoftwareLighting())
{
return pe;
}
@ -174,10 +174,10 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
{
float density;
int lightmode = level.lightmode;
if (lightmode >= 8 && blendfactor > 0) lightmode = 2; // The blendfactor feature does not work with software-style lighting.
auto lightmode = level.lightmode;
if (level.isSoftwareLighting() && blendfactor > 0) lightmode = ELightMode::Doom; // The blendfactor feature does not work with software-style lighting.
if (lightmode & 4)
if (lightmode == ELightMode::DoomLegacy)
{
// uses approximations of Legacy's default settings.
density = level.fogdensity ? (float)level.fogdensity : 18;
@ -190,9 +190,9 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
else if ((fogcolor.d & 0xffffff) == 0)
{
// case 2: black fog
if ((lightmode < 8 || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE))
if ((!level.isSoftwareLighting() || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE))
{
density = distfogtable[level.lightmode != 0][hw_ClampLight(lightlevel)];
density = distfogtable[level.lightmode != ELightMode::LinearStandard][hw_ClampLight(lightlevel)];
}
else
{
@ -250,7 +250,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff))
{
}
else if (level.fogdensity!=0 || (level.lightmode & 4))
else if (level.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy)
{
// case 3: level has fog density set
}
@ -269,7 +269,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
{
return false;
}
else if (level.fogdensity!=0 || (level.lightmode & 4))
else if (level.fogdensity!=0 || level.lightmode == ELightMode::DoomLegacy)
{
// case 3: level has fog density set
return false;

View File

@ -430,7 +430,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
double fadelevel;
// The hardware renderer's light modes 0, 1 and 4 use a linear light scale which must be used here as well. Otherwise the automap gets too dark.
if (vid_rendermode != 4 || (level.lightmode >= 2 && level.lightmode != 4))
if (vid_rendermode != 4 || level.isDarkLightMode() || level.isSoftwareLighting())
{
double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.));
fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0);