36 changes: 21 additions & 15 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,27 @@ void *ServerThread::run()

v3f ServerPlayingSound::getPos(ServerEnvironment *env, bool *pos_exists) const
{
if(pos_exists) *pos_exists = false;
switch(type){
case SSP_LOCAL:
if (pos_exists)
*pos_exists = false;

switch (type ){
case SoundLocation::Local:
return v3f(0,0,0);
case SSP_POSITIONAL:
if(pos_exists) *pos_exists = true;
case SoundLocation::Position:
if (pos_exists)
*pos_exists = true;
return pos;
case SSP_OBJECT: {
if(object == 0)
return v3f(0,0,0);
ServerActiveObject *sao = env->getActiveObject(object);
if(!sao)
return v3f(0,0,0);
if(pos_exists) *pos_exists = true;
return sao->getBasePosition(); }
case SoundLocation::Object:
{
if (object == 0)
return v3f(0,0,0);
ServerActiveObject *sao = env->getActiveObject(object);
if (!sao)
return v3f(0,0,0);
if (pos_exists)
*pos_exists = true;
return sao->getBasePosition();
}
}
return v3f(0,0,0);
}
Expand Down Expand Up @@ -2071,9 +2077,9 @@ s32 Server::playSound(ServerPlayingSound &params, bool ephemeral)
{
// Find out initial position of sound
bool pos_exists = false;
v3f pos = params.getPos(m_env, &pos_exists);
const v3f pos = params.getPos(m_env, &pos_exists);
// If position is not found while it should be, cancel sound
if(pos_exists != (params.type != ServerPlayingSound::SSP_LOCAL))
if(pos_exists != (params.type != SoundLocation::Local))
return -1;

// Filter destination clients
Expand Down
6 changes: 1 addition & 5 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ struct MediaInfo
// Combines the pure sound (SimpleSoundSpec) with positional information
struct ServerPlayingSound
{
enum Type {
SSP_LOCAL,
SSP_POSITIONAL,
SSP_OBJECT
} type = SSP_LOCAL;
SoundLocation type = SoundLocation::Local;

float gain = 1.0f; // for amplification of the base sound
float max_hear_distance = 32 * BS;
Expand Down
8 changes: 8 additions & 0 deletions src/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ struct SimpleSoundSpec
float pitch = 1.0f;
bool loop = false;
};


// The order must not be changed. This is sent over the network.
enum class SoundLocation : u8 {
Local,
Position,
Object
};