summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorBrandon <brandon@bremaweb.com>2016-07-10 00:08:26 -0500
committerparamat <mat.gregory@virginmedia.com>2017-05-03 03:12:45 +0100
commitbd921a7916f0fafc493b1c4d0eeb5e2bb1d6a7c2 (patch)
tree55f92cc02fce2acc9bb041a34de3c474b894bd00 /src/network
parentf1d7a26b7c341b468f34325cec5c3d495f175a8f (diff)
downloadminetest-bd921a7916f0fafc493b1c4d0eeb5e2bb1d6a7c2.tar.gz
minetest-bd921a7916f0fafc493b1c4d0eeb5e2bb1d6a7c2.tar.bz2
minetest-bd921a7916f0fafc493b1c4d0eeb5e2bb1d6a7c2.zip
Sound API: Add fading sounds
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientopcodes.cpp2
-rw-r--r--src/network/clientpackethandler.cpp35
-rw-r--r--src/network/networkprotocol.h11
3 files changed, 45 insertions, 3 deletions
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp
index 1be6e5522..bdcb1dfce 100644
--- a/src/network/clientopcodes.cpp
+++ b/src/network/clientopcodes.cpp
@@ -109,7 +109,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_EYE_OFFSET", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_EyeOffset }, // 0x52
{ "TOCLIENT_DELETE_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeleteParticleSpawner }, // 0x53
{ "TOCLIENT_CLOUD_PARAMS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CloudParams }, // 0x54
- null_command_handler,
+ { "TOCLIENT_FADE_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FadeSound }, // 0x55
null_command_handler,
null_command_handler,
null_command_handler,
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index defc83f31..a895acc84 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -755,21 +755,39 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt)
void Client::handleCommand_PlaySound(NetworkPacket* pkt)
{
+ /*
+ [0] u32 server_id
+ [4] u16 name length
+ [6] char name[len]
+ [ 6 + len] f32 gain
+ [10 + len] u8 type
+ [11 + len] (f32 * 3) pos
+ [23 + len] u16 object_id
+ [25 + len] bool loop
+ [26 + len] f32 fade
+ */
+
s32 server_id;
std::string name;
+
float gain;
u8 type; // 0=local, 1=positional, 2=object
v3f pos;
u16 object_id;
bool loop;
+ float fade = 0;
*pkt >> server_id >> name >> gain >> type >> pos >> object_id >> loop;
+ try {
+ *pkt >> fade;
+ } catch (SerializationError &e) {};
+
// Start playing
int client_id = -1;
switch(type) {
case 0: // local
- client_id = m_sound->playSound(name, loop, gain);
+ client_id = m_sound->playSound(name, loop, gain, fade);
break;
case 1: // positional
client_id = m_sound->playSoundAt(name, loop, gain, pos);
@@ -808,6 +826,21 @@ void Client::handleCommand_StopSound(NetworkPacket* pkt)
}
}
+void Client::handleCommand_FadeSound(NetworkPacket *pkt)
+{
+ s32 sound_id;
+ float step;
+ float gain;
+
+ *pkt >> sound_id >> step >> gain;
+
+ UNORDERED_MAP<s32, int>::iterator i =
+ m_sounds_server_to_client.find(sound_id);
+
+ if (i != m_sounds_server_to_client.end())
+ m_sound->fadeSound(i->second, step, gain);
+}
+
void Client::handleCommand_Privileges(NetworkPacket* pkt)
{
m_privileges.clear();
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index a1a4f5bfa..70cad85d8 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -153,9 +153,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PROTOCOL VERSION 31:
Add tile overlay
Stop sending TOSERVER_CLIENT_READY
+ PROTOCOL VERSION 32:
+ Add fading sounds
*/
-#define LATEST_PROTOCOL_VERSION 31
+#define LATEST_PROTOCOL_VERSION 32
// Server's supported network protocol range
#define SERVER_PROTOCOL_VERSION_MIN 24
@@ -620,6 +622,13 @@ enum ToClientCommand
v2f1000 speed
*/
+ TOCLIENT_FADE_SOUND = 0x55,
+ /*
+ s32 sound_id
+ float step
+ float gain
+ */
+
TOCLIENT_SRP_BYTES_S_B = 0x60,
/*
Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.