mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-21 03:01:36 +00:00
- Clean up some q16horiz usage and how the view pitch is clamped.
This commit is contained in:
parent
4ef9ec93ea
commit
5851c0f2c6
18 changed files with 37 additions and 26 deletions
|
@ -53,7 +53,6 @@ class FSerializer;
|
|||
|
||||
inline double HorizToPitch(double horiz) { return atan2(horiz, 128) * (180. / pi::pi()); }
|
||||
inline double HorizToPitch(fixed_t q16horiz) { return atan2(q16horiz, IntToFixed(128)) * (180. / pi::pi()); }
|
||||
inline fixed_t PitchToHoriz(double pitch) { return xs_CRoundToInt(clamp<double>(IntToFixed(128) * tan(pitch * (pi::pi() / 180.)), INT32_MIN, INT32_MAX)); }
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -183,7 +182,7 @@ public:
|
|||
inline constexpr fixedhoriz q16horiz(fixed_t v) { return fixedhoriz(v); }
|
||||
inline constexpr fixedhoriz buildhoriz(int v) { return fixedhoriz(IntToFixed(v)); }
|
||||
inline constexpr fixedhoriz tanhoriz(double v) { return fixedhoriz(FloatToFixed<23>(v)); }
|
||||
inline fixedhoriz pitchhoriz(double v) { return fixedhoriz(PitchToHoriz(v)); }
|
||||
inline fixedhoriz pitchhoriz(double v) { return fixedhoriz(fixed_t(clamp<double>(IntToFixed(128) * tan(v * (pi::pi() / 180.)), -INT32_MAX, INT32_MAX))); }
|
||||
|
||||
inline FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj, fixedhoriz *defval)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "gamecontrol.h"
|
||||
#include "gamestruct.h"
|
||||
#include "build.h"
|
||||
#include "coreactor.h"
|
||||
#include "fixedhorizon.h"
|
||||
|
@ -536,6 +537,21 @@ inline double BobVal(double val)
|
|||
return g_sinbam(xs_CRoundToUInt(val * (1 << 21)));
|
||||
}
|
||||
|
||||
inline double GetMinPitch()
|
||||
{
|
||||
return gi->playerPitchMin();
|
||||
}
|
||||
|
||||
inline double GetMaxPitch()
|
||||
{
|
||||
return gi->playerPitchMax();
|
||||
}
|
||||
|
||||
inline double ClampViewPitch(const double pitch)
|
||||
{
|
||||
return clamp(pitch, GetMinPitch(), GetMaxPitch());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// old deprecated integer versions
|
||||
|
|
|
@ -256,7 +256,7 @@ void PlayerHorizon::applyinput(float const horz, ESyncBits* actions, double cons
|
|||
doKbdInput(SB_LOOK_UP, SB_LOOK_DOWN, LOOKSPEED, false);
|
||||
|
||||
// clamp before converting back to horizon
|
||||
horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
horiz = pitchhoriz(ClampViewPitch(pitch));
|
||||
}
|
||||
|
||||
// return to center if conditions met.
|
||||
|
|
|
@ -62,7 +62,7 @@ struct PlayerHorizon
|
|||
void settarget(fixedhoriz value, bool const backup = false)
|
||||
{
|
||||
// Clamp incoming variable because sometimes the caller can exceed bounds.
|
||||
value = q16horiz(clamp(value.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
value = pitchhoriz(ClampViewPitch(value.Degrees()));
|
||||
|
||||
if (!SyncInput() && !backup)
|
||||
{
|
||||
|
|
|
@ -109,8 +109,8 @@ struct GameInterface
|
|||
virtual void LevelCompleted(MapRecord* map, int skill) {}
|
||||
virtual bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) { return false; }
|
||||
virtual void SetTileProps(int tile, int surf, int vox, int shade) {}
|
||||
virtual fixed_t playerHorizMin() { return IntToFixed(-200); }
|
||||
virtual fixed_t playerHorizMax() { return IntToFixed(200); }
|
||||
virtual double playerPitchMin() { return -57.375; }
|
||||
virtual double playerPitchMax() { return 57.375; }
|
||||
virtual void WarpToCoords(double x, double y, double z, DAngle a, int h) {}
|
||||
virtual void ToggleThirdPerson() { }
|
||||
virtual void SwitchCoopView() { Printf("Unsupported command\n"); }
|
||||
|
|
|
@ -200,7 +200,7 @@ FRenderViewpoint SetupViewpoint(DCoreActor* cam, const DVector3& position, int s
|
|||
r_viewpoint.SectCount = sectnum;
|
||||
r_viewpoint.Pos = { position.X, -position.Y, -position.Z };
|
||||
r_viewpoint.HWAngles.Yaw = FAngle::fromDeg(-90.f + (float)angle.Degrees());
|
||||
r_viewpoint.HWAngles.Pitch = FAngle::fromDeg(-horizon.Degrees());
|
||||
r_viewpoint.HWAngles.Pitch = FAngle::fromDeg(-ClampViewPitch(horizon.Degrees()));
|
||||
r_viewpoint.HWAngles.Roll = FAngle::fromDeg(-(float)rollang.Degrees());
|
||||
r_viewpoint.FieldOfView = FAngle::fromDeg(fov > 0? fov : (float)r_fov);
|
||||
r_viewpoint.RotAngle = angle.BAMs();
|
||||
|
|
|
@ -133,8 +133,8 @@ struct GameInterface : public ::GameInterface
|
|||
void LevelCompleted(MapRecord* map, int skill) override;
|
||||
bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override;
|
||||
void SetTileProps(int til, int surf, int vox, int shade) override;
|
||||
fixed_t playerHorizMin() override { return IntToFixed(-180); }
|
||||
fixed_t playerHorizMax() override { return IntToFixed(120); }
|
||||
double playerPitchMin() override { return -54.575; }
|
||||
double playerPitchMax() override { return 43.15; }
|
||||
void WarpToCoords(double x, double y, double z, DAngle a, int h) override;
|
||||
void ToggleThirdPerson() override;
|
||||
void SwitchCoopView() override;
|
||||
|
|
|
@ -1556,7 +1556,7 @@ void ProcessInput(PLAYER* pPlayer)
|
|||
}
|
||||
pPlayer->deathTime += 4;
|
||||
if (!bSeqStat)
|
||||
pPlayer->horizon.addadjustment(q16horiz(MulScale(0x8000 - (Cos(ClipHigh(pPlayer->deathTime << 3, 1024)) >> 15), gi->playerHorizMax(), 16) - pPlayer->horizon.horiz.asq16()));
|
||||
pPlayer->horizon.addadjustment(q16horiz(MulScale(0x8000 - (Cos(ClipHigh(pPlayer->deathTime << 3, 1024)) >> 15), pitchhoriz(gi->playerPitchMax()).asq16(), 16) - pPlayer->horizon.horiz.asq16()));
|
||||
if (pPlayer->curWeapon)
|
||||
pInput->setNewWeapon(pPlayer->curWeapon);
|
||||
if (pInput->actions & SB_OPEN)
|
||||
|
|
|
@ -721,7 +721,6 @@ void viewDrawScreen(bool sceneonly)
|
|||
cPos.Z = ceilingZ + 1;
|
||||
}
|
||||
}
|
||||
cH = q16horiz(ClipRange(cH.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
|
||||
if ((tilt.Degrees() || bDelirium) && !sceneonly)
|
||||
{
|
||||
|
|
|
@ -925,7 +925,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
|
|||
|
||||
case PLAYER_RETURN_TO_CENTER:
|
||||
if (bSet) ps[iPlayer].sync.actions |= SB_CENTERVIEW;
|
||||
else SetGameVarID(lVar2, ps[iPlayer].sync.actions & SB_CENTERVIEW ? abs(int(ps[iPlayer].horizon.horiz.asq16() * (9. / gi->playerHorizMax()))) : 0, sActor, sPlayer);
|
||||
else SetGameVarID(lVar2, ps[iPlayer].sync.actions & SB_CENTERVIEW ? abs(int(ps[iPlayer].horizon.horiz.asq16() * (9. / pitchhoriz(GetMaxPitch()).asq16()))) : 0, sActor, sPlayer);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -357,8 +357,6 @@ void displayrooms(int snum, double interpfrac, bool sceneonly)
|
|||
getzsofslopeptr(sect, cpos, &cz, &fz);
|
||||
cpos.Z = min(max(cpos.Z, cz + 4), fz - 4);
|
||||
}
|
||||
|
||||
choriz = clamp(choriz, q16horiz(gi->playerHorizMin()), q16horiz(gi->playerHorizMax()));
|
||||
}
|
||||
|
||||
auto cstat = viewer->spr.cstat;
|
||||
|
|
|
@ -231,8 +231,8 @@ struct GameInterface : public ::GameInterface
|
|||
void LevelCompleted(MapRecord *map, int skill) override;
|
||||
void NextLevel(MapRecord *map, int skill) override;
|
||||
bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const interpfrac) override;
|
||||
fixed_t playerHorizMin() override { return IntToFixed(-150); }
|
||||
fixed_t playerHorizMax() override { return IntToFixed(150); }
|
||||
double playerPitchMin() override { return -49.5; }
|
||||
double playerPitchMax() override { return 49.5; }
|
||||
void WarpToCoords(double x, double y, double z, DAngle ang, int horz) override;
|
||||
void ToggleThirdPerson() override;
|
||||
DVector3 chaseCamPos(DAngle ang, fixedhoriz horiz) { return DVector3(-ang.ToVector() * 96., horiz.Tan() * 96.); }
|
||||
|
|
|
@ -1162,7 +1162,7 @@ void AIPlayer::Tick(RunListEvent* ev)
|
|||
sectdone:
|
||||
if (!PlayerList[nPlayer].bPlayerPan && !PlayerList[nPlayer].bLockPan)
|
||||
{
|
||||
PlayerList[nPlayer].nDestVertPan = q16horiz(clamp((int((spr_pos.Z - pPlayerActor->spr.pos.Z) * zworldtoint)) << 9, gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
PlayerList[nPlayer].nDestVertPan = maphoriz((spr_pos.Z - pPlayerActor->spr.pos.Z) * 2.);
|
||||
}
|
||||
|
||||
playerPos -= pPlayerActor->spr.pos.XY();
|
||||
|
@ -2630,9 +2630,9 @@ sectdone:
|
|||
{
|
||||
PlayerList[nPlayer].horizon.addadjustment(buildhoriz(dVertPan[nPlayer]));
|
||||
|
||||
if (PlayerList[nPlayer].horizon.horiz.asq16() > gi->playerHorizMax())
|
||||
if (PlayerList[nPlayer].horizon.horiz.asq16() >= IntToFixed(100))
|
||||
{
|
||||
PlayerList[nPlayer].horizon.settarget(q16horiz(gi->playerHorizMax()));
|
||||
PlayerList[nPlayer].horizon.settarget(buildhoriz(99));
|
||||
}
|
||||
else if (PlayerList[nPlayer].horizon.horiz.asq16() <= 0)
|
||||
{
|
||||
|
|
|
@ -255,7 +255,6 @@ void DrawView(double interpfrac, bool sceneonly)
|
|||
pPlayerActor->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT;
|
||||
pDop->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
|
||||
}
|
||||
nCamerapan = q16horiz(clamp(nCamerapan.asq16(), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
}
|
||||
|
||||
if (nSnakeCam >= 0 && !sceneonly)
|
||||
|
|
|
@ -1311,7 +1311,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly)
|
|||
}
|
||||
|
||||
// recoil only when not in camera
|
||||
thoriz = q16horiz(clamp(thoriz.asq16() + interpolatedvalue(pp->recoil_ohorizoff, pp->recoil_horizoff, interpfrac), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
thoriz += interpolatedvalue(pp->recoil_ohorizoff, pp->recoil_horizoff, interpfrac);
|
||||
}
|
||||
|
||||
if (automapMode != am_full)
|
||||
|
|
|
@ -593,7 +593,7 @@ struct PLAYER
|
|||
int16_t recoil_amt;
|
||||
int16_t recoil_speed;
|
||||
int16_t recoil_ndx;
|
||||
fixed_t recoil_ohorizoff, recoil_horizoff;
|
||||
fixedhoriz recoil_ohorizoff, recoil_horizoff;
|
||||
|
||||
DVector3 Revolve;
|
||||
DAngle RevolveDeltaAng;
|
||||
|
|
|
@ -593,7 +593,7 @@ void JS_DrawCameras(PLAYER* pp, const DVector3& campos, double smoothratio)
|
|||
}
|
||||
|
||||
// Set the horizon value.
|
||||
auto camhoriz = q16horiz(clamp(IntToFixed(SP_TAG7(camactor) - 100), gi->playerHorizMin(), gi->playerHorizMax()));
|
||||
auto camhoriz = maphoriz(SP_TAG7(camactor) - 100);
|
||||
|
||||
// If player is dead still then update at MoveSkip4
|
||||
// rate.
|
||||
|
|
|
@ -1738,7 +1738,7 @@ void DoPlayerBeginRecoil(PLAYER* pp, short pix_amt)
|
|||
pp->recoil_amt = pix_amt;
|
||||
pp->recoil_speed = 80;
|
||||
pp->recoil_ndx = 0;
|
||||
pp->recoil_ohorizoff = pp->recoil_horizoff = 0;
|
||||
pp->recoil_ohorizoff = pp->recoil_horizoff = pitchhoriz(nullAngle.Degrees());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -1755,13 +1755,13 @@ void DoPlayerRecoil(PLAYER* pp)
|
|||
if (BobVal(pp->recoil_ndx) < 0)
|
||||
{
|
||||
pp->Flags &= ~(PF_RECOIL);
|
||||
pp->recoil_ohorizoff = pp->recoil_horizoff = 0;
|
||||
pp->recoil_ohorizoff = pp->recoil_horizoff = pitchhoriz(nullAngle.Degrees());
|
||||
return;
|
||||
}
|
||||
|
||||
// move pp->q16horiz up and down
|
||||
pp->recoil_ohorizoff = pp->recoil_horizoff;
|
||||
pp->recoil_horizoff = pp->recoil_amt * BobVal(pp->recoil_ndx) * 4;
|
||||
pp->recoil_horizoff = pitchhoriz(HorizToPitch(pp->recoil_amt * BobVal(pp->recoil_ndx)));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue