Merge pull request #8723 from Bamcane/map-sound

Add support for server play map sound
This commit is contained in:
heinrich5991 2024-08-14 09:27:12 +00:00 committed by GitHub
commit a48f502618
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 0 deletions

View file

@ -374,6 +374,10 @@ Objects = [
NetIntAny("m_Layer"), NetIntAny("m_Layer"),
NetIntAny("m_EntityClass"), NetIntAny("m_EntityClass"),
]), ]),
NetEventEx("MapSoundWorld:Common", "map-sound-world@netevent.ddnet.org", [
NetIntAny("m_SoundId"),
]),
] ]
Messages = [ Messages = [
@ -585,4 +589,8 @@ Messages = [
NetMessageEx("Sv_ChangeInfoCooldown", "change-info-cooldown@netmsg.ddnet.org", [ NetMessageEx("Sv_ChangeInfoCooldown", "change-info-cooldown@netmsg.ddnet.org", [
NetTick("m_WaitUntil") NetTick("m_WaitUntil")
]), ]),
NetMessageEx("Sv_MapSoundGlobal", "map-sound-global@netmsg.ddnet.org", [
NetIntAny("m_SoundId"),
]),
] ]

View file

@ -17,6 +17,22 @@ CMapSounds::CMapSounds()
m_Count = 0; 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() void CMapSounds::OnMapLoad()
{ {
IMap *pMap = Kernel()->RequestInterface<IMap>(); IMap *pMap = Kernel()->RequestInterface<IMap>();

View file

@ -33,6 +33,9 @@ public:
CMapSounds(); CMapSounds();
virtual int Sizeof() const override { return sizeof(*this); } virtual int Sizeof() const override { return sizeof(*this); }
void Play(int SoundId);
void PlayAt(int SoundId, vec2 Pos);
virtual void OnMapLoad() override; virtual void OnMapLoad() override;
virtual void OnRender() override; virtual void OnRender() override;
virtual void OnStateChange(int NewState, int OldState) override; virtual void OnStateChange(int NewState, int OldState) override;

View file

@ -1053,6 +1053,17 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dumm
CNetMsg_Sv_ChangeInfoCooldown *pMsg = (CNetMsg_Sv_ChangeInfoCooldown *)pRawMsg; CNetMsg_Sv_ChangeInfoCooldown *pMsg = (CNetMsg_Sv_ChangeInfoCooldown *)pRawMsg;
m_NextChangeInfo = pMsg->m_WaitUntil; 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) void CGameClient::OnStateChange(int NewState, int OldState)
@ -1226,6 +1237,14 @@ void CGameClient::ProcessEvents()
m_Sounds.PlayAt(CSounds::CHN_WORLD, pEvent->m_SoundId, 1.0f, vec2(pEvent->m_X, pEvent->m_Y)); 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));
}
} }
} }