- Added QF_SCALEUP and QF_MAX.

- QF_SCALEUP behaves like QF_SCALEDOWN: it gradually scales the tremors, only going upwards.
- QF_SCALEUP and QF_SCALEDOWN can be combined to make an earthquake that gradually smoothes in and out.
- QF_MAX can be used to invert this behavior, where it starts at the peak of the amplitude, fades out half way, and then grows back to maximum.
This commit is contained in:
MajorCooke 2015-02-20 10:46:37 -06:00
parent 3019f2cc23
commit 140a650442
4 changed files with 31 additions and 7 deletions

View file

@ -80,7 +80,6 @@ void DEarthquake::Serialize (FArchive &arc)
{ {
arc << m_CountdownStart; arc << m_CountdownStart;
} }
} }
//========================================================================== //==========================================================================
@ -101,7 +100,7 @@ void DEarthquake::Tick ()
Destroy (); Destroy ();
return; return;
} }
if (!S_IsActorPlayingSomething (m_Spot, CHAN_BODY, m_QuakeSFX)) if (!S_IsActorPlayingSomething (m_Spot, CHAN_BODY, m_QuakeSFX))
{ {
S_Sound (m_Spot, CHAN_BODY | CHAN_LOOP, m_QuakeSFX, 1, ATTN_NORM); S_Sound (m_Spot, CHAN_BODY | CHAN_LOOP, m_QuakeSFX, 1, ATTN_NORM);
@ -141,6 +140,7 @@ void DEarthquake::Tick ()
} }
} }
} }
if (--m_Countdown == 0) if (--m_Countdown == 0)
{ {
if (S_IsActorPlayingSomething(m_Spot, CHAN_BODY, m_QuakeSFX)) if (S_IsActorPlayingSomething(m_Spot, CHAN_BODY, m_QuakeSFX))
@ -166,7 +166,7 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, quakeInfo &qprop)
{ {
return 0; return 0;
} }
qprop.isScalingDown = qprop.isScalingUp = false, qprop.preferMaximum = false;
qprop.intensityX = qprop.intensityY = qprop.intensityZ = qprop.relIntensityX = qprop.relIntensityY = qprop.relIntensityZ = 0; qprop.intensityX = qprop.intensityY = qprop.intensityZ = qprop.relIntensityX = qprop.relIntensityY = qprop.relIntensityZ = 0;
TThinkerIterator<DEarthquake> iterator(STAT_EARTHQUAKE); TThinkerIterator<DEarthquake> iterator(STAT_EARTHQUAKE);
@ -194,10 +194,13 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, quakeInfo &qprop)
qprop.intensityY = MAX(qprop.intensityY, quake->m_IntensityY); qprop.intensityY = MAX(qprop.intensityY, quake->m_IntensityY);
qprop.intensityZ = MAX(qprop.intensityZ, quake->m_IntensityZ); qprop.intensityZ = MAX(qprop.intensityZ, quake->m_IntensityZ);
} }
if (quake->m_Flags & QF_SCALEDOWN) if (quake->m_Flags)
{ {
qprop.scaleDownStart = quake->m_CountdownStart; qprop.scaleDownStart = quake->m_CountdownStart;
qprop.scaleDown = quake->m_Countdown; qprop.scaleDown = quake->m_Countdown;
qprop.isScalingDown = (quake->m_Flags & QF_SCALEDOWN) ? true : false;
qprop.isScalingUp = (quake->m_Flags & QF_SCALEUP) ? true : false;
qprop.preferMaximum = (quake->m_Flags & QF_MAX) ? true : false;
} }
else else
{ {

View file

@ -136,12 +136,14 @@ enum
QF_RELATIVE = 1, QF_RELATIVE = 1,
QF_SCALEDOWN = 1 << 1, QF_SCALEDOWN = 1 << 1,
QF_SCALEUP = 1 << 2, QF_SCALEUP = 1 << 2,
QF_MAX = 1 << 3,
}; };
struct quakeInfo struct quakeInfo
{ {
int intensityX, intensityY, intensityZ, relIntensityX, relIntensityY, relIntensityZ; int intensityX, intensityY, intensityZ, relIntensityX, relIntensityY, relIntensityZ;
double scaleDown, scaleDownStart; double scaleDown, scaleDownStart;
bool isScalingDown, isScalingUp, preferMaximum;
}; };
class DEarthquake : public DThinker class DEarthquake : public DThinker

View file

@ -781,13 +781,31 @@ static fixed_t QuakePower(double factor, int intensity, quakeInfo quake)
else else
{ {
double ss = (double)((pr_torchflicker() % (intensity << 2)) - (intensity << 1)); double ss = (double)((pr_torchflicker() % (intensity << 2)) - (intensity << 1));
if (scaleDownStart == 0)
if (quake.isScalingDown || quake.isScalingUp)
{ {
return FLOAT2FIXED(factor * ss); fixed_t result;
if (scaleDownStart == 0) scaleDownStart = 1;
if (quake.isScalingDown && quake.isScalingUp)
{
if (quake.preferMaximum)
result = FLOAT2FIXED((factor * ss) * MAX((scaleDown / scaleDownStart), (scaleDownStart - scaleDown) / scaleDownStart));
else
result = FLOAT2FIXED((factor * ss) * MIN((scaleDown / scaleDownStart), (scaleDownStart - scaleDown) / scaleDownStart));
}
else if (quake.isScalingDown)
result = FLOAT2FIXED((factor * ss) * (scaleDown / scaleDownStart));
else if (quake.isScalingUp)
result = FLOAT2FIXED((factor * ss) * ((scaleDownStart - scaleDown) / scaleDownStart));
else
result = FLOAT2FIXED(factor * ss);
return result;
} }
else else
{ {
return FLOAT2FIXED(((factor * ss) * ((scaleDown / scaleDownStart)))); return FLOAT2FIXED(factor * ss);
} }
} }

View file

@ -464,6 +464,7 @@ enum
QF_RELATIVE = 1, QF_RELATIVE = 1,
QF_SCALEDOWN = 1 << 1, QF_SCALEDOWN = 1 << 1,
QF_SCALEUP = 1 << 2, QF_SCALEUP = 1 << 2,
QF_MAX = 1 << 3,
}; };
// This is only here to provide one global variable for testing. // This is only here to provide one global variable for testing.