- 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 > 4) newself = 8;
else if (newself < 0) newself = 0; else if (newself < 0) newself = 0;
if (self != newself) self = newself; 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.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.brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog;
level.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces; level.lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces;
level.notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill; 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 struct level_info_t
{ {
int levelnum; int levelnum;
@ -395,7 +408,7 @@ struct level_info_t
TArray<FString> EventHandlers; TArray<FString> EventHandlers;
int8_t lightmode; ELightMode lightmode;
int8_t brightfog; int8_t brightfog;
int8_t lightadditivesurfaces; int8_t lightadditivesurfaces;
int8_t notexturefill; int8_t notexturefill;

View File

@ -47,9 +47,9 @@
struct FLevelLocals struct FLevelLocals
{ {
void Tick (); void Tick();
void Mark(); void Mark();
void AddScroller (int secnum); void AddScroller(int secnum);
void SetInterMusic(const char *nextmap); void SetInterMusic(const char *nextmap);
void SetMusicVolume(float v); void SetMusicVolume(float v);
@ -87,7 +87,7 @@ struct FLevelLocals
TArray<node_t> gamenodes; TArray<node_t> gamenodes;
node_t *headgamenode; node_t *headgamenode;
TArray<uint8_t> rejectmatrix; TArray<uint8_t> rejectmatrix;
static const int BODYQUESIZE = 32; static const int BODYQUESIZE = 32;
TObjPtr<AActor*> bodyque[BODYQUESIZE]; TObjPtr<AActor*> bodyque[BODYQUESIZE];
int bodyqueslot; int bodyqueslot;
@ -100,7 +100,7 @@ struct FLevelLocals
FDisplacementTable Displacements; FDisplacementTable Displacements;
FPortalBlockmap PortalBlockmap; FPortalBlockmap PortalBlockmap;
TArray<FLinePortal*> linkedPortals; // only the linked portals, this is used to speed up looking for them in P_CollectConnectedGroups. TArray<FLinePortal*> linkedPortals; // only the linked portals, this is used to speed up looking for them in P_CollectConnectedGroups.
TArray<FSectorPortalGroup *> portalGroups; TArray<FSectorPortalGroup *> portalGroups;
TArray<FLinePortalSpan> linePortalSpans; TArray<FLinePortalSpan> linePortalSpans;
FSectionContainer sections; FSectionContainer sections;
@ -181,7 +181,7 @@ struct FLevelLocals
float MusicVolume; float MusicVolume;
// Hardware render stuff that can either be set via CVAR or MAPINFO // Hardware render stuff that can either be set via CVAR or MAPINFO
int lightmode; ELightMode lightmode;
bool brightfog; bool brightfog;
bool lightadditivesurfaces; bool lightadditivesurfaces;
bool notexturefill; bool notexturefill;
@ -192,7 +192,7 @@ struct FLevelLocals
node_t *HeadNode() const node_t *HeadNode() const
{ {
return nodes.Size() == 0? nullptr : &nodes[nodes.Size() - 1]; return nodes.Size() == 0 ? nullptr : &nodes[nodes.Size() - 1];
} }
node_t *HeadGamenode() const node_t *HeadGamenode() const
{ {
@ -202,9 +202,24 @@ struct FLevelLocals
// Returns true if level is loaded from saved game or is being revisited as a part of a hub // Returns true if level is loaded from saved game or is being revisited as a part of a hub
bool IsReentering() const bool IsReentering() const
{ {
return savegamerestore return savegamerestore
|| (info != nullptr && info->Snapshot.mBuffer != nullptr && info->isValid()); || (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; extern FLevelLocals level;

View File

@ -284,7 +284,7 @@ void level_info_t::Reset()
PrecacheSounds.Clear(); PrecacheSounds.Clear();
brightfog = -1; brightfog = -1;
lightmode = -1; lightmode = ELightMode::NotSet;
notexturefill = -1; notexturefill = -1;
lightadditivesurfaces = -1; lightadditivesurfaces = -1;
skyrotatevector = FVector3(0, 0, 1); skyrotatevector = FVector3(0, 0, 1);
@ -1381,9 +1381,9 @@ DEFINE_MAP_OPTION(lightmode, false)
parse.ParseAssign(); parse.ParseAssign();
parse.sc.MustGetNumber(); 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 else
{ {

View File

@ -127,7 +127,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
} }
else 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); float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(light, lightlevel); SetShaderLight(light, lightlevel);
@ -148,7 +148,7 @@ void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const F
SetFog(fogcolor, fogdensity); SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer. // 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); SetSoftLightLevel(255);
} }

View File

@ -326,7 +326,7 @@ public:
void SetSoftLightLevel(int llevel, int blendfactor = 0) 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; else mLightParms[3] = -1.f;
} }

View File

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

View File

@ -106,8 +106,8 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state) void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state)
{ {
int oldlightmode = level.lightmode; auto oldlightmode = level.lightmode;
if (!hudModelStep && level.lightmode >= 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that. if (!hudModelStep && level.isSoftwareLighting()) level.SetFallbackLightMode(); // Software lighting cannot handle 2D content.
for (auto &hudsprite : hudsprites) for (auto &hudsprite : hudsprites)
{ {
if ((!!hudsprite.mframe) == hudModelStep) 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); 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. // 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 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 // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite. // light mode here to draw the weapon sprite.
int oldlightmode = level.lightmode; auto oldlightmode = level.lightmode;
if (level.lightmode >= 8) level.lightmode = 2; if (level.isSoftwareLighting()) level.SetFallbackLightMode();
for (DPSprite *psp = player->psprites; psp != nullptr && psp->GetID() < PSP_TARGETCENTER; psp = psp->GetNext()) 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; 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) if (darklightmode && lightlevel < 192 && !weapon)
{ {
@ -130,7 +130,7 @@ PalEntry hw_CalcLightColor(int light, PalEntry pe, int blendfactor)
if (blendfactor == 0) if (blendfactor == 0)
{ {
if (level.lightmode >= 8) if (level.isSoftwareLighting())
{ {
return pe; return pe;
} }
@ -174,10 +174,10 @@ float hw_GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity,
{ {
float density; float density;
int lightmode = level.lightmode; auto lightmode = level.lightmode;
if (lightmode >= 8 && blendfactor > 0) lightmode = 2; // The blendfactor feature does not work with software-style lighting. 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. // uses approximations of Legacy's default settings.
density = level.fogdensity ? (float)level.fogdensity : 18; 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) else if ((fogcolor.d & 0xffffff) == 0)
{ {
// case 2: black fog // 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 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.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 // case 3: level has fog density set
} }
@ -269,7 +269,7 @@ bool hw_CheckFog(sector_t *frontsector, sector_t *backsector)
{ {
return false; 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 // case 3: level has fog density set
return false; return false;

View File

@ -430,7 +430,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
double fadelevel; 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. // 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.)); double map = (NUMCOLORMAPS * 2.) - ((lightlevel + 12) * (NUMCOLORMAPS / 128.));
fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0); fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0);