This commit is contained in:
Christoph Oelckers 2015-02-20 16:43:21 +01:00
commit 0074e1d216
5 changed files with 62 additions and 31 deletions

View file

@ -45,6 +45,7 @@ DEarthquake::DEarthquake (AActor *center, int intensityX, int intensityY, int in
m_IntensityX = intensityX;
m_IntensityY = intensityY;
m_IntensityZ = intensityZ;
m_CountdownStart = (double)duration;
m_Countdown = duration;
m_Flags = flags;
}
@ -67,6 +68,8 @@ void DEarthquake::Serialize (FArchive &arc)
m_IntensityZ = 0;
m_Flags = 0;
}
if (SaveVersion < 4520)
m_CountdownStart = 0;
else
{
arc << m_IntensityY << m_IntensityZ << m_Flags;
@ -150,15 +153,14 @@ void DEarthquake::Tick ()
//
//==========================================================================
int DEarthquake::StaticGetQuakeIntensities(AActor *victim,
int &x, int &y, int &z, int &relx, int &rely, int &relz)
int DEarthquake::StaticGetQuakeIntensities(AActor *victim, quakeInfo &qprop)
{
if (victim->player != NULL && (victim->player->cheats & CF_NOCLIP))
{
return 0;
}
x = y = z = relx = rely = relz = 0;
qprop.intensityX = qprop.intensityY = qprop.intensityZ = qprop.relIntensityX = qprop.relIntensityY = qprop.relIntensityZ = 0;
TThinkerIterator<DEarthquake> iterator(STAT_EARTHQUAKE);
DEarthquake *quake;
@ -175,15 +177,24 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim,
++count;
if (quake->m_Flags & QF_RELATIVE)
{
relx = MAX(relx, quake->m_IntensityX);
rely = MAX(rely, quake->m_IntensityY);
relz = MAX(relz, quake->m_IntensityZ);
qprop.relIntensityX = MAX(qprop.relIntensityX, quake->m_IntensityX);
qprop.relIntensityY = MAX(qprop.relIntensityY, quake->m_IntensityY);
qprop.relIntensityZ = MAX(qprop.relIntensityZ, quake->m_IntensityZ);
}
else
{
x = MAX(x, quake->m_IntensityX);
y = MAX(y, quake->m_IntensityY);
z = MAX(z, quake->m_IntensityZ);
qprop.intensityX = MAX(qprop.intensityX, quake->m_IntensityX);
qprop.intensityY = MAX(qprop.intensityY, quake->m_IntensityY);
qprop.intensityZ = MAX(qprop.intensityZ, quake->m_IntensityZ);
}
if (quake->m_Flags & QF_SCALEDOWN)
{
qprop.scaleDownStart = quake->m_CountdownStart;
qprop.scaleDown = quake->m_Countdown;
}
else
{
qprop.scaleDownStart = qprop.scaleDown = 0.0;
}
}
}

View file

@ -133,7 +133,15 @@ protected:
enum
{
QF_RELATIVE = 1,
QF_RELATIVE = 1,
QF_SCALEDOWN = 1 << 1,
QF_SCALEUP = 1 << 2,
};
struct quakeInfo
{
int intensityX, intensityY, intensityZ, relIntensityX, relIntensityY, relIntensityZ;
double scaleDown, scaleDownStart;
};
class DEarthquake : public DThinker
@ -148,11 +156,12 @@ public:
TObjPtr<AActor> m_Spot;
fixed_t m_TremorRadius, m_DamageRadius;
int m_Countdown;
double m_CountdownStart;
FSoundID m_QuakeSFX;
int m_Flags;
int m_IntensityX, m_IntensityY, m_IntensityZ;
static int StaticGetQuakeIntensities(AActor *viewer, int &x, int &y, int &z, int &relx, int &rely, int &relz);
static int StaticGetQuakeIntensities(AActor *viewer, quakeInfo &qprop);
private:
DEarthquake ();

View file

@ -770,16 +770,27 @@ bool R_GetViewInterpolationStatus()
//
//==========================================================================
static fixed_t QuakePower(fixed_t factor, int intensity)
static fixed_t QuakePower(double factor, int intensity, quakeInfo quake)
{
double scaleDownStart = quake.scaleDownStart;
double scaleDown = quake.scaleDown;
if (intensity == 0)
{
return 0;
}
else
{
return factor * ((pr_torchflicker() % (intensity << 2)) - (intensity << 1));
double ss = (double)((pr_torchflicker() % (intensity << 2)) - (intensity << 1));
if (scaleDownStart == 0)
{
return FLOAT2FIXED(factor * ss);
}
else
{
return FLOAT2FIXED(((factor * ss) * ((scaleDown / scaleDownStart))));
}
}
}
//==========================================================================
@ -892,40 +903,38 @@ void R_SetupFrame (AActor *actor)
if (!paused)
{
int intensityX, intensityY, intensityZ, relIntensityX, relIntensityY, relIntensityZ;
if (DEarthquake::StaticGetQuakeIntensities(camera,
intensityX, intensityY, intensityZ,
relIntensityX, relIntensityY, relIntensityZ) > 0)
quakeInfo quake;
if (DEarthquake::StaticGetQuakeIntensities(camera, quake) > 0)
{
fixed_t quakefactor = FLOAT2FIXED(r_quakeintensity);
double quakefactor = r_quakeintensity;
if (relIntensityX != 0)
if (quake.relIntensityX != 0)
{
int ang = (camera->angle) >> ANGLETOFINESHIFT;
fixed_t power = QuakePower(quakefactor, relIntensityX);
fixed_t power = QuakePower(quakefactor, quake.relIntensityX, quake);
viewx += FixedMul(finecosine[ang], power);
viewy += FixedMul(finesine[ang], power);
}
if (relIntensityY != 0)
if (quake.relIntensityY != 0)
{
int ang = (camera->angle + ANG90) >> ANGLETOFINESHIFT;
fixed_t power = QuakePower(quakefactor, relIntensityY);
fixed_t power = QuakePower(quakefactor, quake.relIntensityY, quake);
viewx += FixedMul(finecosine[ang], power);
viewy += FixedMul(finesine[ang], power);
}
if (intensityX != 0)
if (quake.intensityX != 0)
{
viewx += QuakePower(quakefactor, intensityX);
viewx += QuakePower(quakefactor, quake.intensityX, quake);
}
if (intensityY != 0)
if (quake.intensityY != 0)
{
viewy += QuakePower(quakefactor, intensityY);
viewy += QuakePower(quakefactor, quake.intensityY, quake);
}
// FIXME: Relative Z is not relative
intensityZ = MAX(intensityZ, relIntensityZ);
if (intensityZ != 0)
quake.intensityZ = MAX(quake.intensityZ, quake.relIntensityZ);
if (quake.intensityZ != 0)
{
viewz += QuakePower(quakefactor, intensityZ);
viewz += QuakePower(quakefactor, quake.intensityZ, quake);
}
}
}

View file

@ -76,7 +76,7 @@ const char *GetVersionString();
// Use 4500 as the base git save version, since it's higher than the
// SVN revision ever got.
#define SAVEVER 4519
#define SAVEVER 4520
#define SAVEVERSTRINGIFY2(x) #x
#define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x)

View file

@ -461,7 +461,9 @@ enum
// Flags for A_QuakeEx
enum
{
QF_RELATIVE = 1,
QF_RELATIVE = 1,
QF_SCALEDOWN = 1 << 1,
QF_SCALEUP = 1 << 2,
};
// This is only here to provide one global variable for testing.