Skip to content

Commit

Permalink
Refactor|Audio: Moved registration of audio cmds/vars to audio::System
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 6, 2015
1 parent cb6ae4a commit dfd1091
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 87 deletions.
5 changes: 5 additions & 0 deletions doomsday/apps/client/include/audio/system.h
Expand Up @@ -35,6 +35,11 @@ class System : public de::System
public:
static System &get();

/**
* Register the console commands and variables of this module.
*/
static void consoleRegister();

public:
System();

Expand Down
85 changes: 0 additions & 85 deletions doomsday/apps/client/src/audio/s_main.cpp
Expand Up @@ -29,8 +29,6 @@
#endif
#include <doomsday/doomsdayapp.h>
#include <doomsday/audio/logical.h>
#include <doomsday/console/cmd.h>
#include <doomsday/console/var.h>
#include <doomsday/filesys/fs_main.h>
#include <doomsday/filesys/fs_util.h>

Expand Down Expand Up @@ -533,89 +531,6 @@ void S_Drawer()
#endif // __CLIENT__
}

/**
* Console command for playing a (local) sound effect.
*/
D_CMD(PlaySound)
{
DENG2_UNUSED(src);

if(argc < 2)
{
LOG_SCR_NOTE("Usage: %s (id) (volume) at (x) (y) (z)") << argv[0];
LOG_SCR_MSG("(volume) must be in 0..1, but may be omitted.");
LOG_SCR_MSG("'at (x) (y) (z)' may also be omitted.");
LOG_SCR_MSG("The sound is always played locally.");
return true;
}
dint p = 0;

// The sound ID is always first.
dint const id = ::defs.getSoundNum(argv[1]);

// The second argument may be a volume.
dfloat volume = 1;
if(argc >= 3 && String(argv[2]).compareWithoutCase("at"))
{
volume = String(argv[2]).toFloat();
p = 3;
}
else
{
p = 2;
}

bool useFixedPos = false;
coord_t fixedPos[3];
if(argc >= p + 4 && !String(argv[p]).compareWithoutCase("at"))
{
useFixedPos = true;
fixedPos[VX] = strtod(argv[p + 1], nullptr);
fixedPos[VY] = strtod(argv[p + 2], nullptr);
fixedPos[VZ] = strtod(argv[p + 3], nullptr);
}

// Check that the volume is valid.
volume = de::clamp(0.f, volume, 1.f);
if(de::fequal(volume, 0)) return true;

if(useFixedPos)
{
S_LocalSoundAtVolumeFrom(id, nullptr, fixedPos, volume);
}
else
{
S_LocalSoundAtVolume(id, nullptr, volume);
}

return true;
}

#ifdef __CLIENT__
static void S_ReverbVolumeChanged()
{
Sfx_UpdateReverb();
}
#endif

void S_Register()
{
C_VAR_BYTE ("sound-overlap-stop", &sfxOneSoundPerEmitter, 0, 0, 1);

#ifdef __CLIENT__
C_VAR_INT ("sound-volume", &sfxVolume, 0, 0, 255);
C_VAR_INT ("sound-info", &showSoundInfo, 0, 0, 1);
C_VAR_INT ("sound-rate", &sfxSampleRate, 0, 11025, 44100);
C_VAR_INT ("sound-16bit", &sfx16Bit, 0, 0, 1);
C_VAR_INT ("sound-3d", &sfx3D, 0, 0, 1);
C_VAR_FLOAT2("sound-reverb-volume", &sfxReverbStrength, 0, 0, 1.5f, S_ReverbVolumeChanged);

C_CMD_FLAGS("playsound", nullptr, PlaySound, CMDF_NO_DEDICATED);

Mus_Register();
#endif
}

DENG_DECLARE_API(S) =
{
{ DE_API_SOUND },
Expand Down
88 changes: 87 additions & 1 deletion doomsday/apps/client/src/audio/system.cpp
Expand Up @@ -16,7 +16,7 @@
* http://www.gnu.org/licenses</small>
*/

#define DENG_NO_API_MACROS_SOUND
//#define DENG_NO_API_MACROS_SOUND

#include "audio/system.h"

Expand All @@ -25,8 +25,11 @@
#ifdef __CLIENT__
# include "audio/audiodriver.h"
#endif
#include "audio/s_main.h"
#include "audio/s_mus.h"
#include "audio/s_sfx.h"
#include <doomsday/console/cmd.h>
#include <doomsday/console/var.h>
#include <de/App>

using namespace de;
Expand Down Expand Up @@ -79,4 +82,87 @@ void System::reset()
_api_S.StopMusic();
}

/**
* Console command for playing a (local) sound effect.
*/
D_CMD(PlaySound)
{
DENG2_UNUSED(src);

if(argc < 2)
{
LOG_SCR_NOTE("Usage: %s (id) (volume) at (x) (y) (z)") << argv[0];
LOG_SCR_MSG("(volume) must be in 0..1, but may be omitted.");
LOG_SCR_MSG("'at (x) (y) (z)' may also be omitted.");
LOG_SCR_MSG("The sound is always played locally.");
return true;
}
dint p = 0;

// The sound ID is always first.
dint const id = ::defs.getSoundNum(argv[1]);

// The second argument may be a volume.
dfloat volume = 1;
if(argc >= 3 && String(argv[2]).compareWithoutCase("at"))
{
volume = String(argv[2]).toFloat();
p = 3;
}
else
{
p = 2;
}

bool useFixedPos = false;
coord_t fixedPos[3];
if(argc >= p + 4 && !String(argv[p]).compareWithoutCase("at"))
{
useFixedPos = true;
fixedPos[0] = String(argv[p + 1]).toDouble();
fixedPos[1] = String(argv[p + 2]).toDouble();
fixedPos[2] = String(argv[p + 3]).toDouble();
}

// Check that the volume is valid.
volume = de::clamp(0.f, volume, 1.f);
if(de::fequal(volume, 0)) return true;

if(useFixedPos)
{
S_LocalSoundAtVolumeFrom(id, nullptr, fixedPos, volume);
}
else
{
S_LocalSoundAtVolume(id, nullptr, volume);
}

return true;
}

#ifdef __CLIENT__
static void reverbVolumeChanged()
{
Sfx_UpdateReverb();
}
#endif

void System::consoleRegister() // static
{
C_VAR_BYTE ("sound-overlap-stop", &sfxOneSoundPerEmitter, 0, 0, 1);

#ifdef __CLIENT__
C_VAR_INT ("sound-volume", &sfxVolume, 0, 0, 255);
C_VAR_INT ("sound-info", &showSoundInfo, 0, 0, 1);
C_VAR_INT ("sound-rate", &sfxSampleRate, 0, 11025, 44100);
C_VAR_INT ("sound-16bit", &sfx16Bit, 0, 0, 1);
C_VAR_INT ("sound-3d", &sfx3D, 0, 0, 1);
C_VAR_FLOAT2("sound-reverb-volume", &sfxReverbStrength, 0, 0, 1.5f, reverbVolumeChanged);

C_CMD_FLAGS("playsound", nullptr, PlaySound, CMDF_NO_DEDICATED);

Mus_Register();
#endif
}

} // namespace audio
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -3141,7 +3141,7 @@ static void consoleRegister()
Con_Register();
Games::consoleRegister();
DH_Register();
S_Register();
::audio::System::consoleRegister();

#ifdef __CLIENT__
C_CMD("clear", "", Clear);
Expand Down

0 comments on commit dfd1091

Please sign in to comment.