Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed audio during spectate free roam camera and other fixes #407

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions src/game/CAbstractPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ void CAbstractPlayer::LoadHUDParts() {
dirArrow->isTransparent = true;
gRenderer->AddHUDPart(dirArrow);

showHud = itsGame->showNewHUD;
hudPreset = itsGame->itsApp->Get(kHUDPreset);
LoadDashboardParts();
}

Expand Down Expand Up @@ -203,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() {
Expand Down Expand Up @@ -359,7 +361,7 @@ CAbstractPlayer::~CAbstractPlayer() {
}

void CAbstractPlayer::DisposeDashboard() {
if (!itsGame->showNewHUD) return;
if (!showHud) return;

if (itsGame->itsApp->Get(kHUDShowMissileLock)) {
gRenderer->RemoveHUDPart(lockLight);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1054,7 +1080,9 @@ void CAbstractPlayer::ControlViewPoint() {
RecalculateViewDistance();

// SetPort(itsGame->itsWindow);
ControlSoundPoint();
if (!freeView) {
ControlSoundPoint();
}
}

void CAbstractPlayer::RecalculateViewDistance() {
Expand Down Expand Up @@ -1301,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) {
Expand Down Expand Up @@ -1355,7 +1384,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)) {
Expand Down Expand Up @@ -1400,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)
Expand Down Expand Up @@ -1594,13 +1624,14 @@ 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:
// - 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();
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/game/CAbstractPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> freeCamDBG;

// Hud parts:
CBSPPart *dirArrow = 0;
Expand Down Expand Up @@ -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();
Expand All @@ -253,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();

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/game/CAvaraGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ void CAvaraGame::StopGame() {

void CAvaraGame::Render() {
//if (gameStatus == kPlayingStatus || gameStatus == kPauseStatus || gameStatus == kWinStatus || gameStatus == kLoseStatus) {
showNewHUD = gApplication ? gApplication->Get<bool>(kShowNewHUD) : false;
ViewControl();
gRenderer->RenderFrame();
}
Expand Down
18 changes: 18 additions & 0 deletions src/game/CFreeCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CFreeCam::CFreeCam(CAbstractPlayer *thePlayer) {
itsPlayer = thePlayer;
itsGame = thePlayer->itsGame;
itsSoundLink = gHub->GetSoundLink();

camSpeed = 350;
radius = FIX3(25000);
Expand Down Expand Up @@ -154,10 +155,27 @@ void CFreeCam::ViewControl(FunctionTable *ft) {
void CFreeCam::FrameAction() {
}

void CFreeCam::ControlSoundPoint(CViewParameters *vp) {
Fixed theRight[] = {FIX(-1), 0, 0};

// 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);
}

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();

ControlSoundPoint(vp);
}
1 change: 1 addition & 0 deletions src/game/CFreeCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Loading