From 6531cc065ec929b6d12d0df01482c60bc1362463 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 14 Aug 2023 01:16:35 -0700 Subject: [PATCH] Fix sound handling in demo freecam - Object sounds are audible from the location of the camera - Certain HUD sounds should no longer be audible - For instance, lap complete sfx --- src/g_demo.c | 1 - src/p_local.h | 1 - src/p_user.c | 20 +++++++++----------- src/s_sound.c | 23 ++++++++--------------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index 52cfdf978..16c972c26 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -3993,7 +3993,6 @@ void G_StopDemo(void) demo.freecam = false; // reset democam shit too: democam.cam = NULL; - democam.soundmobj = NULL; democam.localangle = 0; democam.localaiming = 0; democam.keyboardlook = false; diff --git a/src/p_local.h b/src/p_local.h index bfcccf4a4..fc5307be2 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -137,7 +137,6 @@ struct camera_t struct demofreecam_s { camera_t *cam; // this is useful when the game is paused, notably - mobj_t *soundmobj; // mobj to play sound from, used in s_sound angle_t localangle; // keeps track of the cam angle for cmds angle_t localaiming; // ditto with aiming diff --git a/src/p_user.c b/src/p_user.c index a50396c4e..c3a4ae9df 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1137,6 +1137,15 @@ boolean P_IsDisplayPlayer(player_t *player) return false; } + // Freecam still techically has a player in + // displayplayers. But since the camera is detached, it + // would be weird if sounds were heard from that player's + // perspective. + if (demo.freecam) + { + return false; + } + for (i = 0; i <= r_splitscreen; i++) // DON'T skip P1 { if (player == &players[displayplayers[i]]) @@ -2685,7 +2694,6 @@ void P_DemoCameraMovement(camera_t *cam) { ticcmd_t *cmd = &cameracmd;; angle_t thrustangle; - mobj_t *awayviewmobj_hack; player_t *lastp; // update democam stuff with what we got here: @@ -2734,14 +2742,6 @@ void P_DemoCameraMovement(camera_t *cam) // besides freecam going inside walls sounds pretty cool on paper. } - // awayviewmobj hack; this is to prevent us from hearing sounds from the player's perspective - - awayviewmobj_hack = P_SpawnMobj(cam->x, cam->y, cam->z, MT_THOK); - awayviewmobj_hack->tics = 2; - awayviewmobj_hack->renderflags |= RF_DONTDRAW; - - democam.soundmobj = awayviewmobj_hack; - // update subsector to avoid crashes; cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); } @@ -2812,8 +2812,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall thiscam->old_angle = thiscam->angle; thiscam->old_aiming = thiscam->aiming; - democam.soundmobj = NULL; // reset this each frame, we don't want the game crashing for stupid reasons now do we - // We probably shouldn't move the camera if there is no player or player mobj somehow if (!player || !player->mo) return true; diff --git a/src/s_sound.c b/src/s_sound.c index 3a6b606da..14b9ba89c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -545,11 +545,6 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) continue; } - if (i == 0 && democam.soundmobj) - { - continue; - } - if (player->awayviewtics) { listenmobj[i] = player->awayviewmobj; @@ -559,7 +554,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) listenmobj[i] = player->mo; } - if (origin && origin == listenmobj[i]) + if (origin && origin == listenmobj[i] && !demo.freecam) { itsUs = true; } @@ -810,11 +805,6 @@ void S_UpdateSounds(void) continue; } - if (i == 0 && democam.soundmobj) - { - continue; - } - if (player->awayviewtics) { listenmobj[i] = player->awayviewmobj; @@ -881,12 +871,15 @@ void S_UpdateSounds(void) { boolean itsUs = false; - for (i = r_splitscreen; i >= 0; i--) + if (!demo.freecam) { - if (c->origin != listenmobj[i]) - continue; + for (i = r_splitscreen; i >= 0; i--) + { + if (c->origin != listenmobj[i]) + continue; - itsUs = true; + itsUs = true; + } } if (itsUs == false)