mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
The thinker is entirely unified now, and there is no difference in the light levels between the "old" behavior and this one now.
This commit is contained in:
parent
d939e597a5
commit
350cd1435b
3 changed files with 28 additions and 29 deletions
|
@ -355,17 +355,21 @@ 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->duration = abs(speed); // speed means duration
|
||||
// Speed means duration.
|
||||
ll->timer = abs(speed);
|
||||
ll->fixedpertic = FixedDiv((destvalue<<FRACBITS) - ll->fixedcurlevel, speed<<FRACBITS);
|
||||
}
|
||||
else
|
||||
{
|
||||
ll->ticbased = false;
|
||||
ll->timer = abs(ll->destlevel - ll->sourcelevel);
|
||||
ll->duration = abs(speed); // ll->duration is used as speed
|
||||
// Speed means increment per tic (literally speed).
|
||||
ll->timer = FixedDiv((destvalue<<FRACBITS) - ll->fixedcurlevel, speed<<FRACBITS)>>FRACBITS;
|
||||
ll->fixedpertic = speed<<FRACBITS;
|
||||
}
|
||||
CONS_Printf("Light level %d - %d, speed aprox. %d, tics %d, revised new thinker\n", ll->sector->lightlevel, destvalue, ll->fixedpertic>>FRACBITS, ll->timer);
|
||||
}
|
||||
|
||||
void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased)
|
||||
|
@ -383,20 +387,15 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased)
|
|||
*/
|
||||
void T_LightFade(lightlevel_t *ll)
|
||||
{
|
||||
if ((ll->ticbased && --ll->timer <= 0)
|
||||
|| (!ll->ticbased && (ll->timer -= ll->duration) <= 0))
|
||||
if (--ll->timer <= 0)
|
||||
{
|
||||
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
|
||||
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
|
||||
CONS_Printf("End tic, final light value: %d\n", ll->sector->lightlevel);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
INT16 delta = abs(ll->destlevel - ll->sourcelevel);
|
||||
INT32 duration = ll->ticbased ? ll->duration : delta; // speed-based: timer's initial value is equal to delta
|
||||
fixed_t factor = min(FixedDiv(duration - ll->timer, duration), 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);
|
||||
}
|
||||
|
||||
ll->fixedcurlevel = ll->fixedcurlevel + ll->fixedpertic;
|
||||
ll->sector->lightlevel = (ll->fixedcurlevel)>>FRACBITS;
|
||||
CONS_Printf("Light %d\n", ll->sector->lightlevel);
|
||||
}
|
||||
|
|
|
@ -1561,8 +1561,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);
|
||||
WRITEUINT8(save_p, (UINT8)ht->ticbased);
|
||||
WRITEINT16(save_p, ht->duration);
|
||||
WRITEFIXED(save_p, ht->fixedcurlevel);
|
||||
WRITEFIXED(save_p, ht->fixedpertic);
|
||||
WRITEINT32(save_p, ht->timer);
|
||||
}
|
||||
|
||||
|
@ -2537,8 +2537,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->ticbased = (boolean)READUINT8(save_p);
|
||||
ht->duration = READINT16(save_p);
|
||||
ht->fixedcurlevel = READFIXED(save_p);
|
||||
ht->fixedpertic = READFIXED(save_p);
|
||||
ht->timer = READINT32(save_p);
|
||||
if (ht->sector)
|
||||
ht->sector->lightingdata = ht;
|
||||
|
|
|
@ -139,10 +139,10 @@ typedef struct
|
|||
INT16 sourcelevel; ///< Light level we're fading from.
|
||||
INT16 destlevel; ///< Light level we're fading to.
|
||||
|
||||
// Tic-based behavior
|
||||
boolean ticbased; ///< Tic-based logic
|
||||
INT16 duration; ///< If tic-based: duration of effect. If speed-based: amount to increment
|
||||
INT32 timer; ///< Internal 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
|
||||
|
|
Loading…
Reference in a new issue