Use percentage calc instead of interval decrement for tic-based timing

This commit is contained in:
mazmazz 2018-09-11 10:05:25 -04:00
parent 88d9da79e6
commit 36923ae7b0
3 changed files with 26 additions and 26 deletions

View file

@ -352,19 +352,17 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean
P_AddThinker(&ll->thinker); // add thinker
ll->sector = sector;
ll->sourcelevel = sector->lightlevel;
ll->destlevel = destvalue;
if (ticbased)
{
ll->ticbased = ticbased;
ll->timer = abs(speed);
ll->speed = FixedFloor(FixedDiv(destvalue - sector->lightlevel, ll->timer))/FRACUNIT;
if (!ll->speed)
ll->speed = (destvalue < sector->lightlevel) ? -1 : 1;
ll->interval = max(FixedFloor(FixedDiv(ll->timer, abs(destvalue - sector->lightlevel)))/FRACUNIT, 1);
ll->ticbased = true;
ll->timer = ll->speed = abs(speed); // use ll->speed for total duration
}
else
{
ll->ticbased = false;
ll->timer = -1;
ll->speed = abs(speed);
}
@ -389,15 +387,17 @@ void T_LightFade(lightlevel_t *ll)
{
if (--ll->timer <= 0)
{
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else if (!(ll->timer % ll->interval))
else
{
if (ll->speed < 0)
ll->sector->lightlevel = max(ll->sector->lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
else
ll->sector->lightlevel = min(ll->sector->lightlevel + (INT16)ll->speed, (INT16)ll->destlevel);
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;
}
@ -408,12 +408,12 @@ void T_LightFade(lightlevel_t *ll)
if (ll->sector->lightlevel + ll->speed >= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel + (INT16)ll->speed); // move lightlevel
ll->sector->lightlevel += ll->speed; // move lightlevel
}
else
{
@ -421,11 +421,11 @@ void T_LightFade(lightlevel_t *ll)
if (ll->sector->lightlevel - ll->speed <= ll->destlevel)
{
// stop changing light level
ll->sector->lightlevel = (INT16)ll->destlevel; // set to dest lightlevel
ll->sector->lightlevel = ll->destlevel; // set to dest lightlevel
P_RemoveLighting(ll->sector); // clear lightingdata, remove thinker
}
else
ll->sector->lightlevel = (INT16)(ll->sector->lightlevel - (INT16)ll->speed); // move lightlevel
ll->sector->lightlevel -= ll->speed; // move lightlevel
}
}

View file

@ -1537,11 +1537,11 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type)
const lightlevel_t *ht = (const void *)th;
WRITEUINT8(save_p, type);
WRITEUINT32(save_p, SaveSector(ht->sector));
WRITEINT32(save_p, ht->destlevel);
WRITEINT32(save_p, ht->speed);
WRITEINT16(save_p, ht->sourcelevel);
WRITEINT16(save_p, ht->destlevel);
WRITEINT16(save_p, ht->speed);
WRITEUINT8(save_p, (UINT8)ht->ticbased);
WRITEINT32(save_p, ht->timer);
WRITEUINT32(save_p, ht->interval);
}
//
@ -2513,11 +2513,11 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker)
lightlevel_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL);
ht->thinker.function.acp1 = thinker;
ht->sector = LoadSector(READUINT32(save_p));
ht->destlevel = READINT32(save_p);
ht->speed = READINT32(save_p);
ht->sourcelevel = READINT16(save_p);
ht->destlevel = READINT16(save_p);
ht->speed = READINT16(save_p);
ht->ticbased = (boolean)READUINT8(save_p);
ht->timer = READINT32(save_p);
ht->interval = READUINT32(save_p);
if (ht->sector)
ht->sector->lightingdata = ht;
P_AddThinker(&ht->thinker);

View file

@ -136,13 +136,13 @@ typedef struct
{
thinker_t thinker; ///< Thinker in use for the effect.
sector_t *sector; ///< Sector where action is taking place.
INT32 destlevel; ///< Light level we're fading to.
INT32 speed; ///< Speed at which to change light level.
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
UINT32 interval; ///< Interval to deduct light level
INT32 timer; ///< Tic-based timer
} lightlevel_t;
#define GLOWSPEED 8