diff --git a/src/p_polyobj.c b/src/p_polyobj.c index f7545e5bd..bbcf4f42a 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -2873,54 +2873,29 @@ void T_PolyObjFade(polyfade_t *th) if (po->thinker == NULL) po->thinker = &th->thinker; - if (th->ticbased) + stillfading = th->ticbased ? !(--(th->timer) <= 0) + : !((th->timer -= th->duration) <= 0); + + if (th->timer <= 0) { - stillfading = !(--(th->timer) <= 0); + po->translucency = max(min(th->destvalue, NUMTRANSMAPS), 0); - if (th->timer <= 0) - { - po->translucency = max(min(th->destvalue, NUMTRANSMAPS), 0); - - // remove thinker - if (po->thinker == &th->thinker) - po->thinker = NULL; - P_RemoveThinker(&th->thinker); - } - else - { - INT16 delta = abs(th->destvalue - th->sourcevalue); - fixed_t factor = min(FixedDiv(th->speed - th->timer, th->speed), 1*FRACUNIT); - if (th->destvalue < th->sourcevalue) - po->translucency = max(min(po->translucency, th->sourcevalue - (INT16)FixedMul(delta, factor)), th->destvalue); - else if (th->destvalue > th->sourcevalue) - po->translucency = min(max(po->translucency, th->sourcevalue + (INT16)FixedMul(delta, factor)), th->destvalue); - } + // remove thinker + if (po->thinker == &th->thinker) + po->thinker = NULL; + P_RemoveThinker(&th->thinker); } else { - fixed_t timerdest = FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS-th->destvalue); - - if (th->destvalue > th->sourcevalue) // fading out, destvalue is higher - { - // for timer, lower is transparent, higher is opaque - stillfading = (th->timer > timerdest); - th->timer = max(timerdest, th->timer - th->speed); - } - else if (th->destvalue < th->sourcevalue) // fading in, destvalue is lower - { stillfading = (th->timer < timerdest); - th->timer = min(timerdest, th->timer + th->speed); - } - - if (!stillfading) - { - po->translucency = max(min(th->destvalue, NUMTRANSMAPS), 0); - // remove thinker - if (po->thinker == &th->thinker) - po->thinker = NULL; - P_RemoveThinker(&th->thinker); - } - else - po->translucency = FixedDiv(256-th->timer, FixedDiv(256, NUMTRANSMAPS)); + INT16 delta = abs(th->destvalue - th->sourcevalue); + INT32 duration = th->ticbased ? th->duration + : abs(FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS - th->destvalue) + - FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS - th->sourcevalue)); // speed-based internal counter duration: delta in 256 scale + fixed_t factor = min(FixedDiv(duration - th->timer, duration), 1*FRACUNIT); + if (th->destvalue < th->sourcevalue) + po->translucency = max(min(po->translucency, th->sourcevalue - (INT16)FixedMul(delta, factor)), th->destvalue); + else if (th->destvalue > th->sourcevalue) + po->translucency = min(max(po->translucency, th->sourcevalue + (INT16)FixedMul(delta, factor)), th->destvalue); } if (!stillfading) @@ -3010,13 +2985,14 @@ INT32 EV_DoPolyObjFade(polyfadedata_t *pfdata) if (pfdata->ticbased) { th->ticbased = true; - th->timer = th->speed = abs(pfdata->speed); // use th->speed for total duration + th->timer = th->duration = abs(pfdata->speed); // pfdata->speed is duration } else { th->ticbased = false; - th->timer = FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS - po->translucency); // use as internal counter - th->speed = pfdata->speed; + th->timer = abs(FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS - th->destvalue) + - FixedMul(FixedDiv(256, NUMTRANSMAPS), NUMTRANSMAPS - th->sourcevalue)); // delta converted to 256 scale, use as internal counter + th->duration = abs(pfdata->speed); // use th->duration as speed decrement } oldpo = po; diff --git a/src/p_polyobj.h b/src/p_polyobj.h index 61404112c..524518f2a 100644 --- a/src/p_polyobj.h +++ b/src/p_polyobj.h @@ -217,8 +217,8 @@ typedef struct polyfade_s boolean docollision; boolean doghostfade; boolean ticbased; + INT32 duration; INT32 timer; - INT32 speed; } polyfade_t; // diff --git a/src/p_saveg.c b/src/p_saveg.c index 2bfc5859a..11c481be8 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1710,8 +1710,8 @@ static void SavePolyfadeThinker(const thinker_t *th, const UINT8 type) WRITEUINT8(save_p, (UINT8)ht->docollision); WRITEUINT8(save_p, (UINT8)ht->doghostfade); WRITEUINT8(save_p, (UINT8)ht->ticbased); + WRITEINT32(save_p, ht->duration); WRITEINT32(save_p, ht->timer); - WRITEINT32(save_p, ht->speed); } #endif @@ -2725,8 +2725,8 @@ static void LoadPolyfadeThinker(actionf_p1 thinker) ht->docollision = (boolean)READUINT8(save_p); ht->doghostfade = (boolean)READUINT8(save_p); ht->ticbased = (boolean)READUINT8(save_p); + ht->duration = READINT32(save_p); ht->timer = READINT32(save_p); - ht->speed = READINT32(save_p); P_AddThinker(&ht->thinker); } #endif