mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-12 22:02:12 +00:00
492: Merge speed and duration logic for fade polyobject
This commit is contained in:
parent
ca4a94eca5
commit
17e23f55eb
3 changed files with 25 additions and 49 deletions
|
@ -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;
|
||||
|
|
|
@ -217,8 +217,8 @@ typedef struct polyfade_s
|
|||
boolean docollision;
|
||||
boolean doghostfade;
|
||||
boolean ticbased;
|
||||
INT32 duration;
|
||||
INT32 timer;
|
||||
INT32 speed;
|
||||
} polyfade_t;
|
||||
|
||||
//
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue