mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-17 13:38:18 +00:00
Add map sound
Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
This commit is contained in:
parent
5a2891933c
commit
12057d9f6d
|
@ -374,6 +374,10 @@ Objects = [
|
|||
NetIntAny("m_Layer"),
|
||||
NetIntAny("m_EntityClass"),
|
||||
]),
|
||||
|
||||
NetEventEx("MapSoundWorld:Common", "map-sound-world@netevent.ddnet.org", [
|
||||
NetIntAny("m_SoundId"),
|
||||
]),
|
||||
]
|
||||
|
||||
Messages = [
|
||||
|
@ -585,4 +589,8 @@ Messages = [
|
|||
NetMessageEx("Sv_ChangeInfoCooldown", "change-info-cooldown@netmsg.ddnet.org", [
|
||||
NetTick("m_WaitUntil")
|
||||
]),
|
||||
|
||||
NetMessageEx("Sv_MapSoundGlobal", "map-sound-global@netmsg.ddnet.org", [
|
||||
NetIntAny("m_SoundId"),
|
||||
]),
|
||||
]
|
||||
|
|
|
@ -17,6 +17,22 @@ CMapSounds::CMapSounds()
|
|||
m_Count = 0;
|
||||
}
|
||||
|
||||
void CMapSounds::Play(int SoundId)
|
||||
{
|
||||
if(SoundId < 0 || SoundId >= m_Count)
|
||||
return;
|
||||
|
||||
m_pClient->m_Sounds.PlaySample(CSounds::CHN_MAPSOUND, m_aSounds[SoundId], 1.0f, 0);
|
||||
}
|
||||
|
||||
void CMapSounds::PlayAt(int SoundId, vec2 Pos)
|
||||
{
|
||||
if(SoundId < 0 || SoundId >= m_Count)
|
||||
return;
|
||||
|
||||
m_pClient->m_Sounds.PlaySampleAt(CSounds::CHN_MAPSOUND, m_aSounds[SoundId], 1.0f, Pos, 0);
|
||||
}
|
||||
|
||||
void CMapSounds::OnMapLoad()
|
||||
{
|
||||
IMap *pMap = Kernel()->RequestInterface<IMap>();
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
CMapSounds();
|
||||
virtual int Sizeof() const override { return sizeof(*this); }
|
||||
|
||||
void Play(int SoundId);
|
||||
void PlayAt(int SoundId, vec2 Pos);
|
||||
|
||||
virtual void OnMapLoad() override;
|
||||
virtual void OnRender() override;
|
||||
virtual void OnStateChange(int NewState, int OldState) override;
|
||||
|
|
|
@ -1067,6 +1067,17 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dumm
|
|||
CNetMsg_Sv_ChangeInfoCooldown *pMsg = (CNetMsg_Sv_ChangeInfoCooldown *)pRawMsg;
|
||||
m_NextChangeInfo = pMsg->m_WaitUntil;
|
||||
}
|
||||
else if(MsgId == NETMSGTYPE_SV_MAPSOUNDGLOBAL)
|
||||
{
|
||||
if(m_SuppressEvents)
|
||||
return;
|
||||
|
||||
if(!g_Config.m_SndGame)
|
||||
return;
|
||||
|
||||
CNetMsg_Sv_MapSoundGlobal *pMsg = (CNetMsg_Sv_MapSoundGlobal *)pRawMsg;
|
||||
m_MapSounds.Play(pMsg->m_SoundId);
|
||||
}
|
||||
}
|
||||
|
||||
void CGameClient::OnStateChange(int NewState, int OldState)
|
||||
|
@ -1240,6 +1251,14 @@ void CGameClient::ProcessEvents()
|
|||
|
||||
m_Sounds.PlayAt(CSounds::CHN_WORLD, pEvent->m_SoundId, 1.0f, vec2(pEvent->m_X, pEvent->m_Y));
|
||||
}
|
||||
else if(Item.m_Type == NETEVENTTYPE_MAPSOUNDWORLD)
|
||||
{
|
||||
CNetEvent_MapSoundWorld *pEvent = (CNetEvent_MapSoundWorld *)Item.m_pData;
|
||||
if(!Config()->m_SndGame)
|
||||
continue;
|
||||
|
||||
m_MapSounds.PlayAt(pEvent->m_SoundId, vec2(pEvent->m_X, pEvent->m_Y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue