1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Sounds: Partial revert of #14436 and #14341 (#14889)

This reverts functional changes of:
 * commit bf52d1e6 (#14436)
 * commit 63a98538 (#14341)
This commit is contained in:
SmallJoker 2024-07-30 21:25:50 +02:00 committed by GitHub
parent 2ba1d60ba5
commit 26deb26f17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 61 deletions

View file

@ -2054,19 +2054,10 @@ void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersa
// Removed objects
pkt << static_cast<u16>(removed_objects.size());
std::vector<u16> sounds_to_stop;
for (auto &it : removed_objects) {
const auto [gone, id] = it;
ServerActiveObject *obj = m_env->getActiveObject(id);
// Stop sounds if objects go out of range.
// This fixes https://github.com/minetest/minetest/issues/8094.
// We may not remove sounds if an entity was removed on the server.
// See https://github.com/minetest/minetest/issues/14422.
if (!gone) // just out of range for client, not gone on server?
sounds_to_stop.push_back(id);
pkt << id;
// Remove from known objects
@ -2075,8 +2066,10 @@ void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersa
obj->m_known_by_count--;
}
if (!sounds_to_stop.empty())
stopAttachedSounds(client->peer_id, sounds_to_stop);
// Note: Do yet NOT stop or remove object-attached sounds where the object goes out
// of range (client side). Such sounds would need to be re-sent when coming into range.
// Currently, the client will initiate m_playing_sounds clean ups indirectly by
// "Server::handleCommand_RemovedSounds".
// Added objects
pkt << static_cast<u16>(added_objects.size());
@ -2260,37 +2253,6 @@ void Server::fadeSound(s32 handle, float step, float gain)
m_playing_sounds.erase(it);
}
void Server::stopAttachedSounds(session_t peer_id,
const std::vector<u16> &object_ids)
{
assert(peer_id != PEER_ID_INEXISTENT);
assert(!object_ids.empty());
auto cb = [&] (const s32 id, ServerPlayingSound &sound) -> bool {
if (!CONTAINS(object_ids, sound.object))
return false;
auto clients_it = sound.clients.find(peer_id);
if (clients_it == sound.clients.end())
return false;
NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4);
pkt << id;
Send(peer_id, &pkt);
sound.clients.erase(clients_it);
// delete if client list empty
return sound.clients.empty();
};
for (auto it = m_playing_sounds.begin(); it != m_playing_sounds.end(); ) {
if (cb(it->first, it->second))
it = m_playing_sounds.erase(it);
else
++it;
}
}
void Server::sendRemoveNode(v3s16 p, std::unordered_set<u16> *far_players,
float far_d_nodes)
{