Revert "Snap light level to software values (32 levels)"

This reverts commit cc26d03c93.
This commit is contained in:
mazmazz 2018-09-09 13:43:00 -04:00
parent 675f69afea
commit aeb45132c5
5 changed files with 32 additions and 65 deletions

View file

@ -1810,10 +1810,9 @@ static int lib_pFadeLight(lua_State *L)
INT32 destvalue = (INT32)luaL_checkinteger(L, 2);
INT32 speed = (INT32)luaL_checkinteger(L, 3);
boolean ticbased = lua_optboolean(L, 4);
boolean exactlightlevel = lua_optboolean(L, 5);
NOHUD
INLEVEL
P_FadeLight(tag, destvalue, speed, ticbased, exactlightlevel);
P_FadeLight(tag, destvalue, speed, ticbased);
return 0;
}

View file

@ -15,7 +15,6 @@
#include "doomdef.h"
#include "doomstat.h" // gametic
#include "p_local.h"
#include "r_main.h" // LIGHTSEGSHIFT
#include "r_state.h"
#include "z_zone.h"
#include "m_random.h"
@ -332,10 +331,9 @@ glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector,
* \param speed Speed of the fade; the change to the ligh
* level in each sector per tic.
* \param ticbased Use a specific duration for the fade, defined by speed
* \param exactlightlevel Do not snap to software values (for OpenGL)
* \sa T_LightFade
*/
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel)
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased)
{
lightlevel_t *ll;
@ -355,8 +353,6 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean
ll->sector = sector;
ll->destlevel = destvalue;
ll->exactlightlevel = exactlightlevel;
ll->lightlevel = sector->lightlevel;
if (ticbased)
{
@ -374,12 +370,12 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean
}
}
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel)
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased)
{
INT32 i;
// search all sectors for ones with tag
for (i = -1; (i = P_FindSectorFromTag(tag, i)) >= 0 ;)
P_FadeLightBySector(&sectors[i], destvalue, speed, ticbased, exactlightlevel);
P_FadeLightBySector(&sectors[i], destvalue, speed, ticbased);
}
/** Fades the light level in a sector to a new value.
@ -389,66 +385,47 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, bool
*/
void T_LightFade(lightlevel_t *ll)
{
boolean stillfading = false;
INT16 lightlevel = ll->lightlevel;
if (ll->duration >= 0) // tic-based
{
stillfading = !(gametic - ll->firsttic >= ll->duration);
if (gametic - ll->firsttic >= ll->duration)
{
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else if (!((gametic - ll->firsttic) % ll->interval))
{
if (ll->speed < 0)
lightlevel = max(lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
ll->sector->lightlevel = max(ll->sector->lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
else
lightlevel = min(lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
ll->sector->lightlevel = min(ll->sector->lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
}
return;
}
else // x/tic speed-based
{
if (lightlevel < ll->destlevel)
{
// increase the lightlevel
if (lightlevel + ll->speed >= ll->destlevel)
{
// stop changing light level
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
{
stillfading = true;
lightlevel = (INT16)(lightlevel + (INT16)ll->speed); // move lightlevel
}
if (ll->sector->lightlevel < ll->destlevel)
{
// increase the lightlevel
if (ll->sector->lightlevel + ll->speed >= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
{
// decrease lightlevel
if (lightlevel - ll->speed <= ll->destlevel)
{
// stop changing light level
lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
{
stillfading = true;
lightlevel = (INT16)(lightlevel - (INT16)ll->speed); // move lightlevel
}
}
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel + (INT16)ll->speed); // move lightlevel
}
// Snap light level to software values
if (!stillfading || ll->exactlightlevel)
ll->sector->lightlevel = lightlevel;
else
ll->sector->lightlevel = (lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT;
{
// decrease lightlevel
if (ll->sector->lightlevel - ll->speed <= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
ll->lightlevel = lightlevel;
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel - (INT16)ll->speed); // move lightlevel
}
}

View file

@ -1542,8 +1542,6 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type)
WRITEINT32(save_p, ht->duration);
WRITEUINT32(save_p, ht->interval);
WRITEUINT32(save_p, (UINT32)ht->firsttic);
WRITEUINT8(save_p, (UINT8)ht->exactlightlevel);
WRITEINT16(save_p, ht->lightlevel);
}
//
@ -2520,8 +2518,6 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker)
ht->duration = READINT32(save_p);
ht->interval = READUINT32(save_p);
ht->firsttic = (tic_t)READUINT32(save_p);
ht->exactlightlevel = (boolean)READUINT8(save_p);
ht->lightlevel = READINT16(save_p);
if (ht->sector)
ht->sector->lightingdata = ht;
P_AddThinker(&ht->thinker);

View file

@ -2781,8 +2781,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
P_FadeLight(line->tag,
(line->flags & ML_DONTPEGBOTTOM) ? max(min(sides[line->sidenum[0]].textureoffset>>FRACBITS, 255), 0) : line->frontsector->lightlevel,
(line->flags & ML_DONTPEGBOTTOM) ? max(sides[line->sidenum[0]].rowoffset>>FRACBITS, 0) : P_AproxDistance(line->dx, line->dy)>>FRACBITS,
(line->flags & ML_EFFECT5),
(line->flags & ML_TFERLINE));
(line->flags & ML_EFFECT5));
break;
case 421: // Stop lighting effect in tagged sectors

View file

@ -143,10 +143,6 @@ typedef struct
INT32 duration; ///< If <0, do not use tic-based behavior. If 0, set instantly. If >0, fade lasts this duration.
UINT32 interval; ///< Interval to deduct light level
tic_t firsttic; ///< First gametic to count from
// Snap to software values
boolean exactlightlevel; ///< Use exact values for OpenGL
INT16 lightlevel; ///< Internal counter for fading
} lightlevel_t;
#define GLOWSPEED 8
@ -165,8 +161,8 @@ strobe_t * P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector
void T_Glow(glow_t *g);
glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, INT32 length);
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel);
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean exactlightlevel);
void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased);
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased);
void T_LightFade(lightlevel_t *ll);
typedef enum