diff --git a/game/neo/scripts/game_sounds_player.txt b/game/neo/scripts/game_sounds_player.txt index 1741ded4b..b772c35fc 100644 --- a/game/neo/scripts/game_sounds_player.txt +++ b/game/neo/scripts/game_sounds_player.txt @@ -25,13 +25,22 @@ "NeoPlayer.VisionOn" { - "channel" "CHAN_ITEM" + "channel" "137" // CHAN_VISION "volume" "VOL_NORM" "soundlevel" "SNDLVL_75dB" "wave" "player/vision_on.wav" } +"NeoPlayer.VisionOff" +{ + "channel" "137" // CHAN_VISION + "volume" "VOL_NORM" + "soundlevel" "SNDLVL_75dB" + + "wave" "player/vision_off.wav" +} + "NeoPlayer.RankUp" { "channel" "CHAN_ITEM" diff --git a/game/neo/scripts/game_sounds_ui.txt b/game/neo/scripts/game_sounds_ui.txt index 47f326bf7..1bd1ea41d 100644 --- a/game/neo/scripts/game_sounds_ui.txt +++ b/game/neo/scripts/game_sounds_ui.txt @@ -92,7 +92,7 @@ "HUD.GhostPickUp" { - "channel" "CHAN_ITEM" + "channel" "136" // CHAN_GHOST_PICKUP "volume" "0.9" "pitch" "PITCH_NORM" diff --git a/src/game/client/neo/c_neo_player.cpp b/src/game/client/neo/c_neo_player.cpp index 0b6563fae..5bfc8bd7c 100644 --- a/src/game/client/neo/c_neo_player.cpp +++ b/src/game/client/neo/c_neo_player.cpp @@ -94,7 +94,7 @@ IMPLEMENT_CLIENTCLASS_DT(C_NEO_Player, DT_NEO_Player, CNEO_Player) RecvPropBool(RECVINFO(m_bCarryingGhost)), RecvPropTime(RECVINFO(m_flCamoAuxLastTime)), - RecvPropInt(RECVINFO(m_nVisionLastTick)), + RecvPropTime(RECVINFO(m_flVisionLastTime)), RecvPropTime(RECVINFO(m_flJumpLastTime)), RecvPropTime(RECVINFO(m_flNextPingTime)), @@ -123,7 +123,7 @@ BEGIN_PREDICTION_DATA(C_NEO_Player) DEFINE_PRED_FIELD(m_bInVision, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bHasBeenAirborneForTooLongToSuperJump, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), - DEFINE_PRED_FIELD(m_nVisionLastTick, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD_TOL(m_flVisionLastTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE), DEFINE_PRED_FIELD_TOL(m_flJumpLastTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE), DEFINE_PRED_FIELD_TOL(m_flNextPingTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE), END_PREDICTION_DATA() @@ -458,7 +458,7 @@ C_NEO_Player::C_NEO_Player() m_bInLean = NEO_LEAN_NONE; m_flCamoAuxLastTime = 0; - m_nVisionLastTick = 0; + m_flVisionLastTime = 0; m_flLastAirborneJumpOkTime = 0; m_flLastSuperJumpTime = 0; @@ -466,7 +466,6 @@ C_NEO_Player::C_NEO_Player() m_bFirstDeathTick = true; m_bPreviouslyReloading = false; m_bLastTickInThermOpticCamo = false; - m_bIsAllowedToToggleVision = false; m_bSpecRefreshedStates = false; m_flTocFactor = 0.15f; @@ -510,44 +509,6 @@ void C_NEO_Player::CheckThermOpticButtons() } } -void C_NEO_Player::CheckVisionButtons() -{ - if (!m_bIsAllowedToToggleVision) - { - return; - } - - if (m_afButtonPressed & IN_VISION) - { - if (IsAlive()) - { - m_bIsAllowedToToggleVision = false; - - m_bInVision = !m_bInVision; - - if (m_bInVision) - { - DevMsg("Playing sound at :%f\n", gpGlobals->curtime); - - C_RecipientFilter filter; - filter.AddRecipient(this); - filter.MakeReliable(); - filter.UsePredictionRules(); - - EmitSound_t params; - params.m_bEmitCloseCaption = false; - params.m_pOrigin = &GetAbsOrigin(); - params.m_nChannel = CHAN_ITEM; - params.m_nFlags |= SND_DO_NOT_OVERWRITE_EXISTING_ON_CHANNEL; - static int visionToggle = CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOn"); - params.m_hSoundScriptHandle = visionToggle; - - EmitSound(filter, entindex(), params); - } - } - } -} - void C_NEO_Player::CheckLeanButtons() { if (!IsAlive() || GetFlags() & FL_FROZEN) @@ -1595,7 +1556,7 @@ void C_NEO_Player::Spawn( void ) m_flCamoAuxLastTime = 0; m_bInVision = false; - m_nVisionLastTick = 0; + m_flVisionLastTime = 0; m_bInLean = NEO_LEAN_NONE; ClearLocalPlayerDmgReports(); @@ -1904,8 +1865,8 @@ void C_NEO_Player::PlayCloakSound(void) params.m_bEmitCloseCaption = false; params.m_hSoundScriptHandle = (m_bInThermOpticCamo ? tocOn : tocOff); params.m_pOrigin = &GetAbsOrigin(); - params.m_nChannel = CHAN_VOICE; - + params.m_nChannel = CHAN_VOICE; // NEO TODO (Adam) This doesn't change the channel this sound is played on, set correct channel in sound script + EmitSound(filter, entindex(), params); } @@ -1925,23 +1886,6 @@ void C_NEO_Player::SetCloakState(bool state) } } -void C_NEO_Player::PreDataUpdate(DataUpdateType_t updateType) -{ - if (updateType == DATA_UPDATE_DATATABLE_CHANGED) - { - if (gpGlobals->tickcount - m_nVisionLastTick < TIME_TO_TICKS(0.1f)) - { - return; - } - else - { - m_bIsAllowedToToggleVision = true; - } - } - - BaseClass::PreDataUpdate(updateType); -} - // NEO NOTE (Rain): doesn't seem to be implemented at all clientside? // Don't need to do this, unless we want it for prediction with proper implementation later. // Keeping it for now. @@ -2036,12 +1980,11 @@ void C_NEO_Player::CSpectatorTakeoverPlayerUpdate(C_NEO_Player* pPlayerTakeoverT m_bInLean = pPlayerTakeoverTarget->m_bInLean; m_flCamoAuxLastTime = pPlayerTakeoverTarget->m_flCamoAuxLastTime; - m_nVisionLastTick = pPlayerTakeoverTarget->m_nVisionLastTick; + m_flVisionLastTime = pPlayerTakeoverTarget->m_flVisionLastTime; m_flLastAirborneJumpOkTime = pPlayerTakeoverTarget->m_flLastAirborneJumpOkTime; m_flLastSuperJumpTime = pPlayerTakeoverTarget->m_flLastSuperJumpTime; m_bPreviouslyReloading = pPlayerTakeoverTarget->m_bPreviouslyReloading; m_bLastTickInThermOpticCamo = pPlayerTakeoverTarget->m_bLastTickInThermOpticCamo; - m_bIsAllowedToToggleVision = pPlayerTakeoverTarget->m_bIsAllowedToToggleVision; m_flTocFactor = pPlayerTakeoverTarget->m_flTocFactor; pPlayerTakeoverTarget->SnatchModelInstance(this); diff --git a/src/game/client/neo/c_neo_player.h b/src/game/client/neo/c_neo_player.h index 607d7185e..4066342e1 100644 --- a/src/game/client/neo/c_neo_player.h +++ b/src/game/client/neo/c_neo_player.h @@ -46,8 +46,6 @@ class C_NEO_Player : public C_HL2MP_Player virtual void AddEntity( void ); virtual void AddPoints(int score, bool bAllowNegativeScore, bool bIgnorePlayerTakeover = false); - virtual void PreDataUpdate(DataUpdateType_t updateType) OVERRIDE; - // Should this object cast shadows? virtual ShadowType_t ShadowCastType( void ); @@ -227,7 +225,7 @@ class C_NEO_Player : public C_HL2MP_Player CNetworkVar(bool, m_bHasBeenAirborneForTooLongToSuperJump); CNetworkVar(float, m_flCamoAuxLastTime); - CNetworkVar(int, m_nVisionLastTick); + CNetworkVar(float, m_flVisionLastTime); CNetworkVar(float, m_flJumpLastTime); CNetworkVar(float, m_flNextPingTime); @@ -263,7 +261,6 @@ class C_NEO_Player : public C_HL2MP_Player bool m_bFirstAliveTick; bool m_bFirstDeathTick; bool m_bPreviouslyReloading; - bool m_bIsAllowedToToggleVision; bool m_bSpecRefreshedStates; float m_flLastAirborneJumpOkTime; diff --git a/src/game/server/neo/neo_client.cpp b/src/game/server/neo/neo_client.cpp index 24d81fade..f4ca61367 100644 --- a/src/game/server/neo/neo_client.cpp +++ b/src/game/server/neo/neo_client.cpp @@ -327,6 +327,7 @@ void Precache_NEO_Sounds( void ) CBaseEntity::PrecacheScriptSound("NeoPlayer.ThermOpticOn"); CBaseEntity::PrecacheScriptSound("NeoPlayer.ThermOpticOff"); CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOn"); + CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOff"); } //----------------------------------------------------------------------------- diff --git a/src/game/server/neo/neo_message.cpp b/src/game/server/neo/neo_message.cpp index cc886c901..d3c0b2ac3 100644 --- a/src/game/server/neo/neo_message.cpp +++ b/src/game/server/neo/neo_message.cpp @@ -87,7 +87,7 @@ void CNEO_Message::InputShowMessage(inputdata_t& inputData) filter.AddAllPlayers(); EmitSound_t ep; - ep.m_nChannel = CHAN_BODY; + ep.m_nChannel = CHAN_BODY; // NEO TODO (Adam) This doesn't change the channel this sound is played on, set correct channel in sound script ep.m_pSoundName = (char*)STRING(m_sSound); ep.m_flVolume = m_SoundVolume; ep.m_SoundLevel = ATTN_TO_SNDLVL(ATTN_NONE); diff --git a/src/game/server/neo/neo_player.cpp b/src/game/server/neo/neo_player.cpp index 7e04b45bc..411e1d746 100644 --- a/src/game/server/neo/neo_player.cpp +++ b/src/game/server/neo/neo_player.cpp @@ -69,7 +69,7 @@ SendPropBool(SENDINFO(m_bIneligibleForLoadoutPick)), SendPropBool(SENDINFO(m_bCarryingGhost)), SendPropTime(SENDINFO(m_flCamoAuxLastTime)), -SendPropInt(SENDINFO(m_nVisionLastTick), -1, SPROP_UNSIGNED), +SendPropTime(SENDINFO(m_flVisionLastTime)), SendPropTime(SENDINFO(m_flJumpLastTime)), SendPropTime(SENDINFO(m_flNextPingTime)), @@ -109,7 +109,7 @@ DEFINE_FIELD(m_bShowTestMessage, FIELD_BOOLEAN), DEFINE_FIELD(m_bInAim, FIELD_BOOLEAN), DEFINE_FIELD(m_flCamoAuxLastTime, FIELD_TIME), -DEFINE_FIELD(m_nVisionLastTick, FIELD_TICK), +DEFINE_FIELD(m_flVisionLastTime, FIELD_TIME), DEFINE_FIELD(m_flJumpLastTime, FIELD_TIME), DEFINE_FIELD(m_flNextPingTime, FIELD_TIME), @@ -597,7 +597,7 @@ CNEO_Player::CNEO_Player() V_memset(m_pszTestMessage.GetForModify(), 0, sizeof(m_pszTestMessage)); m_flCamoAuxLastTime = 0; - m_nVisionLastTick = 0; + m_flVisionLastTime = 0; m_flLastAirborneJumpOkTime = 0; m_flLastSuperJumpTime = 0; m_botThermOpticCamoDisruptedTimer.Invalidate(); @@ -735,7 +735,7 @@ void CNEO_Player::Spawn(void) m_flCamoAuxLastTime = 0; m_bInVision = false; - m_nVisionLastTick = 0; + m_flVisionLastTime = 0; m_bInLean = NEO_LEAN_NONE; m_bCorpseSet = false; m_bAllowGibbing = true; @@ -832,65 +832,6 @@ void CNEO_Player::Lean(void) } } -void CNEO_Player::CheckVisionButtons() -{ - if (m_iNeoClass == NEO_CLASS_VIP) - return; - - if (gpGlobals->tickcount - m_nVisionLastTick < TIME_TO_TICKS(0.1f)) - { - return; - } - - if (m_afButtonPressed & IN_VISION) - { - if (IsAlive()) - { - m_nVisionLastTick = gpGlobals->tickcount; - - m_bInVision = !m_bInVision; - - if (m_bInVision) - { - CRecipientFilter filter; - - // NEO TODO/FIXME (Rain): optimise this loop to once per cycle instead of repeating for each client - for (int i = 1; i <= gpGlobals->maxClients; ++i) - { - if (edict()->m_EdictIndex == i) - { - continue; - } - - auto player = UTIL_PlayerByIndex(i); - if (!player || !player->IsDead() || player->GetObserverMode() != OBS_MODE_IN_EYE) - { - continue; - } - - if (player->GetObserverTarget() == this) - { - filter.AddRecipient(player); - } - } - - if (filter.GetRecipientCount() > 0) - { - static int visionToggle = CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOn"); - - EmitSound_t params; - params.m_bEmitCloseCaption = false; - params.m_hSoundScriptHandle = visionToggle; - params.m_pOrigin = &GetAbsOrigin(); - params.m_nChannel = CHAN_ITEM; - - EmitSound(filter, edict()->m_EdictIndex, params); - } - } - } - } -} - void CNEO_Player::CheckLeanButtons() { if (!IsAlive() || GetFlags() & FL_FROZEN) @@ -1295,7 +1236,7 @@ void CNEO_Player::PlayCloakSound(bool removeLocalPlayer) params.m_bEmitCloseCaption = false; params.m_hSoundScriptHandle = (m_bInThermOpticCamo ? tocOn : tocOff); params.m_pOrigin = &GetAbsOrigin(); - params.m_nChannel = CHAN_VOICE; + params.m_nChannel = CHAN_VOICE; // NEO TODO (Adam) This doesn't change the channel this sound is played on, set correct channel in sound script EmitSound(filter, edict()->m_EdictIndex, params); @@ -4239,7 +4180,6 @@ void CNEO_Player::SpawnJuggernautPostDeath() { EmitSound_t soundParams; soundParams.m_pSoundName = "HUD.GhostPickUp"; - soundParams.m_nChannel = CHAN_GHOST_PICKUP; soundParams.m_bWarnOnDirectWaveReference = false; soundParams.m_bEmitCloseCaption = false; soundParams.m_SoundLevel = ATTN_TO_SNDLVL(ATTN_NONE); @@ -4358,7 +4298,7 @@ void CNEO_Player::SpectatorTakeoverPlayerPreThink() m_iBotDetectableBleedingInjuryEvents = pPlayerTakeoverTarget->m_iBotDetectableBleedingInjuryEvents; m_bInVision = pPlayerTakeoverTarget->m_bInVision; - m_nVisionLastTick = pPlayerTakeoverTarget->m_nVisionLastTick; + m_flVisionLastTime = pPlayerTakeoverTarget->m_flVisionLastTime; // Just clear this so the attackers scores/hits are based on only when it's // impersonated not including the bot controlled part diff --git a/src/game/server/neo/neo_player.h b/src/game/server/neo/neo_player.h index 7e5f7ac8a..e23f3772e 100644 --- a/src/game/server/neo/neo_player.h +++ b/src/game/server/neo/neo_player.h @@ -299,7 +299,7 @@ class CNEO_Player : public CHL2MP_Player CNetworkHandle(CBaseEntity, m_hServerRagdoll); CNetworkVar(float, m_flCamoAuxLastTime); - CNetworkVar(int, m_nVisionLastTick); + CNetworkVar(float, m_flVisionLastTime); CNetworkVar(float, m_flJumpLastTime); CNetworkVar(float, m_flNextPingTime); diff --git a/src/game/shared/neo/neo_player_shared.cpp b/src/game/shared/neo/neo_player_shared.cpp index 9eb432423..8eca0124e 100644 --- a/src/game/shared/neo/neo_player_shared.cpp +++ b/src/game/shared/neo/neo_player_shared.cpp @@ -16,6 +16,7 @@ #include "c_neo_player.h" #include "c_playerresource.h" #include "ui/neo_hud_context_hint.h" +#include "prediction.h" #define CNEO_Player C_NEO_Player #else #include "neo_player.h" @@ -728,4 +729,80 @@ CBaseEntity *CNEO_Player::FindUseEntity() } return pNearest; -} \ No newline at end of file +} + +void CNEO_Player::CheckVisionButtons() +{ + if (m_iNeoClass == NEO_CLASS_VIP) + { + return; + } + + constexpr float MIN_INTERVAL_BETWEEN_VISION_TOGGLE = 0.1f; + if (gpGlobals->curtime - m_flVisionLastTime < MIN_INTERVAL_BETWEEN_VISION_TOGGLE) + { + return; + } + + if (!(m_afButtonPressed & IN_VISION)) + { + return; + } + + if (!IsAlive()) + { + return; + } + + m_flVisionLastTime = gpGlobals->curtime; + m_bInVision = !m_bInVision; + +#ifdef CLIENT_DLL + if (prediction->IsFirstTimePredicted()) + { + // NEO TODO (Adam) Is this still needed? + DevMsg("Playing sound at :%f\n", gpGlobals->curtime); + } + + CLocalPlayerFilter filter; + filter.MakeReliable(); + filter.UsePredictionRules(); + +#else + CRecipientFilter filter; + + // NEO TODO/FIXME (Rain): optimise this loop to once per cycle instead of repeating for each client + for (int i = 1; i <= gpGlobals->maxClients; ++i) + { + if (edict()->m_EdictIndex == i) + { + continue; + } + + auto player = UTIL_PlayerByIndex(i); + if (!player || !player->IsDead() || player->GetObserverMode() != OBS_MODE_IN_EYE) + { + continue; + } + + if (player->GetObserverTarget() == this) + { + filter.AddRecipient(player); + } + } + + if (filter.GetRecipientCount() == 0) + { + return; + } +#endif // CLIENT_DLL + + EmitSound_t params; + params.m_bEmitCloseCaption = false; + params.m_pOrigin = &GetAbsOrigin(); + static int VISION_ON = CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOn"); + static int VISION_OFF = CBaseEntity::PrecacheScriptSound("NeoPlayer.VisionOff"); + params.m_hSoundScriptHandle = m_bInVision ? VISION_ON : VISION_OFF; + + EmitSound(filter, entindex(), params); +} diff --git a/src/public/SoundParametersInternal.cpp b/src/public/SoundParametersInternal.cpp index 4469650f4..fe1246151 100644 --- a/src/public/SoundParametersInternal.cpp +++ b/src/public/SoundParametersInternal.cpp @@ -41,6 +41,7 @@ static SoundChannels g_pChannelNames[] = { CHAN_VOICE_BASE, "CHAN_VOICE_BASE" }, { CHAN_USER_BASE, "CHAN_USER_BASE" }, { CHAN_GHOST_PICKUP, "CHAN_GHOST_PICKUP" }, + { CHAN_VISION, "CHAN_VISION" }, #endif }; diff --git a/src/public/soundflags.h b/src/public/soundflags.h index 88d499a4d..10af89514 100644 --- a/src/public/soundflags.h +++ b/src/public/soundflags.h @@ -30,7 +30,13 @@ enum CHAN_VOICE_BASE = 8, // allocate channel for network voice data CHAN_USER_BASE = (CHAN_VOICE_BASE+128) // Anything >= this number is allocated to game code. #ifdef NEO - ,CHAN_GHOST_PICKUP = CHAN_USER_BASE, + // NEO NOTE (Adam) These cannot be used inside of sound scripts, nor does using them in code do much (EmitSound ignores the channel set in the EmitSound_t param passed to it). + // We could add a flag like SND_CHANGE_PITCH and SND_CHANGE_VOL, but the reason SND_CHANGE_CHANNEL doesn't exist is because it cannot be changed for already playing sounds. + // Still might be useful for sounds that aren't playing yet if theres some disclaimer attached to the flag I guess. If you add something like that please update this comment. + // For now add any channels you may need here and in SoundParametersInternal.cpp, then use the integer equivalent in the sound scripts. + // If any of the enums here change, remember to update all the soundscripts. + ,CHAN_GHOST_PICKUP = CHAN_USER_BASE, + CHAN_VISION, #endif // NEO };