From 3d5f225702bbb9cae9a52ec00ff1a32304d8eb71 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sun, 9 Sep 2018 20:18:43 -0400 Subject: [PATCH] Replace firsttic with decrement timer --- src/p_lights.c | 16 ++++++++-------- src/p_saveg.c | 8 ++++---- src/p_spec.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/p_lights.c b/src/p_lights.c index 8be3d793c..77d05dad3 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -356,16 +356,16 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean if (ticbased) { - ll->duration = abs(speed); - ll->speed = FixedFloor(FixedDiv(destvalue - sector->lightlevel, ll->duration))/FRACUNIT; + 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->duration, abs(destvalue - sector->lightlevel)))/FRACUNIT, 1); - ll->firsttic = gametic; + ll->interval = max(FixedFloor(FixedDiv(ll->timer, abs(destvalue - sector->lightlevel)))/FRACUNIT, 1); } else { - ll->duration = -1; + ll->timer = -1; ll->speed = abs(speed); } } @@ -385,14 +385,14 @@ void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased) */ void T_LightFade(lightlevel_t *ll) { - if (ll->duration >= 0) // tic-based + if (ll->ticbased) { - if (gametic - ll->firsttic >= ll->duration) + if (--ll->timer <= 0) { 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)) + else if (!(ll->timer % ll->interval)) { if (ll->speed < 0) ll->sector->lightlevel = max(ll->sector->lightlevel + (INT16)ll->speed, (INT16)ll->destlevel); diff --git a/src/p_saveg.c b/src/p_saveg.c index 8ec5b5ea8..eefee072d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1539,9 +1539,9 @@ static void SaveLightlevelThinker(const thinker_t *th, const UINT8 type) WRITEUINT32(save_p, SaveSector(ht->sector)); WRITEINT32(save_p, ht->destlevel); WRITEINT32(save_p, ht->speed); - WRITEINT32(save_p, ht->duration); + WRITEUINT8(save_p, (UINT8)ht->ticbased); + WRITEINT32(save_p, ht->timer); WRITEUINT32(save_p, ht->interval); - WRITEUINT32(save_p, (UINT32)ht->firsttic); } // @@ -2515,9 +2515,9 @@ static inline void LoadLightlevelThinker(actionf_p1 thinker) ht->sector = LoadSector(READUINT32(save_p)); ht->destlevel = READINT32(save_p); ht->speed = READINT32(save_p); - ht->duration = READINT32(save_p); + ht->ticbased = (boolean)READUINT8(save_p); + ht->timer = READINT32(save_p); ht->interval = READUINT32(save_p); - ht->firsttic = (tic_t)READUINT32(save_p); if (ht->sector) ht->sector->lightingdata = ht; P_AddThinker(&ht->thinker); diff --git a/src/p_spec.h b/src/p_spec.h index c2c4c8976..1e327c5f2 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -140,9 +140,9 @@ typedef struct INT32 speed; ///< Speed at which to change light level. // Tic-based behavior - INT32 duration; ///< If <0, do not use tic-based behavior. If 0, set instantly. If >0, fade lasts this duration. + boolean ticbased; ///< Tic-based logic + INT32 timer; ///< Tic-based timer UINT32 interval; ///< Interval to deduct light level - tic_t firsttic; ///< First gametic to count from } lightlevel_t; #define GLOWSPEED 8