1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Sound refactor and improvements (#12764)

This commit is contained in:
DS 2023-06-16 20:15:21 +02:00 committed by GitHub
parent 8e1af25738
commit edcbfa31c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 2802 additions and 1211 deletions

View file

@ -805,57 +805,74 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt)
void Client::handleCommand_PlaySound(NetworkPacket* pkt)
{
/*
[0] u32 server_id
[0] s32 server_id
[4] u16 name length
[6] char name[len]
[ 6 + len] f32 gain
[10 + len] u8 type
[11 + len] (f32 * 3) pos
[10 + len] u8 type (SoundLocation)
[11 + len] v3f pos (in BS-space)
[23 + len] u16 object_id
[25 + len] bool loop
[26 + len] f32 fade
[30 + len] f32 pitch
[34 + len] bool ephemeral
[35 + len] f32 start_time (in seconds)
*/
s32 server_id;
SimpleSoundSpec spec;
SoundLocation type; // 0=local, 1=positional, 2=object
SoundSpec spec;
SoundLocation type;
v3f pos;
u16 object_id;
bool ephemeral = false;
*pkt >> server_id >> spec.name >> spec.gain >> (u8 &)type >> pos >> object_id >> spec.loop;
pos *= 1.0f/BS;
try {
*pkt >> spec.fade;
*pkt >> spec.pitch;
*pkt >> ephemeral;
*pkt >> spec.start_time;
} catch (PacketError &e) {};
// Generate a new id
sound_handle_t client_id = (ephemeral && object_id == 0) ? 0 : m_sound->allocateId(2);
// Start playing
int client_id = -1;
switch(type) {
case SoundLocation::Local:
client_id = m_sound->playSound(spec);
m_sound->playSound(client_id, spec);
break;
case SoundLocation::Position:
client_id = m_sound->playSoundAt(spec, pos);
m_sound->playSoundAt(client_id, spec, pos, v3f(0.0f));
break;
case SoundLocation::Object:
{
ClientActiveObject *cao = m_env.getActiveObject(object_id);
if (cao)
pos = cao->getPosition();
client_id = m_sound->playSoundAt(spec, pos);
break;
case SoundLocation::Object: {
ClientActiveObject *cao = m_env.getActiveObject(object_id);
v3f vel(0.0f);
if (cao) {
pos = cao->getPosition() * (1.0f/BS);
vel = cao->getVelocity() * (1.0f/BS);
}
m_sound->playSoundAt(client_id, spec, pos, vel);
break;
}
default:
// Unknown SoundLocation, instantly remove sound
if (client_id != 0)
m_sound->freeId(client_id, 2);
if (!ephemeral)
sendRemovedSounds({server_id});
return;
}
if (client_id != -1) {
// for ephemeral sounds, server_id is not meaningful
if (!ephemeral) {
if (client_id != 0) {
// Note: m_sounds_client_to_server takes 1 ownership
// For ephemeral sounds, server_id is not meaningful
if (ephemeral) {
m_sounds_client_to_server[client_id] = -1;
} else {
m_sounds_server_to_client[server_id] = client_id;
m_sounds_client_to_server[client_id] = server_id;
}

View file

@ -215,9 +215,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
new fields for TOCLIENT_SET_LIGHTING and TOCLIENT_SET_SKY
Send forgotten TweenedParameter properties
[scheduled bump for 5.7.0]
PROTOCOL VERSION 43:
"start_time" added to TOCLIENT_PLAY_SOUND
[scheduled bump for 5.8.0]
*/
#define LATEST_PROTOCOL_VERSION 42
#define LATEST_PROTOCOL_VERSION 43
#define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
// Server's supported network protocol range
@ -454,15 +457,18 @@ enum ToClientCommand
TOCLIENT_PLAY_SOUND = 0x3f,
/*
s32 sound_id
s32 server_id
u16 len
u8[len] sound name
s32 gain*1000
u8 type (0=local, 1=positional, 2=object)
s32[3] pos_nodes*10000
f32 gain
u8 type (SoundLocation: 0=local, 1=positional, 2=object)
v3f pos_nodes (in BS-space)
u16 object_id
u8 loop (bool)
f32 fade
f32 pitch
u8 ephemeral (bool)
f32 start_time (in seconds)
*/
TOCLIENT_STOP_SOUND = 0x40,