|
|
|
@ -30,8 +30,10 @@
|
|
|
|
|
#include <nel/sound/u_listener.h>
|
|
|
|
|
#include <nel/sound/u_source.h>
|
|
|
|
|
|
|
|
|
|
#include "snowballs_client.h"
|
|
|
|
|
#include "sound.h"
|
|
|
|
|
#include "entities.h"
|
|
|
|
|
#include "configuration.h"
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Namespaces
|
|
|
|
@ -41,116 +43,149 @@ using namespace std;
|
|
|
|
|
using namespace NLMISC;
|
|
|
|
|
using namespace NLSOUND;
|
|
|
|
|
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
namespace SBCLIENT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
////
|
|
|
|
|
//// Variables
|
|
|
|
|
////
|
|
|
|
|
//
|
|
|
|
|
//UAudioMixer *AudioMixer = NULL;
|
|
|
|
|
// Variables
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
UAudioMixer *AudioMixer = NULL;
|
|
|
|
|
//TSoundId SoundId;
|
|
|
|
|
//const vector<TSoundId> *SoundIdArray;
|
|
|
|
|
//static bool SoundEnabled;
|
|
|
|
|
//
|
|
|
|
|
////
|
|
|
|
|
//// Functions
|
|
|
|
|
////
|
|
|
|
|
//
|
|
|
|
|
//#ifdef NL_OS_WINDOWS
|
|
|
|
|
//void initSound2();
|
|
|
|
|
//void releaseSound2();
|
|
|
|
|
//#endif
|
|
|
|
|
//
|
|
|
|
|
//void cbConfigFileSoundMaxTracks(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
//{
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// AudioMixer->changeMaxTrack(var.asInt());
|
|
|
|
|
////#endif
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//void cbConfigFileSoundEnabled(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
//{
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// if (var.asBool() != SoundEnabled)
|
|
|
|
|
//// {
|
|
|
|
|
//// if (var.asBool()) initSound2();
|
|
|
|
|
//// else releaseSound2();
|
|
|
|
|
//// }
|
|
|
|
|
////#endif
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//void cbConfigFileFail(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
//{
|
|
|
|
|
// //nlwarning("You can't modify the config variable '%s' at runtime for now, please restart the game", var.asString().c_str());
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
////void initSound2()
|
|
|
|
|
////{
|
|
|
|
|
//// AudioMixer = UAudioMixer::createAudioMixer ();
|
|
|
|
|
//// std::string driverName;
|
|
|
|
|
//// NLSOUND::UAudioMixer::TDriver driverType;
|
|
|
|
|
//// if (!ConfigFile->exists("SoundDriver"))
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// driverType = NLSOUND::UAudioMixer::DriverFMod;
|
|
|
|
|
////#elif defined (NL_OS_UNIX)
|
|
|
|
|
//// driverType = NLSOUND::UAudioMixer::DriverOpenAl;
|
|
|
|
|
////#else
|
|
|
|
|
//// driverType = NLSOUND::UAudioMixer::DriverAuto;
|
|
|
|
|
////#endif
|
|
|
|
|
//// else
|
|
|
|
|
//// {
|
|
|
|
|
//// driverName = ConfigFile->getVar("SoundDriver").asString();
|
|
|
|
|
//// if (driverName == "Auto") driverType = NLSOUND::UAudioMixer::DriverAuto;
|
|
|
|
|
//// else if (driverName == "FMod") driverType = NLSOUND::UAudioMixer::DriverFMod;
|
|
|
|
|
//// else if (driverName == "DSound") driverType = NLSOUND::UAudioMixer::DriverDSound;
|
|
|
|
|
//// else if (driverName == "OpenAl") driverType = NLSOUND::UAudioMixer::DriverOpenAl;
|
|
|
|
|
//// else nlerror("SoundDriver value '%s' is invalid.", driverName.c_str());
|
|
|
|
|
//// }
|
|
|
|
|
////
|
|
|
|
|
//// AudioMixer->init(
|
|
|
|
|
//// ConfigFile->exists("SoundMaxTracks")
|
|
|
|
|
//// ? ConfigFile->getVar("SoundMaxTracks").asInt() : 32,
|
|
|
|
|
//// ConfigFile->exists("SoundUseEax")
|
|
|
|
|
//// ? ConfigFile->getVar("SoundUseEax").asBool() : true,
|
|
|
|
|
//// ConfigFile->exists("SoundUseADPCM")
|
|
|
|
|
//// ? ConfigFile->getVar("SoundUseADPCM").asBool() : true,
|
|
|
|
|
//// NULL, false, driverType,
|
|
|
|
|
//// ConfigFile->exists("SoundForceSoftware")
|
|
|
|
|
//// ? ConfigFile->getVar("SoundForceSoftware").asBool() : true);
|
|
|
|
|
////
|
|
|
|
|
//// ConfigFile->setCallback("SoundMaxTracks", cbConfigFileSoundMaxTracks);
|
|
|
|
|
//// ConfigFile->setCallback("SoundUseEax", cbConfigFileFail);
|
|
|
|
|
//// ConfigFile->setCallback("SoundUseADPCM", cbConfigFileFail);
|
|
|
|
|
//// ConfigFile->setCallback("SoundForceSoftware", cbConfigFileFail);
|
|
|
|
|
//// ConfigFile->setCallback("SoundDriver", cbConfigFileFail);
|
|
|
|
|
////
|
|
|
|
|
//// PlaylistManager = new SBCLIENT::CMusicPlaylistManager(AudioMixer, ConfigFile, "SoundPlaylist");
|
|
|
|
|
////
|
|
|
|
|
//// /* AudioMixer->loadSoundBuffers ("sounds.nss", &SoundIdArray);
|
|
|
|
|
//// nlassert( SoundIdArray->size() == 2 );
|
|
|
|
|
//// SoundId = (*SoundIdArray)[0];
|
|
|
|
|
//// // StSoundId = (*SoundIdArray)[1]; */
|
|
|
|
|
////
|
|
|
|
|
//// SoundEnabled = true;
|
|
|
|
|
////}
|
|
|
|
|
////#endif
|
|
|
|
|
static bool SoundEnabled;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//void initSound()
|
|
|
|
|
//{
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// if (ConfigFile->exists("SoundEnabled") ? ConfigFile->getVar("SoundEnabled").asBool() : false) initSound2();
|
|
|
|
|
//// ConfigFile->setCallback("SoundEnabled", cbConfigFileSoundEnabled);
|
|
|
|
|
////#endif
|
|
|
|
|
//}
|
|
|
|
|
// Functions
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
|
|
|
|
|
void initSound2();
|
|
|
|
|
void releaseSound2();
|
|
|
|
|
|
|
|
|
|
void cbConfigFileSoundMaxTracks(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
{
|
|
|
|
|
if (AudioMixer)
|
|
|
|
|
AudioMixer->changeMaxTrack(var.asInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cbConfigFileSoundEnabled(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
{
|
|
|
|
|
if (var.asBool() != SoundEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (var.asBool())
|
|
|
|
|
initSound2();
|
|
|
|
|
else
|
|
|
|
|
releaseSound2();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cbConfigFileMusicVolume(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
{
|
|
|
|
|
if (AudioMixer)
|
|
|
|
|
AudioMixer->setMusicVolume(var.asFloat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cbConfigFileFail(NLMISC::CConfigFile::CVar &var)
|
|
|
|
|
{
|
|
|
|
|
nlwarning("You can't modify the config variable '%s' at runtime for now, please restart the game", var.asString().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initSound2()
|
|
|
|
|
{
|
|
|
|
|
AudioMixer = UAudioMixer::createAudioMixer();
|
|
|
|
|
std::string driverName;
|
|
|
|
|
NLSOUND::UAudioMixer::TDriver driverType;
|
|
|
|
|
if (!ConfigFile->exists("SoundDriver"))
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverFMod;
|
|
|
|
|
#elif defined(NL_OS_UNIX)
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverOpenAl;
|
|
|
|
|
#else
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverAuto;
|
|
|
|
|
#endif
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
driverName = ConfigFile->getVar("SoundDriver").asString();
|
|
|
|
|
if (driverName == "Auto")
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverAuto;
|
|
|
|
|
else if (driverName == "FMod")
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverFMod;
|
|
|
|
|
else if (driverName == "DSound")
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverDSound;
|
|
|
|
|
else if (driverName == "OpenAl")
|
|
|
|
|
driverType = NLSOUND::UAudioMixer::DriverOpenAl;
|
|
|
|
|
else
|
|
|
|
|
nlerror("SoundDriver value '%s' is invalid.", driverName.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioMixer->init(
|
|
|
|
|
ConfigFile->exists("SoundMaxTracks")
|
|
|
|
|
? ConfigFile->getVar("SoundMaxTracks").asInt()
|
|
|
|
|
: 32,
|
|
|
|
|
ConfigFile->exists("SoundUseEax")
|
|
|
|
|
? ConfigFile->getVar("SoundUseEax").asBool()
|
|
|
|
|
: true,
|
|
|
|
|
ConfigFile->exists("SoundUseADPCM")
|
|
|
|
|
? ConfigFile->getVar("SoundUseADPCM").asBool()
|
|
|
|
|
: true,
|
|
|
|
|
NULL, true, driverType,
|
|
|
|
|
ConfigFile->exists("SoundForceSoftware")
|
|
|
|
|
? ConfigFile->getVar("SoundForceSoftware").asBool()
|
|
|
|
|
: true);
|
|
|
|
|
|
|
|
|
|
ConfigFile->setCallback("SoundMaxTracks", cbConfigFileSoundMaxTracks);
|
|
|
|
|
ConfigFile->setCallback("SoundUseEax", cbConfigFileFail);
|
|
|
|
|
ConfigFile->setCallback("SoundUseADPCM", cbConfigFileFail);
|
|
|
|
|
ConfigFile->setCallback("SoundForceSoftware", cbConfigFileFail);
|
|
|
|
|
ConfigFile->setCallback("SoundDriver", cbConfigFileFail);
|
|
|
|
|
CConfiguration::setAndCallback("MusicVolume", cbConfigFileMusicVolume);
|
|
|
|
|
|
|
|
|
|
// PlaylistManager = new SBCLIENT::CMusicPlaylistManager(AudioMixer, ConfigFile, "SoundPlaylist");
|
|
|
|
|
|
|
|
|
|
/* AudioMixer->loadSoundBuffers ("sounds.nss", &SoundIdArray);
|
|
|
|
|
nlassert( SoundIdArray->size() == 2 );
|
|
|
|
|
SoundId = (*SoundIdArray)[0];
|
|
|
|
|
// StSoundId = (*SoundIdArray)[1]; */
|
|
|
|
|
|
|
|
|
|
SoundEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void releaseSound2()
|
|
|
|
|
{
|
|
|
|
|
SoundEnabled = false;
|
|
|
|
|
ConfigFile->setCallback("SoundMaxTracks", NULL);
|
|
|
|
|
ConfigFile->setCallback("SoundUseEax", NULL);
|
|
|
|
|
ConfigFile->setCallback("SoundUseADPCM", NULL);
|
|
|
|
|
ConfigFile->setCallback("SoundForceSoftware", NULL);
|
|
|
|
|
ConfigFile->setCallback("SoundDriver", NULL);
|
|
|
|
|
// delete PlaylistManager;
|
|
|
|
|
// PlaylistManager = NULL;
|
|
|
|
|
delete AudioMixer;
|
|
|
|
|
AudioMixer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void initSound()
|
|
|
|
|
{
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
if (ConfigFile->exists("SoundEnabled") ? ConfigFile->getVar("SoundEnabled").asBool() : false)
|
|
|
|
|
initSound2();
|
|
|
|
|
ConfigFile->setCallback("SoundEnabled", cbConfigFileSoundEnabled);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//void playSound (CEntity &entity, TSoundId id)
|
|
|
|
|
//{
|
|
|
|
|
///* entity.Source = AudioMixer->createSource (id);
|
|
|
|
|
// entity.Source->setLooping (true);
|
|
|
|
|
// entity.Source->play ();
|
|
|
|
|
//*/}
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//void deleteSound (CEntity &entity)
|
|
|
|
|
//{
|
|
|
|
|
///* if (entity.Source != NULL)
|
|
|
|
@ -162,42 +197,36 @@ using namespace NLSOUND;
|
|
|
|
|
// entity.Source = NULL;
|
|
|
|
|
// }
|
|
|
|
|
//*/}
|
|
|
|
|
//
|
|
|
|
|
//void updateSound()
|
|
|
|
|
//{
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// if (SoundEnabled)
|
|
|
|
|
//// {
|
|
|
|
|
//// PlaylistManager->update(DiffTime);
|
|
|
|
|
//// AudioMixer->update();
|
|
|
|
|
//// }
|
|
|
|
|
////#endif
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
////void releaseSound2()
|
|
|
|
|
////{
|
|
|
|
|
//// SoundEnabled = false;
|
|
|
|
|
//// ConfigFile->setCallback("SoundMaxTracks", NULL);
|
|
|
|
|
//// ConfigFile->setCallback("SoundUseEax", NULL);
|
|
|
|
|
//// ConfigFile->setCallback("SoundUseADPCM", NULL);
|
|
|
|
|
//// ConfigFile->setCallback("SoundForceSoftware", NULL);
|
|
|
|
|
//// ConfigFile->setCallback("SoundDriver", NULL);
|
|
|
|
|
//// delete PlaylistManager;
|
|
|
|
|
//// PlaylistManager = NULL;
|
|
|
|
|
//// delete AudioMixer;
|
|
|
|
|
//// AudioMixer = NULL;
|
|
|
|
|
////}
|
|
|
|
|
////#endif
|
|
|
|
|
//
|
|
|
|
|
//void releaseSound()
|
|
|
|
|
//{
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
//// ConfigFile->setCallback("SoundEnabled", NULL);
|
|
|
|
|
//// if (SoundEnabled) releaseSound2();
|
|
|
|
|
////#endif
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
void updateSound()
|
|
|
|
|
{
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
if (SoundEnabled)
|
|
|
|
|
{
|
|
|
|
|
// PlaylistManager->update(DiffTime);
|
|
|
|
|
AudioMixer->update();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void releaseSound()
|
|
|
|
|
{
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
ConfigFile->setCallback("SoundEnabled", NULL);
|
|
|
|
|
if (SoundEnabled) releaseSound2();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void playMusic(const char *file)
|
|
|
|
|
{
|
|
|
|
|
#ifdef SBCLIENT_WITH_SOUND
|
|
|
|
|
if (AudioMixer)
|
|
|
|
|
AudioMixer->playMusic(file, 1000, true, true);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} /* namespace SBCLIENT */
|
|
|
|
|
|
|
|
|
|
////#ifdef NL_OS_WINDOWS
|
|
|
|
|
////
|
|
|
|
|
////void playMusic(sint32 playlist, sint32 track)
|
|
|
|
@ -211,35 +240,38 @@ using namespace NLSOUND;
|
|
|
|
|
//// if (SoundEnabled)
|
|
|
|
|
//// PlaylistManager->setVolume(playlist, volume);
|
|
|
|
|
////}
|
|
|
|
|
////
|
|
|
|
|
////NLMISC_COMMAND(music_bg,"background music","")
|
|
|
|
|
////{
|
|
|
|
|
//// if (args.size() != 0) return false;
|
|
|
|
|
//// playMusic(SBCLIENT_MUSIC_BACKGROUND);
|
|
|
|
|
//// return true;
|
|
|
|
|
////}
|
|
|
|
|
////
|
|
|
|
|
////NLMISC_COMMAND(music_bg_beat,"background music with beat","")
|
|
|
|
|
////{
|
|
|
|
|
//// if (args.size() != 0) return false;
|
|
|
|
|
//// PlaylistManager->playMusic(SBCLIENT_MUSIC_BACKGROUND_BEAT);
|
|
|
|
|
//// return true;
|
|
|
|
|
////}
|
|
|
|
|
////
|
|
|
|
|
////NLMISC_COMMAND(music_wait,"loading music","")
|
|
|
|
|
////{
|
|
|
|
|
//// if (args.size() != 0) return false;
|
|
|
|
|
//// PlaylistManager->playMusic(SBCLIENT_MUSIC_WAIT);
|
|
|
|
|
//// return true;
|
|
|
|
|
////}
|
|
|
|
|
////
|
|
|
|
|
////NLMISC_COMMAND(music_login,"login screen music","")
|
|
|
|
|
////{
|
|
|
|
|
//// if (args.size() != 0) return false;
|
|
|
|
|
//// PlaylistManager->playMusic(SBCLIENT_MUSIC_LOGIN);
|
|
|
|
|
//// return true;
|
|
|
|
|
////}
|
|
|
|
|
////
|
|
|
|
|
|
|
|
|
|
NLMISC_COMMAND(music_bg,"background music","")
|
|
|
|
|
{
|
|
|
|
|
if (args.size() != 0) return false;
|
|
|
|
|
SBCLIENT::playMusic(SBCLIENT_MUSIC_BACKGROUND);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLMISC_COMMAND(music_bg_beat,"background music with beat","")
|
|
|
|
|
{
|
|
|
|
|
if (args.size() != 0)
|
|
|
|
|
return false;
|
|
|
|
|
SBCLIENT::playMusic(SBCLIENT_MUSIC_BACKGROUND_BEAT);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLMISC_COMMAND(music_wait,"loading music","")
|
|
|
|
|
{
|
|
|
|
|
if (args.size() != 0)
|
|
|
|
|
return false;
|
|
|
|
|
SBCLIENT::playMusic(SBCLIENT_MUSIC_WAIT);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLMISC_COMMAND(music_login,"login screen music","")
|
|
|
|
|
{
|
|
|
|
|
if (args.size() != 0)
|
|
|
|
|
return false;
|
|
|
|
|
SBCLIENT::playMusic(SBCLIENT_MUSIC_LOGIN);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////#endif
|
|
|
|
|
|
|
|
|
|
#endif // SBCLIENT_WITH_SOUND
|
|
|
|
|
/* end of file */
|
|
|
|
|