From 6557f3b8c834c62d4d640beee90c3c8d2de2b3b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 23 Mar 2016 20:45:48 +0100 Subject: [PATCH] - floatified quake and weapon code --- src/b_bot.cpp | 2 +- src/b_think.cpp | 2 +- src/g_shared/a_pickups.h | 16 ++-- src/g_shared/a_quake.cpp | 135 ++++++++++----------------- src/g_shared/a_sharedglobal.h | 25 ++--- src/g_shared/a_weapons.cpp | 8 +- src/p_enemy.cpp | 2 +- src/p_pspr.cpp | 50 +++++----- src/p_pspr.h | 2 +- src/r_things.cpp | 8 +- src/r_utility.cpp | 51 +++++----- src/thingdef/thingdef_properties.cpp | 8 +- src/vectors.h | 10 +- 13 files changed, 140 insertions(+), 179 deletions(-) diff --git a/src/b_bot.cpp b/src/b_bot.cpp index 89b7b9471..3d6c916c6 100644 --- a/src/b_bot.cpp +++ b/src/b_bot.cpp @@ -269,7 +269,7 @@ void InitBotStuff() AWeapon *w = (AWeapon*)GetDefaultByType(cls); if (w != NULL) { - w->MoveCombatDist = botinits[i].movecombatdist; + w->MoveCombatDist = botinits[i].movecombatdist/65536.; w->WeaponFlags |= botinits[i].weaponflags; w->ProjectileType = PClass::FindActor(botinits[i].projectile); } diff --git a/src/b_think.cpp b/src/b_think.cpp index 0d02f76f8..dd6ce49aa 100644 --- a/src/b_think.cpp +++ b/src/b_think.cpp @@ -171,7 +171,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd) angle = player->mo->__f_AngleTo(enemy); if (player->ReadyWeapon == NULL || - player->mo->AproxDistance(enemy) > + player->mo->Distance2D(enemy) > player->ReadyWeapon->MoveCombatDist) { // If a monster, use lower speed (just for cooler apperance while strafing down doomed monster) diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 158c4130d..26b27e202 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -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 Ammo1, Ammo2; @@ -395,7 +395,7 @@ public: bool TryPickup(AActor *&toucher); void Serialize(FArchive &arc); - fixed_t DropAmmoFactor; + double DropAmmoFactor; }; diff --git a/src/g_shared/a_quake.cpp b/src/g_shared/a_quake.cpp index db8aadadf..8668c2dd6 100644 --- a/src/g_shared/a_quake.cpp +++ b/src/g_shared/a_quake.cpp @@ -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; } } } diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index c65c0992d..6776fa814 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -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 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); diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index 5e00d9025..d0d566fee 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -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) { diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index a75aa891b..64161014c 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -3130,7 +3130,7 @@ void ModifyDropAmount(AInventory *inv, int dropamount) } else if (inv->IsKindOf (RUNTIME_CLASS(AWeaponGiver))) { - static_cast(inv)->DropAmmoFactor = dropammofactor; + static_cast(inv)->DropAmmoFactor = FIXED2DBL(dropammofactor); inv->ItemFlags |= flagmask; } else if (inv->IsKindOf (RUNTIME_CLASS(AWeapon))) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 7b1dbc50d..ed578dd8e 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -367,12 +367,12 @@ void P_DropWeapon (player_t *player) // //============================================================================ -void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) +void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y) { - static fixed_t curbob; + static float curbob; AWeapon *weapon; - fixed_t bobtarget; + float bobtarget; weapon = player->ReadyWeapon; @@ -384,26 +384,26 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) // [XA] Get the current weapon's bob properties. int bobstyle = weapon->BobStyle; - int bobspeed = (weapon->BobSpeed * 128) >> 16; - fixed_t rangex = weapon->BobRangeX; - fixed_t rangey = weapon->BobRangeY; + float BobSpeed = (weapon->BobSpeed * 128); + float Rangex = weapon->BobRangeX; + float Rangey = weapon->BobRangeY; // Bob the weapon based on movement speed. - int angle = (bobspeed*35/TICRATE*level.time)&FINEMASK; + FAngle angle = (BobSpeed * 35 / TICRATE*level.time) * (360.f / 8192.f); // [RH] Smooth transitions between bobbing and not-bobbing frames. // This also fixes the bug where you can "stick" a weapon off-center by // shooting it when it's at the peak of its swing. - bobtarget = (player->WeaponState & WF_WEAPONBOBBING) ? FLOAT2FIXED(player->bob) : 0; + bobtarget = float((player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0.); if (curbob != bobtarget) { - if (abs (bobtarget - curbob) <= 1*FRACUNIT) + if (fabsf (bobtarget - curbob) <= 1) { curbob = bobtarget; } else { - fixed_t zoom = MAX (1*FRACUNIT, abs (curbob - bobtarget) / 40); + float zoom = MAX (1.f, fabsf (curbob - bobtarget) / 40); if (curbob > bobtarget) { curbob -= zoom; @@ -417,38 +417,38 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) if (curbob != 0) { - fixed_t bobx = fixed_t(player->bob * rangex); - fixed_t boby = fixed_t(player->bob * rangey); - switch (bobstyle) + float bobx = float(player->bob * Rangex); + float boby = float(player->bob * Rangey); + switch (level.levelnum)//bobstyle) { case AWeapon::BobNormal: - *x = FixedMul(bobx, finecosine[angle]); - *y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + *x = bobx * angle.Cos(); + *y = boby * fabsf(angle.Sin()); break; case AWeapon::BobInverse: - *x = FixedMul(bobx, finecosine[angle]); - *y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + *x = bobx*angle.Cos(); + *y = boby * (1.f - fabsf(angle.Sin())); break; case AWeapon::BobAlpha: - *x = FixedMul(bobx, finesine[angle]); - *y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + *x = bobx * angle.Sin(); + *y = boby * fabsf(angle.Sin()); break; case AWeapon::BobInverseAlpha: - *x = FixedMul(bobx, finesine[angle]); - *y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + *x = bobx * angle.Sin(); + *y = boby * (1.f - fabsf(angle.Sin())); break; case AWeapon::BobSmooth: - *x = FixedMul(bobx, finecosine[angle]); - *y = (boby - FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)])) / 2; + *x = bobx*angle.Cos(); + *y = 0.5f * (boby * (1.f - fabsf((angle * 2).Cos()))); break; case AWeapon::BobInverseSmooth: - *x = FixedMul(bobx, finecosine[angle]); - *y = (FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)]) + boby) / 2; + *x = bobx*angle.Cos(); + *y = 0.5f * (boby * (1.f + fabsf((angle * 2).Cos()))); } } else diff --git a/src/p_pspr.h b/src/p_pspr.h index 2f19eb4e8..7045f96a5 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -87,7 +87,7 @@ void P_CalcSwing (player_t *player); void P_BringUpWeapon (player_t *player); void P_FireWeapon (player_t *player); void P_DropWeapon (player_t *player); -void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y); +void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y); DAngle P_BulletSlope (AActor *mo, FTranslatedLineTarget *pLineTarget = NULL, int aimflags = 0); void P_GunShot (AActor *mo, bool accurate, PClassActor *pufftype, DAngle pitch); diff --git a/src/r_things.cpp b/src/r_things.cpp index fa5145001..1e26d2f90 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1350,12 +1350,12 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ { if (RenderTarget != screen || viewheight == RenderTarget->GetHeight()) { - vis->texturemid -= weapon->YAdjust; + vis->texturemid -= FLOAT2FIXED(weapon->YAdjust); } else { vis->texturemid -= FixedMul (StatusBar->GetDisplacement (), - weapon->YAdjust); + FLOAT2FIXED(weapon->YAdjust)); } } } @@ -1575,7 +1575,7 @@ void R_DrawPlayerSprites () if (camera->player != NULL) { fixed_t centerhack = centeryfrac; - fixed_t ofsx, ofsy; + float ofsx, ofsy; centery = viewheight >> 1; centeryfrac = centery << FRACBITS; @@ -1590,7 +1590,7 @@ void R_DrawPlayerSprites () // [RH] Don't draw the targeter's crosshair if the player already has a crosshair set. if (psp->state && (i != ps_targetcenter || CrosshairImage == NULL)) { - R_DrawPSprite (psp, i, camera, FLOAT2FIXED(psp->sx) + ofsx, FLOAT2FIXED(psp->sy) + ofsy); + R_DrawPSprite (psp, i, camera, FLOAT2FIXED(psp->sx + ofsx), FLOAT2FIXED(psp->sy + ofsy)); } // [RH] Don't bob the targeter. if (i == ps_flash) diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 3d945864f..3bc2db6cd 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -897,19 +897,18 @@ void R_AddInterpolationPoint(const fixedvec3a &vec) // //========================================================================== -static fixed_t QuakePower(fixed_t factor, fixed_t intensity, fixed_t offset, fixed_t falloff, fixed_t wfalloff) +static double QuakePower(double factor, double intensity, double offset, double falloff, double wfalloff) { - fixed_t randumb; + double randumb; if (intensity == 0) { randumb = 0; } else { - randumb = pr_torchflicker(intensity * 2) - intensity; + randumb = pr_torchflicker.GenRand_Real2() * (intensity * 2) - intensity; } - fixed_t rn2 = (FixedMul(wfalloff,offset) + FixedMul(falloff, randumb)); - return FixedMul(factor, rn2); + return factor * (wfalloff * offset + falloff * randumb); } //========================================================================== @@ -1046,42 +1045,44 @@ void R_SetupFrame (AActor *actor) if (!paused) { - FQuakeJiggers jiggers = { 0, }; + FQuakeJiggers jiggers; + memset(&jiggers, 0, sizeof(jiggers)); if (DEarthquake::StaticGetQuakeIntensities(camera, jiggers) > 0) { - fixed_t quakefactor = FLOAT2FIXED(r_quakeintensity); + double quakefactor = r_quakeintensity; + DAngle an; - if ((jiggers.RelIntensityX | jiggers.RelOffsetX) != 0) + if (jiggers.RelIntensity.X != 0 || jiggers.RelOffset.X != 0) { - int ang = (camera->_f_angle()) >> ANGLETOFINESHIFT; - fixed_t power = QuakePower(quakefactor, jiggers.RelIntensityX, jiggers.RelOffsetX, jiggers.Falloff, jiggers.WFalloff); - viewx += FixedMul(finecosine[ang], power); - viewy += FixedMul(finesine[ang], power); + an = camera->Angles.Yaw; + double power = QuakePower(quakefactor, jiggers.RelIntensity.X, jiggers.RelOffset.X, jiggers.Falloff, jiggers.WFalloff); + viewx += FLOAT2FIXED(an.Cos() * power); + viewy += FLOAT2FIXED(an.Sin() * power); } - if ((jiggers.RelIntensityY | jiggers.RelOffsetY) != 0) + if (jiggers.RelIntensity.Y != 0 || jiggers.RelOffset.Y != 0) { - int ang = (camera->_f_angle() + ANG90) >> ANGLETOFINESHIFT; - fixed_t power = QuakePower(quakefactor, jiggers.RelIntensityY, jiggers.RelOffsetY, jiggers.Falloff, jiggers.WFalloff); - viewx += FixedMul(finecosine[ang], power); - viewy += FixedMul(finesine[ang], power); + an = camera->Angles.Yaw + 90; + double power = QuakePower(quakefactor, jiggers.RelIntensity.Y, jiggers.RelOffset.Y, jiggers.Falloff, jiggers.WFalloff); + viewx += FLOAT2FIXED(an.Cos() * power); + viewy += FLOAT2FIXED(an.Sin() * power); } // FIXME: Relative Z is not relative - if ((jiggers.RelIntensityZ | jiggers.RelOffsetZ) != 0) + if (jiggers.RelIntensity.Z != 0 || jiggers.RelOffset.Z != 0) { - viewz += QuakePower(quakefactor, jiggers.RelIntensityZ, jiggers.RelOffsetZ, jiggers.Falloff, jiggers.WFalloff); + viewz += FLOAT2FIXED(QuakePower(quakefactor, jiggers.RelIntensity.Z, jiggers.RelOffset.Z, jiggers.Falloff, jiggers.WFalloff)); } - if ((jiggers.IntensityX | jiggers.OffsetX) != 0) + if (jiggers.Intensity.X != 0 || jiggers.Offset.X != 0) { - viewx += QuakePower(quakefactor, jiggers.IntensityX, jiggers.OffsetX, jiggers.Falloff, jiggers.WFalloff); + viewx += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.X, jiggers.Offset.X, jiggers.Falloff, jiggers.WFalloff)); } - if ((jiggers.IntensityY | jiggers.OffsetY) != 0) + if (jiggers.Intensity.Y != 0 || jiggers.Offset.Y != 0) { - viewy += QuakePower(quakefactor, jiggers.IntensityY, jiggers.OffsetY, jiggers.Falloff, jiggers.WFalloff); + viewy += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.Y, jiggers.Offset.Y, jiggers.Falloff, jiggers.WFalloff)); } - if ((jiggers.IntensityZ | jiggers.OffsetZ) != 0) + if (jiggers.Intensity.Z != 0 || jiggers.Offset.Z != 0) { - viewz += QuakePower(quakefactor, jiggers.IntensityZ, jiggers.OffsetZ, jiggers.Falloff, jiggers.WFalloff); + viewz += FLOAT2FIXED(QuakePower(quakefactor, jiggers.Intensity.Z, jiggers.Offset.Z, jiggers.Falloff, jiggers.WFalloff)); } } } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 8c2a664e2..4ac179305 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -2028,7 +2028,7 @@ DEFINE_CLASS_PROPERTY(upsound, S, Weapon) //========================================================================== DEFINE_CLASS_PROPERTY(yadjust, F, Weapon) { - PROP_FIXED_PARM(i, 0); + PROP_FLOAT_PARM(i, 0); defaults->YAdjust = i; } @@ -2056,7 +2056,7 @@ DEFINE_CLASS_PROPERTY(bobstyle, S, Weapon) //========================================================================== DEFINE_CLASS_PROPERTY(bobspeed, F, Weapon) { - PROP_FIXED_PARM(i, 0); + PROP_FLOAT_PARM(i, 0); defaults->BobSpeed = i; } @@ -2065,7 +2065,7 @@ DEFINE_CLASS_PROPERTY(bobspeed, F, Weapon) //========================================================================== DEFINE_CLASS_PROPERTY(bobrangex, F, Weapon) { - PROP_FIXED_PARM(i, 0); + PROP_FLOAT_PARM(i, 0); defaults->BobRangeX = i; } @@ -2074,7 +2074,7 @@ DEFINE_CLASS_PROPERTY(bobrangex, F, Weapon) //========================================================================== DEFINE_CLASS_PROPERTY(bobrangey, F, Weapon) { - PROP_FIXED_PARM(i, 0); + PROP_FLOAT_PARM(i, 0); defaults->BobRangeY = i; } diff --git a/src/vectors.h b/src/vectors.h index cbc221b1f..cc51f779f 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -1041,14 +1041,14 @@ struct TAngle return FLOAT2ANGLE(Degrees) >> 16; } - double Cos() const + vec_t Cos() const { - return g_cosdeg(Degrees); + return vec_t(g_cosdeg(Degrees)); } - double Sin() const + vec_t Sin() const { - return g_sindeg(Degrees); + return vec_t(g_sindeg(Degrees)); } double Tan() const @@ -1354,7 +1354,7 @@ typedef TVector2 FVector2; typedef TVector3 FVector3; typedef TRotator FRotator; typedef TMatrix3x3 FMatrix3x3; -//typedef TAngle FAngle; +typedef TAngle FAngle; typedef TVector2 DVector2; typedef TVector3 DVector3;