mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Sound API: Add fading sounds
This commit is contained in:
parent
f1d7a26b7c
commit
bd921a7916
14 changed files with 248 additions and 19 deletions
|
@ -2100,15 +2100,23 @@ s32 Server::playSound(const SimpleSoundSpec &spec,
|
|||
m_playing_sounds[id] = ServerPlayingSound();
|
||||
ServerPlayingSound &psound = m_playing_sounds[id];
|
||||
psound.params = params;
|
||||
psound.spec = spec;
|
||||
|
||||
float gain = params.gain * spec.gain;
|
||||
NetworkPacket pkt(TOCLIENT_PLAY_SOUND, 0);
|
||||
pkt << id << spec.name << (float) (spec.gain * params.gain)
|
||||
<< (u8) params.type << pos << params.object << params.loop;
|
||||
pkt << id << spec.name << gain
|
||||
<< (u8) params.type << pos << params.object
|
||||
<< params.loop << params.fade;
|
||||
|
||||
for(std::vector<u16>::iterator i = dst_clients.begin();
|
||||
// Backwards compability
|
||||
bool play_sound = gain > 0;
|
||||
|
||||
for (std::vector<u16>::iterator i = dst_clients.begin();
|
||||
i != dst_clients.end(); ++i) {
|
||||
psound.clients.insert(*i);
|
||||
m_clients.send(*i, 0, &pkt, true);
|
||||
if (play_sound || m_clients.getProtocolVersion(*i) >= 32) {
|
||||
psound.clients.insert(*i);
|
||||
m_clients.send(*i, 0, &pkt, true);
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@ -2132,6 +2140,52 @@ void Server::stopSound(s32 handle)
|
|||
m_playing_sounds.erase(i);
|
||||
}
|
||||
|
||||
void Server::fadeSound(s32 handle, float step, float gain)
|
||||
{
|
||||
// Get sound reference
|
||||
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i =
|
||||
m_playing_sounds.find(handle);
|
||||
if (i == m_playing_sounds.end())
|
||||
return;
|
||||
|
||||
ServerPlayingSound &psound = i->second;
|
||||
psound.params.gain = gain;
|
||||
|
||||
NetworkPacket pkt(TOCLIENT_FADE_SOUND, 4);
|
||||
pkt << handle << step << gain;
|
||||
|
||||
// Backwards compability
|
||||
bool play_sound = gain > 0;
|
||||
ServerPlayingSound compat_psound = psound;
|
||||
compat_psound.clients.clear();
|
||||
|
||||
NetworkPacket compat_pkt(TOCLIENT_STOP_SOUND, 4);
|
||||
compat_pkt << handle;
|
||||
|
||||
for (UNORDERED_SET<u16>::iterator it = psound.clients.begin();
|
||||
it != psound.clients.end();) {
|
||||
if (m_clients.getProtocolVersion(*it) >= 32) {
|
||||
// Send as reliable
|
||||
m_clients.send(*it, 0, &pkt, true);
|
||||
++it;
|
||||
} else {
|
||||
compat_psound.clients.insert(*it);
|
||||
// Stop old sound
|
||||
m_clients.send(*it, 0, &compat_pkt, true);
|
||||
psound.clients.erase(it++);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove sound reference
|
||||
if (!play_sound || psound.clients.size() == 0)
|
||||
m_playing_sounds.erase(i);
|
||||
|
||||
if (play_sound && compat_psound.clients.size() > 0) {
|
||||
// Play new sound volume on older clients
|
||||
playSound(compat_psound.spec, compat_psound.params);
|
||||
}
|
||||
}
|
||||
|
||||
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
||||
std::vector<u16> *far_players, float far_d_nodes)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue