- floatified quake and weapon code

This commit is contained in:
Christoph Oelckers 2016-03-23 20:45:48 +01:00
commit 6557f3b8c8
13 changed files with 140 additions and 179 deletions

View file

@ -46,7 +46,7 @@ private:
struct WeaponInfo
{
PClassWeapon *Type;
fixed_t Position;
int Position;
};
void SetInitialPositions();
void Sort();
@ -274,7 +274,7 @@ public:
virtual void ReplaceClassRef(PClass *oldclass, PClass *newclass);
int SlotNumber;
fixed_t SlotPriority;
int SlotPriority;
};
class AWeapon : public AInventory
@ -288,18 +288,18 @@ public:
int MinAmmo1, MinAmmo2; // Minimum ammo needed to switch to this weapon
int AmmoUse1, AmmoUse2; // How much ammo to use with each shot
int Kickback;
fixed_t YAdjust; // For viewing the weapon fullscreen
float YAdjust; // For viewing the weapon fullscreen (visual only so no need to be a double)
FSoundIDNoInit UpSound, ReadySound; // Sounds when coming up and idle
PClassWeapon *SisterWeaponType; // Another weapon to pick up with this one
PClassActor *ProjectileType; // Projectile used by primary attack
PClassActor *AltProjectileType; // Projectile used by alternate attack
int SelectionOrder; // Lower-numbered weapons get picked first
int MinSelAmmo1, MinSelAmmo2; // Ignore in BestWeapon() if inadequate ammo
fixed_t MoveCombatDist; // Used by bots, but do they *really* need it?
double MoveCombatDist; // Used by bots, but do they *really* need it?
int ReloadCounter; // For A_CheckForReload
int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha)
fixed_t BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs.
fixed_t BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction.
int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha) (visual only so no need to be a double)
float BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs.
float BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction.
// In-inventory instance variables
TObjPtr<AAmmo> Ammo1, Ammo2;
@ -395,7 +395,7 @@ public:
bool TryPickup(AActor *&toucher);
void Serialize(FArchive &arc);
fixed_t DropAmmoFactor;
double DropAmmoFactor;
};

View file

@ -35,26 +35,22 @@ DEarthquake::DEarthquake()
//
//==========================================================================
DEarthquake::DEarthquake (AActor *center, int intensityX, int intensityY, int intensityZ, int duration,
int damrad, int tremrad, FSoundID quakesound, int flags,
double waveSpeedX, double waveSpeedY, double waveSpeedZ, int falloff, int highpoint)
: DThinker(STAT_EARTHQUAKE)
DEarthquake::DEarthquake(AActor *center, int intensityX, int intensityY, int intensityZ, int duration,
int damrad, int tremrad, FSoundID quakesound, int flags,
double waveSpeedX, double waveSpeedY, double waveSpeedZ, int falloff, int highpoint)
: DThinker(STAT_EARTHQUAKE)
{
m_QuakeSFX = quakesound;
m_Spot = center;
// Radii are specified in tile units (64 pixels)
m_DamageRadius = damrad << FRACBITS;
m_TremorRadius = tremrad << FRACBITS;
m_IntensityX = intensityX << FRACBITS;
m_IntensityY = intensityY << FRACBITS;
m_IntensityZ = intensityZ << FRACBITS;
m_DamageRadius = damrad;
m_TremorRadius = tremrad;
m_Intensity = DVector3(intensityX, intensityY, intensityZ);
m_CountdownStart = duration;
m_Countdown = duration;
m_Flags = flags;
m_WaveSpeedX = (float)waveSpeedX;
m_WaveSpeedY = (float)waveSpeedY;
m_WaveSpeedZ = (float)waveSpeedZ;
m_Falloff = falloff << FRACBITS;
m_WaveSpeed = DVector3(waveSpeedX, waveSpeedY, waveSpeedZ);
m_Falloff = falloff;
m_Highpoint = highpoint;
m_MiniCount = highpoint;
}
@ -68,46 +64,11 @@ DEarthquake::DEarthquake (AActor *center, int intensityX, int intensityY, int in
void DEarthquake::Serialize (FArchive &arc)
{
Super::Serialize (arc);
arc << m_Spot << m_IntensityX << m_Countdown
arc << m_Spot << m_Intensity << m_Countdown
<< m_TremorRadius << m_DamageRadius
<< m_QuakeSFX;
if (SaveVersion < 4519)
{
m_IntensityY = m_IntensityX;
m_IntensityZ = 0;
m_Flags = 0;
}
else
{
arc << m_IntensityY << m_IntensityZ << m_Flags;
}
if (SaveVersion < 4520)
{
m_CountdownStart = 0;
}
else
{
arc << m_CountdownStart;
}
if (SaveVersion < 4521)
{
m_WaveSpeedX = m_WaveSpeedY = m_WaveSpeedZ = 0;
m_IntensityX <<= FRACBITS;
m_IntensityY <<= FRACBITS;
m_IntensityZ <<= FRACBITS;
}
else
{
arc << m_WaveSpeedX << m_WaveSpeedY << m_WaveSpeedZ;
}
if (SaveVersion < 4534)
{
m_Falloff = m_Highpoint = m_MiniCount = 0;
}
else
{
arc << m_Falloff << m_Highpoint << m_MiniCount;
}
<< m_QuakeSFX << m_Flags << m_CountdownStart
<< m_WaveSpeed
<< m_Falloff << m_Highpoint << m_MiniCount;
}
//==========================================================================
@ -141,9 +102,9 @@ void DEarthquake::Tick ()
if (playeringame[i] && !(players[i].cheats & CF_NOCLIP))
{
AActor *victim = players[i].mo;
fixed_t dist;
double dist;
dist = m_Spot->AproxDistance (victim, true);
dist = m_Spot->Distance2D(victim, true);
// Check if in damage radius
if (dist < m_DamageRadius && victim->Z() <= victim->floorz)
{
@ -153,8 +114,8 @@ void DEarthquake::Tick ()
}
// Thrust player around
DAngle an = victim->Angles.Yaw + pr_quake();
victim->Vel.X += FIXED2DBL(m_IntensityX) * an.Cos() * 0.5;
victim->Vel.Y += FIXED2DBL(m_IntensityY) * an.Sin() * 0.5;
victim->Vel.X += m_Intensity.X * an.Cos() * 0.5;
victim->Vel.Y += m_Intensity.Y * an.Sin() * 0.5;
}
}
}
@ -182,10 +143,10 @@ void DEarthquake::Tick ()
//
//==========================================================================
fixed_t DEarthquake::GetModWave(double waveMultiplier) const
double DEarthquake::GetModWave(double waveMultiplier) const
{
double time = m_Countdown - FIXED2DBL(r_TicFrac);
return FLOAT2FIXED(g_sin(waveMultiplier * time * (M_PI * 2 / TICRATE)));
return g_sin(waveMultiplier * time * (M_PI * 2 / TICRATE));
}
//==========================================================================
@ -196,7 +157,7 @@ fixed_t DEarthquake::GetModWave(double waveMultiplier) const
//
//==========================================================================
fixed_t DEarthquake::GetModIntensity(fixed_t intensity) const
double DEarthquake::GetModIntensity(double intensity) const
{
assert(m_CountdownStart >= m_Countdown);
@ -255,7 +216,7 @@ fixed_t DEarthquake::GetModIntensity(fixed_t intensity) const
scalar = (scalar > divider) ? divider : scalar;
}
assert(divider > 0);
intensity = Scale(intensity, scalar, divider);
intensity = intensity * scalar / divider;
}
return intensity;
}
@ -265,27 +226,25 @@ fixed_t DEarthquake::GetModIntensity(fixed_t intensity) const
// DEarthquake :: GetFalloff
//
// Given the distance of the player from the quake, find the multiplier.
// Process everything as doubles, and output again as fixed_t (mainly
// because fixed_t was misbehaving here...)
//
//==========================================================================
fixed_t DEarthquake::GetFalloff(fixed_t dist) const
double DEarthquake::GetFalloff(double dist) const
{
if ((dist < m_Falloff) || (m_Falloff >= m_TremorRadius) || (m_Falloff <= 0) || (m_TremorRadius - m_Falloff <= 0))
{ //Player inside the minimum falloff range, or safety check kicked in.
return FRACUNIT;
return 1.;
}
else if ((dist > m_Falloff) && (dist < m_TremorRadius))
{ //Player inside the radius, and outside the min distance for falloff.
fixed_t tremorsize = m_TremorRadius - m_Falloff;
fixed_t tremordist = dist - m_Falloff;
double tremorsize = m_TremorRadius - m_Falloff;
double tremordist = dist - m_Falloff;
assert(tremorsize > 0);
return (FRACUNIT - FixedMul(FRACUNIT,tremordist) / tremorsize);
return (1. - tremordist) / tremorsize;
}
else
{ //Shouldn't happen.
return FRACUNIT;
return 1.;
}
}
@ -315,14 +274,14 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jigger
{
if (quake->m_Spot != NULL)
{
fixed_t dist = quake->m_Spot->AproxDistance (victim, true);
double dist = quake->m_Spot->Distance2D (victim, true);
if (dist < quake->m_TremorRadius)
{
fixed_t falloff = quake->GetFalloff(dist);
double falloff = quake->GetFalloff(dist);
++count;
fixed_t x = quake->GetModIntensity(quake->m_IntensityX);
fixed_t y = quake->GetModIntensity(quake->m_IntensityY);
fixed_t z = quake->GetModIntensity(quake->m_IntensityZ);
double x = quake->GetModIntensity(quake->m_Intensity.X);
double y = quake->GetModIntensity(quake->m_Intensity.Y);
double z = quake->GetModIntensity(quake->m_Intensity.Z);
if (!(quake->m_Flags & QF_WAVE))
@ -330,23 +289,23 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jigger
jiggers.Falloff = MAX(falloff, jiggers.Falloff);
if (quake->m_Flags & QF_RELATIVE)
{
jiggers.RelIntensityX = MAX(x, jiggers.RelIntensityX);
jiggers.RelIntensityY = MAX(y, jiggers.RelIntensityY);
jiggers.RelIntensityZ = MAX(z, jiggers.RelIntensityZ);
jiggers.RelIntensity.X = MAX(x, jiggers.RelIntensity.X);
jiggers.RelIntensity.Y = MAX(y, jiggers.RelIntensity.Y);
jiggers.RelIntensity.Z = MAX(z, jiggers.RelIntensity.Z);
}
else
{
jiggers.IntensityX = MAX(x, jiggers.IntensityX);
jiggers.IntensityY = MAX(y, jiggers.IntensityY);
jiggers.IntensityZ = MAX(z, jiggers.IntensityZ);
jiggers.Intensity.X = MAX(x, jiggers.Intensity.X);
jiggers.Intensity.Y = MAX(y, jiggers.Intensity.Y);
jiggers.Intensity.Z = MAX(z, jiggers.Intensity.Z);
}
}
else
{
jiggers.WFalloff = MAX(falloff, jiggers.WFalloff);
fixed_t mx = FixedMul(x, quake->GetModWave(quake->m_WaveSpeedX));
fixed_t my = FixedMul(y, quake->GetModWave(quake->m_WaveSpeedY));
fixed_t mz = FixedMul(z, quake->GetModWave(quake->m_WaveSpeedZ));
double mx = x * quake->GetModWave(quake->m_WaveSpeed.X);
double my = y * quake->GetModWave(quake->m_WaveSpeed.Y);
double mz = z * quake->GetModWave(quake->m_WaveSpeed.Z);
// [RH] This only gives effect to the last sine quake. I would
// prefer if some way was found to make multiples coexist
@ -355,15 +314,15 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jigger
// relative phases.
if (quake->m_Flags & QF_RELATIVE)
{
jiggers.RelOffsetX = mx;
jiggers.RelOffsetY = my;
jiggers.RelOffsetZ = mz;
jiggers.RelOffset.X = mx;
jiggers.RelOffset.Y = my;
jiggers.RelOffset.Z = mz;
}
else
{
jiggers.OffsetX = mx;
jiggers.OffsetY = my;
jiggers.OffsetZ = mz;
jiggers.Offset.X = mx;
jiggers.Offset.Y = my;
jiggers.Offset.Z = mz;
}
}
}

View file

@ -154,11 +154,12 @@ enum
struct FQuakeJiggers
{
int IntensityX, IntensityY, IntensityZ;
int RelIntensityX, RelIntensityY, RelIntensityZ;
int OffsetX, OffsetY, OffsetZ;
int RelOffsetX, RelOffsetY, RelOffsetZ;
int Falloff, WFalloff;
DVector3 Intensity;
DVector3 RelIntensity;
DVector3 Offset;
DVector3 RelOffset;
double Falloff;
double WFalloff;
};
class DEarthquake : public DThinker
@ -173,19 +174,19 @@ public:
void Serialize (FArchive &arc);
void Tick ();
TObjPtr<AActor> m_Spot;
fixed_t m_TremorRadius, m_DamageRadius;
double m_TremorRadius, m_DamageRadius;
int m_Countdown;
int m_CountdownStart;
FSoundID m_QuakeSFX;
int m_Flags;
fixed_t m_IntensityX, m_IntensityY, m_IntensityZ;
float m_WaveSpeedX, m_WaveSpeedY, m_WaveSpeedZ;
fixed_t m_Falloff;
DVector3 m_Intensity;
DVector3 m_WaveSpeed;
double m_Falloff;
int m_Highpoint, m_MiniCount;
fixed_t GetModIntensity(int intensity) const;
fixed_t GetModWave(double waveMultiplier) const;
fixed_t GetFalloff(fixed_t dist) const;
double GetModIntensity(double intensity) const;
double GetModWave(double waveMultiplier) const;
double GetFalloff(double dist) const;
static int StaticGetQuakeIntensities(AActor *viewer, FQuakeJiggers &jiggers);

View file

@ -41,7 +41,7 @@ IMPLEMENT_CLASS(PClassWeapon)
PClassWeapon::PClassWeapon()
{
SlotNumber = -1;
SlotPriority = FIXED_MAX;
SlotPriority = INT_MAX;
}
void PClassWeapon::DeriveData(PClass *newclass)
@ -762,8 +762,8 @@ bool AWeaponGiver::TryPickup(AActor *&toucher)
// If DropAmmoFactor is non-negative, modify the given ammo amounts.
if (DropAmmoFactor > 0)
{
weap->AmmoGive1 = FixedMul(weap->AmmoGive1, DropAmmoFactor);
weap->AmmoGive2 = FixedMul(weap->AmmoGive2, DropAmmoFactor);
weap->AmmoGive1 = int(weap->AmmoGive1 * DropAmmoFactor);
weap->AmmoGive2 = int(weap->AmmoGive2 * DropAmmoFactor);
}
weap->BecomeItem();
}
@ -984,7 +984,7 @@ void FWeaponSlot::Sort()
for (i = 1; i < (int)Weapons.Size(); ++i)
{
fixed_t pos = Weapons[i].Position;
int pos = Weapons[i].Position;
PClassWeapon *type = Weapons[i].Type;
for (j = i - 1; j >= 0 && Weapons[j].Position > pos; --j)
{