From b47097d77822b4eed1da02e4b1eefd35570051ad Mon Sep 17 00:00:00 2001 From: Ymihere03 Date: Fri, 24 May 2024 20:55:19 -0600 Subject: [PATCH 1/4] Audio during spectate free roam camera is properly centered on camera --- src/game/CAbstractPlayer.cpp | 39 +++++++++++++++++++++++++++++++----- src/game/CAbstractPlayer.h | 3 +++ src/game/CAvaraGame.cpp | 1 + src/game/CFreeCam.cpp | 17 ++++++++++++++++ src/game/CFreeCam.h | 1 + 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/game/CAbstractPlayer.cpp b/src/game/CAbstractPlayer.cpp index 14f5a390..4152340b 100644 --- a/src/game/CAbstractPlayer.cpp +++ b/src/game/CAbstractPlayer.cpp @@ -89,6 +89,8 @@ void CAbstractPlayer::LoadHUDParts() { dirArrow->isTransparent = true; gRenderer->AddHUDPart(dirArrow); + showHud = itsGame->showNewHUD; + hudPreset = itsGame->itsApp->Get(kHUDPreset); LoadDashboardParts(); } @@ -359,7 +361,7 @@ CAbstractPlayer::~CAbstractPlayer() { } void CAbstractPlayer::DisposeDashboard() { - if (!itsGame->showNewHUD) return; + if (!showHud) return; if (itsGame->itsApp->Get(kHUDShowMissileLock)) { gRenderer->RemoveHUDPart(lockLight); @@ -450,7 +452,8 @@ void CAbstractPlayer::PlaceHUDParts() { RayHitRecord theHit; CWeapon *weapon = NULL; - if (itsGame->itsApp->Get(kHUDArrowStyle) == 1) { + // Make sure we always default to the old style arrow if other arrow styles are turned off + if ((itsGame->itsApp->Get(kHUDArrowStyle) == 1) || !itsGame->showNewHUD) { dirArrow->Reset(); InitialRotatePartY(dirArrow, heading); TranslatePart(dirArrow, location[0], location[1] + dirArrowHeight, location[2]); @@ -672,8 +675,30 @@ void CAbstractPlayer::LoadDashboardParts() { } } +// Check if the user changed the 'showNewHud' pref +// Load or Unload the dashboard based on the new setting +void CAbstractPlayer::DashboardReloadCheck() { + // User toggled the entire HUD on/off + if (showHud != itsGame->showNewHUD) { + if (itsGame->showNewHUD) { + LoadDashboardParts(); + } else { + DisposeDashboard(); + } + showHud = itsGame->showNewHUD; + } + + // User changed the hud layout + if (hudPreset != itsGame->itsApp->Get(kHUDPreset)) { + DisposeDashboard(); + LoadDashboardParts(); + hudPreset = itsGame->itsApp->Get(kHUDPreset); + } +} + // Place parts on screen void CAbstractPlayer::RenderDashboard() { + DashboardReloadCheck(); if (!itsGame->showNewHUD) return; if (scoutView) { ResetDashboard(); @@ -955,7 +980,8 @@ void CAbstractPlayer::DashboardFixedPosition(CScaledBSP *part, float dist, Fixed } void CAbstractPlayer::ResetDashboard() { - if (!itsGame->showNewHUD) return; + DashboardReloadCheck(); + if (!showHud) return; if (itsGame->itsApp->Get(kHUDShowMissileLock)) { lockLight->isTransparent = true; @@ -1054,7 +1080,9 @@ void CAbstractPlayer::ControlViewPoint() { RecalculateViewDistance(); // SetPort(itsGame->itsWindow); - ControlSoundPoint(); + if (!freeView) { + ControlSoundPoint(); + } } void CAbstractPlayer::RecalculateViewDistance() { @@ -1355,7 +1383,8 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) { } } - if (winFrame < 0) { + // Disable scout controls while spectating + if (winFrame < 0 && !freeView && itsGame->GetSpectatePlayer() == NULL) { Boolean doRelease = false; if (TESTFUNC(kfuScoutView, ft->down)) { diff --git a/src/game/CAbstractPlayer.h b/src/game/CAbstractPlayer.h index d5f4cf02..8e3029d4 100644 --- a/src/game/CAbstractPlayer.h +++ b/src/game/CAbstractPlayer.h @@ -243,6 +243,8 @@ class CAbstractPlayer : public CRealMovers { float boosterSpacing; float livesSpacing; float weaponSpacing; + Boolean showHud; // Store pref to detect if the user changes it during a game + int hudPreset; // Store pref to detect if the user changes it during a game virtual void BeginScript(); virtual CAbstractActor *EndScript(); @@ -282,6 +284,7 @@ class CAbstractPlayer : public CRealMovers { virtual void PlaceHUDParts(); // + virtual void DashboardReloadCheck(); virtual void LoadDashboardParts(); virtual CScaledBSP* DashboardPart(uint16_t id); virtual CScaledBSP* DashboardPart(uint16_t id, Fixed scale); diff --git a/src/game/CAvaraGame.cpp b/src/game/CAvaraGame.cpp index 05d90a67..22ed2687 100755 --- a/src/game/CAvaraGame.cpp +++ b/src/game/CAvaraGame.cpp @@ -1021,6 +1021,7 @@ void CAvaraGame::StopGame() { void CAvaraGame::Render() { //if (gameStatus == kPlayingStatus || gameStatus == kPauseStatus || gameStatus == kWinStatus || gameStatus == kLoseStatus) { + showNewHUD = gApplication ? gApplication->Get(kShowNewHUD) : false; ViewControl(); gRenderer->RenderFrame(); } diff --git a/src/game/CFreeCam.cpp b/src/game/CFreeCam.cpp index f46dcdca..5e486979 100644 --- a/src/game/CFreeCam.cpp +++ b/src/game/CFreeCam.cpp @@ -10,6 +10,7 @@ CFreeCam::CFreeCam(CAbstractPlayer *thePlayer) { itsPlayer = thePlayer; itsGame = thePlayer->itsGame; + itsSoundLink = gHub->GetSoundLink(); camSpeed = 350; radius = FIX3(25000); @@ -154,10 +155,26 @@ void CFreeCam::ViewControl(FunctionTable *ft) { void CFreeCam::FrameAction() { } +void CFreeCam::ControlSoundPoint(CViewParameters *vp) { + Fixed theRight[] = {FIX(-1), 0, 0}; + + // This hard-coded data matches the vector data used for ControlSoundPoint() in AbstractPlayer.cpp + // The matrix data from viewParams differs from the hard-coded data in a way that makes the sound not play in the correct channels + theRight[0] = FIX3(707); + theRight[1] = 0; + theRight[2] = FIX3(707); + + gHub->SetMixerLink(itsSoundLink); + gHub->UpdateRightVector(theRight); +} + void CFreeCam::ControlViewPoint() { auto vp = gRenderer->viewParams; vp->LookFrom(vp->fromPoint[0], vp->fromPoint[1], vp->fromPoint[2]); vp->LookAt(vp->atPoint[0], vp->atPoint[1], vp->atPoint[2]); vp->PointCamera(); + + UpdateSoundLink(itsSoundLink, vp->fromPoint, speed, itsGame->soundTime); + ControlSoundPoint(vp); } \ No newline at end of file diff --git a/src/game/CFreeCam.h b/src/game/CFreeCam.h index b3b6cb33..c0b43551 100644 --- a/src/game/CFreeCam.h +++ b/src/game/CFreeCam.h @@ -27,4 +27,5 @@ class CFreeCam final : public CRealMovers { virtual Boolean IsAttached(); virtual void SetAttached(Boolean attach); virtual void ControlViewPoint(); + virtual void ControlSoundPoint(CViewParameters* vp); }; \ No newline at end of file From 43d7f6a334372c242b400b160fff61dfa7612174 Mon Sep 17 00:00:00 2001 From: Ymihere03 Date: Wed, 29 May 2024 19:14:43 -0600 Subject: [PATCH 2/4] All spectate controls can only be used after the limbo timer completes --- src/game/CAbstractPlayer.cpp | 12 +++++++----- src/game/CAbstractPlayer.h | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/game/CAbstractPlayer.cpp b/src/game/CAbstractPlayer.cpp index 4152340b..a12b0ff8 100644 --- a/src/game/CAbstractPlayer.cpp +++ b/src/game/CAbstractPlayer.cpp @@ -205,8 +205,8 @@ void CAbstractPlayer::LoadFreeCam() { SetFreeCamState(false); } -void CAbstractPlayer::WriteDBG(int index, float val) { - freeCamDBG[index] = val; +void CAbstractPlayer::WriteDBG(float val) { + freeCamDBG.push_back(val); } void CAbstractPlayer::ReplacePartColors() { @@ -1329,7 +1329,8 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) { if (TESTFUNC(kfuLoadMissile, ft->down)) ArmSmartMissile(); } - else if(lives == 0) { + else if(lives == 0 && limboCount < 0) { + // These controls only function after the limbo pause if (itsManager->IsLocalPlayer() && TESTFUNC(kfuSpectateNext, ft->down)) { itsGame->SpectateNext(); if (freeView) { @@ -1429,9 +1430,9 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) { if (TESTFUNC(kfuDebug2, ft->down)) debug2Flag = !debug2Flag; - if (TESTFUNC(kfuZoomIn, ft->held)) + if (TESTFUNC(kfuZoomIn, ft->held) && !freeView) fieldOfView -= FOVSTEP; - if (TESTFUNC(kfuZoomOut, ft->held)) + if (TESTFUNC(kfuZoomOut, ft->held) && !freeView) fieldOfView += FOVSTEP; #define LOOKSTEP FpsCoefficient2(0x1000L) @@ -1623,6 +1624,7 @@ void CAbstractPlayer::PlayerAction() { } Reincarnate(); } else { + limboCount = -1; // No need for limboCount to continue counting down at this point itsManager->DeadOrDone(); // Auto spectate another player if: diff --git a/src/game/CAbstractPlayer.h b/src/game/CAbstractPlayer.h index 8e3029d4..86968829 100644 --- a/src/game/CAbstractPlayer.h +++ b/src/game/CAbstractPlayer.h @@ -184,7 +184,7 @@ class CAbstractPlayer : public CRealMovers { Fixed supportTraction = 0; Fixed supportFriction = 0; - double freeCamDBG[18] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + std::deque freeCamDBG; // Hud parts: CBSPPart *dirArrow = 0; @@ -255,7 +255,7 @@ class CAbstractPlayer : public CRealMovers { virtual void LoadParts(); virtual void LoadScout(); virtual void LoadFreeCam(); - virtual void WriteDBG(int index, float val); + virtual void WriteDBG(float val); virtual void StartSystems(); virtual void LevelReset(); From a5dfe3f9fa98e4e72af4ef42ed3ddbc8cd5f4450 Mon Sep 17 00:00:00 2001 From: Ymihere03 Date: Wed, 29 May 2024 22:09:42 -0600 Subject: [PATCH 3/4] Minor changes --- src/game/CAbstractPlayer.h | 2 +- src/game/CFreeCam.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/game/CAbstractPlayer.h b/src/game/CAbstractPlayer.h index 86968829..769dbcfb 100644 --- a/src/game/CAbstractPlayer.h +++ b/src/game/CAbstractPlayer.h @@ -184,7 +184,7 @@ class CAbstractPlayer : public CRealMovers { Fixed supportTraction = 0; Fixed supportFriction = 0; - std::deque freeCamDBG; + std::deque freeCamDBG; // Hud parts: CBSPPart *dirArrow = 0; diff --git a/src/game/CFreeCam.cpp b/src/game/CFreeCam.cpp index 5e486979..a7563821 100644 --- a/src/game/CFreeCam.cpp +++ b/src/game/CFreeCam.cpp @@ -158,12 +158,14 @@ void CFreeCam::FrameAction() { void CFreeCam::ControlSoundPoint(CViewParameters *vp) { Fixed theRight[] = {FIX(-1), 0, 0}; - // This hard-coded data matches the vector data used for ControlSoundPoint() in AbstractPlayer.cpp - // The matrix data from viewParams differs from the hard-coded data in a way that makes the sound not play in the correct channels + // For whatever reason, the viewParams matrix data didn't + // provide the correct vector to make the sound play in the correct channels + // so I copied the values used for the RightVector in ControlSoundPoint() in AbstractPlayer.cpp theRight[0] = FIX3(707); theRight[1] = 0; theRight[2] = FIX3(707); - + + UpdateSoundLink(itsSoundLink, vp->fromPoint, speed, itsGame->soundTime); gHub->SetMixerLink(itsSoundLink); gHub->UpdateRightVector(theRight); } @@ -175,6 +177,5 @@ void CFreeCam::ControlViewPoint() { vp->LookAt(vp->atPoint[0], vp->atPoint[1], vp->atPoint[2]); vp->PointCamera(); - UpdateSoundLink(itsSoundLink, vp->fromPoint, speed, itsGame->soundTime); ControlSoundPoint(vp); } \ No newline at end of file From 68c56ef8b29e3c08db19845a0af5c1ddf877ed76 Mon Sep 17 00:00:00 2001 From: Ymihere03 Date: Wed, 29 May 2024 23:06:01 -0600 Subject: [PATCH 4/4] Auto-spectate now uses limbo timer to not switch spectate player too quickly --- src/game/CAbstractPlayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/CAbstractPlayer.cpp b/src/game/CAbstractPlayer.cpp index a12b0ff8..d3db6b3b 100644 --- a/src/game/CAbstractPlayer.cpp +++ b/src/game/CAbstractPlayer.cpp @@ -1629,9 +1629,9 @@ void CAbstractPlayer::PlayerAction() { // Auto spectate another player if: // - The player runs out of lives - // - The player being spectated runs out of lives + // - The player being spectated runs out of lives (check that players limbo timer to prevent fast transition) if ((itsGame->GetSpectatePlayer() == NULL && itsManager->IsLocalPlayer()) || - (itsGame->GetSpectatePlayer() != NULL && itsGame->GetSpectatePlayer()->lives == 0)) { + (itsGame->GetSpectatePlayer() != NULL && itsGame->GetSpectatePlayer()->lives == 0 && itsGame->GetSpectatePlayer()->limboCount <= 0)) { itsGame->SpectateNext(); } }