Merge branch 'lightfade-ticbased' into le-fadefof

This commit is contained in:
mazmazz 2018-09-16 08:20:57 -04:00
commit 7c8fa151c4
3 changed files with 27 additions and 59 deletions

View file

@ -327,7 +327,8 @@ glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector,
*
* \param sector Target sector
* \param destvalue The final light value in these sectors.
* \param speed Speed of the fade; the change to the ligh
* \param speed If tic-based: total duration of effect.
* If speed-based: 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
* \sa T_LightFade
@ -354,16 +355,19 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean
ll->sourcelevel = sector->lightlevel;
ll->destlevel = destvalue;
ll->fixedcurlevel = sector->lightlevel<<FRACBITS;
if (ticbased)
{
ll->ticbased = true;
ll->timer = ll->speed = abs(speed); // use ll->speed for total duration
// Speed means duration.
ll->timer = abs(speed);
ll->fixedpertic = FixedDiv((destvalue<<FRACBITS) - ll->fixedcurlevel, speed<<FRACBITS);
}
else
{
ll->ticbased = false;
ll->timer = -1;
ll->speed = abs(speed);
// Speed means increment per tic (literally speed).
ll->timer = FixedDiv((destvalue<<FRACBITS) - ll->fixedcurlevel, speed<<FRACBITS)>>FRACBITS;
ll->fixedpertic = speed<<FRACBITS;
}
}
@ -381,50 +385,14 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased)
* \sa P_FadeLight
*/
void T_LightFade(lightlevel_t *ll)
{
if (ll->ticbased)
{
if (--ll->timer <= 0)
{
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
{
INT16 delta = abs(ll->destlevel - ll->sourcelevel);
fixed_t factor = min(FixedDiv(ll->speed - ll->timer, ll->speed), 1*FRACUNIT);
if (ll->destlevel < ll->sourcelevel)
ll->sector->lightlevel = max(min(ll->sector->lightlevel, ll->sourcelevel - (INT16)FixedMul(delta, factor)), ll->destlevel);
else if (ll->destlevel > ll->sourcelevel)
ll->sector->lightlevel = min(max(ll->sector->lightlevel, ll->sourcelevel + (INT16)FixedMul(delta, factor)), ll->destlevel);
}
return;
}
if (ll->sector->lightlevel < ll->destlevel)
{
// increase the lightlevel
if (ll->sector->lightlevel + ll->speed >= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
ll->sector->lightlevel += ll->speed; // move lightlevel
}
else
{
// decrease lightlevel
if (ll->sector->lightlevel - ll->speed <= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
ll->sector->lightlevel -= ll->speed; // move lightlevel
}
ll->fixedcurlevel = ll->fixedcurlevel + ll->fixedpertic;
ll->sector->lightlevel = (ll->fixedcurlevel)>>FRACBITS;
}

View file

@ -1562,8 +1562,8 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type)
WRITEUINT32(save_p, SaveSector(ht->sector));
WRITEINT16(save_p, ht->sourcelevel);
WRITEINT16(save_p, ht->destlevel);
WRITEINT16(save_p, ht->speed);
WRITEUINT8(save_p, (UINT8)ht->ticbased);
WRITEFIXED(save_p, ht->fixedcurlevel);
WRITEFIXED(save_p, ht->fixedpertic);
WRITEINT32(save_p, ht->timer);
}
@ -2571,8 +2571,8 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker)
ht->sector = LoadSector(READUINT32(save_p));
ht->sourcelevel = READINT16(save_p);
ht->destlevel = READINT16(save_p);
ht->speed = READINT16(save_p);
ht->ticbased = (boolean)READUINT8(save_p);
ht->fixedcurlevel = READFIXED(save_p);
ht->fixedpertic = READFIXED(save_p);
ht->timer = READINT32(save_p);
if (ht->sector)
ht->sector->lightingdata = ht;

View file

@ -138,11 +138,11 @@ typedef struct
sector_t *sector; ///< Sector where action is taking place.
INT16 sourcelevel; ///< Light level we're fading from.
INT16 destlevel; ///< Light level we're fading to.
INT16 speed; ///< Speed at which to change light level. OR: Tic-based duration
// Tic-based behavior
boolean ticbased; ///< Tic-based logic
INT32 timer; ///< Tic-based timer
fixed_t fixedcurlevel; ///< Fixed point for current light level.
fixed_t fixedpertic; ///< Fixed point for increment per tic.
// The reason for those two above to be fixed point is to deal with decimal values that would otherwise get trimmed away.
INT32 timer; ///< Internal timer.
} lightlevel_t;
#define GLOWSPEED 8