- made the glow getter functions members of sector_t.

This commit is contained in:
Christoph Oelckers 2018-04-02 13:36:28 +02:00
commit 52c5328412
15 changed files with 119 additions and 183 deletions

View file

@ -3,7 +3,7 @@
// Copyright 1993-1996 id Software
// Copyright 1998-1998 Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2017 Christoph Oelckers
// Copyright 2002-2018 Christoph Oelckers
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -1527,6 +1527,112 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt)
}
//==========================================================================
//
// Checks whether a sprite should be affected by a glow
//
//==========================================================================
int sector_t::CheckSpriteGlow(int lightlevel, const DVector3 &pos)
{
float bottomglowcolor[4];
bottomglowcolor[3] = 0;
auto c = planes[sector_t::floor].GlowColor;
if (c == 0)
{
FTexture *tex = TexMan[GetTexture(sector_t::floor)];
if (tex != NULL && tex->isGlowing())
{
if (!tex->bAutoGlowing) tex = TexMan(GetTexture(sector_t::floor));
if (tex->isGlowing()) // recheck the current animation frame.
{
tex->GetGlowColor(bottomglowcolor);
bottomglowcolor[3] = (float)tex->GlowHeight;
}
}
}
else if (c != ~0u)
{
bottomglowcolor[0] = c.r / 255.f;
bottomglowcolor[1] = c.g / 255.f;
bottomglowcolor[2] = c.b / 255.f;
bottomglowcolor[3] = planes[sector_t::floor].GlowHeight;
}
if (bottomglowcolor[3]> 0)
{
double floordiff = pos.Z - floorplane.ZatPoint(pos);
if (floordiff < bottomglowcolor[3])
{
int maxlight = (255 + lightlevel) >> 1;
double lightfrac = floordiff / bottomglowcolor[3];
if (lightfrac < 0) lightfrac = 0;
lightlevel = int(lightfrac*lightlevel + maxlight * (1 - lightfrac));
}
}
return lightlevel;
}
//==========================================================================
//
// Checks whether a wall should glow
//
//==========================================================================
bool sector_t::GetWallGlow(float *topglowcolor, float *bottomglowcolor)
{
bool ret = false;
bottomglowcolor[3] = topglowcolor[3] = 0;
auto c = planes[sector_t::ceiling].GlowColor;
if (c == 0)
{
FTexture *tex = TexMan[GetTexture(sector_t::ceiling)];
if (tex != NULL && tex->isGlowing())
{
if (!tex->bAutoGlowing) tex = TexMan(GetTexture(sector_t::ceiling));
if (tex->isGlowing()) // recheck the current animation frame.
{
ret = true;
tex->GetGlowColor(topglowcolor);
topglowcolor[3] = (float)tex->GlowHeight;
}
}
}
else if (c != ~0u)
{
topglowcolor[0] = c.r / 255.f;
topglowcolor[1] = c.g / 255.f;
topglowcolor[2] = c.b / 255.f;
topglowcolor[3] = planes[sector_t::ceiling].GlowHeight;
ret = topglowcolor[3] > 0;
}
c = planes[sector_t::floor].GlowColor;
if (c == 0)
{
FTexture *tex = TexMan[GetTexture(sector_t::floor)];
if (tex != NULL && tex->isGlowing())
{
if (!tex->bAutoGlowing) tex = TexMan(GetTexture(sector_t::floor));
if (tex->isGlowing()) // recheck the current animation frame.
{
ret = true;
tex->GetGlowColor(bottomglowcolor);
bottomglowcolor[3] = (float)tex->GlowHeight;
}
}
}
else if (c != ~0u)
{
bottomglowcolor[0] = c.r / 255.f;
bottomglowcolor[1] = c.g / 255.f;
bottomglowcolor[2] = c.b / 255.f;
bottomglowcolor[3] = planes[sector_t::floor].GlowHeight;
ret = bottomglowcolor[3] > 0;
}
return ret;
}
//===========================================================================
//
//