From f3ebfae18e409e48b6553019788fbf4818f40eee Mon Sep 17 00:00:00 2001 From: oy Date: Fri, 6 Jan 2012 19:47:49 +0100 Subject: drop multiple chat sounds that are played within 300ms. Closes #440 --- src/game/client/components/chat.cpp | 28 +++++++++++++++++++++++++--- src/game/client/components/chat.h | 6 ++++++ 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index a89d2b7e..591dccc6 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -41,6 +41,9 @@ void CChat::OnReset() m_PlaceholderOffset = 0; m_PlaceholderLength = 0; m_pHistoryEntry = 0x0; + + for(int i = 0; i < CHAT_NUM; ++i) + m_aLastSoundPlayed[i] = -1; } void CChat::OnRelease() @@ -322,12 +325,31 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) } // play sound + int64 Now = time_get(); if(ClientID == -1) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0); + { + if(Now-m_aLastSoundPlayed[CHAT_SERVER] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0); + m_aLastSoundPlayed[CHAT_SERVER] = Now; + } + } else if(Highlighted) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0); + { + if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0); + m_aLastSoundPlayed[CHAT_HIGHLIGHT] = Now; + } + } else - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0); + { + if(Now-m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq()*3/10) + { + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0); + m_aLastSoundPlayed[CHAT_CLIENT] = Now; + } + } } void CChat::OnRender() diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h index 60e18387..f007f314 100644 --- a/src/game/client/components/chat.h +++ b/src/game/client/components/chat.h @@ -36,6 +36,11 @@ class CChat : public CComponent MODE_NONE=0, MODE_ALL, MODE_TEAM, + + CHAT_SERVER=0, + CHAT_HIGHLIGHT, + CHAT_CLIENT, + CHAT_NUM, }; int m_Mode; @@ -49,6 +54,7 @@ class CChat : public CComponent int m_PlaceholderLength; char *m_pHistoryEntry; TStaticRingBuffer m_History; + int64 m_aLastSoundPlayed[CHAT_NUM]; static void ConSay(IConsole::IResult *pResult, void *pUserData); static void ConSayTeam(IConsole::IResult *pResult, void *pUserData); -- cgit 1.4.1