diff --git a/src/audio/dummy_sfx.hpp b/src/audio/dummy_sfx.hpp index 32eb1116d..bc07f2184 100644 --- a/src/audio/dummy_sfx.hpp +++ b/src/audio/dummy_sfx.hpp @@ -21,7 +21,7 @@ #define HEADER_DUMMY_SFX_HPP #include "audio/sfx_base.hpp" - +#include "utils/cpp2011.hpp" /** * \brief Dummy sound when ogg or openal aren't available @@ -32,41 +32,41 @@ class DummySFX : public SFXBase public: DummySFX(SFXBuffer* buffer, bool positional, float gain) {} - virtual ~DummySFX() {} + virtual ~DummySFX() {} /** Late creation, if SFX was initially disabled */ - virtual bool init() { return true; } - virtual bool isLooped() { return false; } - virtual void updatePlayingSFX(float dt) {} - virtual void setLoop(bool status) {} - virtual void reallySetLoop(bool status) {} - virtual void setPosition(const Vec3 &p) {} - virtual void reallySetPosition(const Vec3 &p) {} + virtual bool init() OVERRIDE { return true; } + virtual bool isLooped() OVERRIDE { return false; } + virtual void updatePlayingSFX(float dt) OVERRIDE {} + virtual void setLoop(bool status) OVERRIDE {} + virtual void reallySetLoop(bool status) OVERRIDE {} + virtual void setPosition(const Vec3 &p) OVERRIDE {} + virtual void reallySetPosition(const Vec3 &p) OVERRIDE {} virtual void setSpeedPosition(float factor, - const Vec3 &p) {} + const Vec3 &p) OVERRIDE {} virtual void reallySetSpeedPosition(float f, - const Vec3 &p) {} - virtual void play() {} - virtual void reallyPlayNow(SFXBuffer* buffer = NULL) {} - virtual void play(const Vec3 &xyz, SFXBuffer* buffer = NULL) {} - virtual void reallyPlayNow(const Vec3 &xyz, SFXBuffer* buffer = NULL) {} - virtual void stop() {} - virtual void reallyStopNow() {} - virtual void pause() {} - virtual void reallyPauseNow() {} - virtual void resume() {} - virtual void reallyResumeNow() {} - virtual void deleteSFX() { delete this; } - virtual void setSpeed(float factor) {} - virtual void reallySetSpeed(float factor) {} - virtual void setVolume(float gain) {} - virtual void reallySetVolume(float gain) {} - virtual void setMasterVolume(float gain) {} - virtual void reallySetMasterVolumeNow(float gain) {} - virtual SFXStatus getStatus() { return SFX_STOPPED; } - virtual void onSoundEnabledBack() {} - virtual void setRolloff(float rolloff) {} - virtual const SFXBuffer* getBuffer() const { return NULL; } + const Vec3 &p) OVERRIDE {} + virtual void play() OVERRIDE {} + virtual void reallyPlayNow(SFXBuffer* buffer = NULL) OVERRIDE {} + virtual void play(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE {} + virtual void reallyPlayNow(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE {} + virtual void stop() OVERRIDE {} + virtual void reallyStopNow() OVERRIDE {} + virtual void pause() OVERRIDE {} + virtual void reallyPauseNow() OVERRIDE {} + virtual void resume() OVERRIDE {} + virtual void reallyResumeNow() OVERRIDE {} + virtual void deleteSFX() OVERRIDE {} + virtual void setSpeed(float factor) OVERRIDE {} + virtual void reallySetSpeed(float factor) OVERRIDE {} + virtual void setVolume(float gain) OVERRIDE {} + virtual void reallySetVolume(float gain) OVERRIDE {} + virtual void setMasterVolume(float gain) OVERRIDE {} + virtual void reallySetMasterVolumeNow(float gain) OVERRIDE {} + virtual SFXStatus getStatus() OVERRIDE { return SFX_STOPPED; } + virtual void onSoundEnabledBack() OVERRIDE {} + virtual void setRolloff(float rolloff) OVERRIDE {} + virtual const SFXBuffer* getBuffer() const OVERRIDE { return NULL; } }; // DummySFX diff --git a/src/audio/music_manager.cpp b/src/audio/music_manager.cpp index b9949d2c2..6ef12a973 100644 --- a/src/audio/music_manager.cpp +++ b/src/audio/music_manager.cpp @@ -33,6 +33,7 @@ #endif #include "audio/music_ogg.hpp" +#include "audio/sfx_manager.hpp" #include "audio/sfx_openal.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" @@ -44,6 +45,7 @@ MusicManager* music_manager= NULL; MusicManager::MusicManager() { m_current_music= NULL; + m_initialized = false; setMasterMusicVolume(UserConfigParams::m_music_volume); //FIXME: I'm not sure that this code goes here diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index cda8fce6a..3d396610b 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -97,6 +97,7 @@ SFXManager::SFXManager() loadSfx(); +#ifdef ENABLE_SOUND pthread_cond_init(&m_cond_request, NULL); pthread_attr_t attr; @@ -123,7 +124,7 @@ SFXManager::SFXManager() m_sfx_commands.lock(); m_sfx_commands.getData().clear(); m_sfx_commands.unlock(); - +#endif } // SoundManager //----------------------------------------------------------------------------- @@ -131,11 +132,13 @@ SFXManager::SFXManager() */ SFXManager::~SFXManager() { +#ifdef ENABLE_SOUND m_thread_id.lock(); pthread_join(*m_thread_id.getData(), NULL); delete m_thread_id.getData(); m_thread_id.unlock(); pthread_cond_destroy(&m_cond_request); +#endif // ---- clear m_all_sfx // not strictly necessary, but might avoid copy&paste problems @@ -185,8 +188,10 @@ SFXManager::~SFXManager() */ void SFXManager::queue(SFXCommands command, SFXBase *sfx) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, sfx); queueCommand(sfx_command); +#endif } // queue //---------------------------------------------------------------------------- @@ -199,8 +204,10 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx) */ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, sfx, f); queueCommand(sfx_command); +#endif } // queue(float) //---------------------------------------------------------------------------- @@ -213,17 +220,21 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f) */ void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, sfx, p); queueCommand(sfx_command); +#endif } // queue (Vec3) //---------------------------------------------------------------------------- void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p, SFXBuffer* buffer) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, sfx, p); sfx_command->m_buffer = buffer; queueCommand(sfx_command); +#endif } // queue (Vec3) //---------------------------------------------------------------------------- @@ -238,8 +249,10 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p, SFXBuff void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f, const Vec3 &p) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, sfx, f, p); queueCommand(sfx_command); +#endif } // queue(float, Vec3) //---------------------------------------------------------------------------- @@ -248,8 +261,10 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f, */ void SFXManager::queue(SFXCommands command, MusicInformation *mi) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, mi); queueCommand(sfx_command); +#endif } // queue(MusicInformation) //---------------------------------------------------------------------------- /** Queues a command for the music manager that takes a floating point value @@ -259,8 +274,10 @@ void SFXManager::queue(SFXCommands command, MusicInformation *mi) */ void SFXManager::queue(SFXCommands command, MusicInformation *mi, float f) { +#ifdef ENABLE_SOUND SFXCommand *sfx_command = new SFXCommand(command, mi, f); queueCommand(sfx_command); +#endif } // queue(MusicInformation) //---------------------------------------------------------------------------- @@ -270,6 +287,7 @@ void SFXManager::queue(SFXCommands command, MusicInformation *mi, float f) */ void SFXManager::queueCommand(SFXCommand *command) { +#ifdef ENABLE_SOUND m_sfx_commands.lock(); if(World::getWorld() && m_sfx_commands.getData().size() > 20*race_manager->getNumberOfKarts()+20 && @@ -293,6 +311,7 @@ void SFXManager::queueCommand(SFXCommand *command) } m_sfx_commands.getData().push_back(command); m_sfx_commands.unlock(); +#endif } // queueCommand //---------------------------------------------------------------------------- @@ -301,9 +320,13 @@ void SFXManager::queueCommand(SFXCommand *command) */ void SFXManager::stopThread() { +#ifdef ENABLE_SOUND queue(SFX_EXIT); // Make sure the thread wakes up. pthread_cond_signal(&m_cond_request); +#else + setCanBeDeleted(); +#endif } // stopThread //---------------------------------------------------------------------------- @@ -314,6 +337,7 @@ void SFXManager::stopThread() */ void* SFXManager::mainLoop(void *obj) { +#ifdef ENABLE_SOUND VS::setThreadName("SFXManager"); SFXManager *me = (SFXManager*)obj; @@ -436,6 +460,7 @@ void* SFXManager::mainLoop(void *obj) me->m_sfx_commands.getData().erase(me->m_sfx_commands.getData().begin()); } me->m_sfx_commands.unlock(); +#endif return NULL; } // mainLoop @@ -653,7 +678,7 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer, //assert( alIsBuffer(buffer->getBufferID()) ); crashes on server SFXBase* sfx = new SFXOpenAL(buffer, positional, buffer->getGain(), owns_buffer); #else - SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain(), owns_buffer); + SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain()); #endif sfx->setMasterVolume(m_master_gain); @@ -738,9 +763,11 @@ void SFXManager::deleteSFXMapping(const std::string &name) */ void SFXManager::update() { +#ifdef ENABLE_SOUND queue(SFX_UPDATE, (SFXBase*)NULL); // Wake up the sfx thread to handle all queued up audio commands. pthread_cond_signal(&m_cond_request); +#endif } // update //---------------------------------------------------------------------------- @@ -750,6 +777,7 @@ void SFXManager::update() */ void SFXManager::reallyUpdateNow(SFXCommand *current) { +#ifdef ENABLE_SOUND if (m_last_update_time < 0.0) { // first time @@ -782,7 +810,7 @@ void SFXManager::reallyUpdateNow(SFXCommand *current) i->second->updatePlayingSFX(dt); } // for i in m_all_sfx m_quick_sounds.unlock(); - +#endif } // reallyUpdateNow //---------------------------------------------------------------------------- @@ -1002,6 +1030,7 @@ void SFXManager::reallyPositionListenerNow() */ SFXBase* SFXManager::quickSound(const std::string &sound_type) { +#ifdef ENABLE_SOUND if (!sfxAllowed()) return NULL; MutexLockerHelper lock(m_quick_sounds); @@ -1024,6 +1053,8 @@ SFXBase* SFXManager::quickSound(const std::string &sound_type) base_sound->play(); return base_sound; } - +#else + return NULL; +#endif } // quickSound diff --git a/src/audio/sfx_openal.hpp b/src/audio/sfx_openal.hpp index 009f8ff1c..32f948451 100644 --- a/src/audio/sfx_openal.hpp +++ b/src/audio/sfx_openal.hpp @@ -81,43 +81,44 @@ public: bool owns_buffer = false); virtual ~SFXOpenAL(); - virtual void updatePlayingSFX(float dt); + virtual void updatePlayingSFX(float dt) OVERRIDE; virtual bool init() OVERRIDE; virtual void play() OVERRIDE; virtual void reallyPlayNow(SFXBuffer* buffer = NULL) OVERRIDE; virtual void play(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE; virtual void reallyPlayNow(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE; - virtual void setLoop(bool status); - virtual void reallySetLoop(bool status); - virtual void stop(); - virtual void reallyStopNow(); - virtual void pause(); - virtual void reallyPauseNow(); - virtual void resume(); - virtual void reallyResumeNow(); - virtual void deleteSFX(); - virtual void setSpeed(float factor); - virtual void reallySetSpeed(float factor); - virtual void setPosition(const Vec3 &position); - virtual void reallySetPosition(const Vec3 &p); - virtual void setSpeedPosition(float factor, const Vec3 &p); - virtual void reallySetSpeedPosition(float f,const Vec3 &p); - virtual void setVolume(float volume); - virtual void reallySetVolume(float volume); - virtual void setMasterVolume(float volume); - virtual void reallySetMasterVolumeNow(float volue); - virtual void onSoundEnabledBack(); - virtual void setRolloff(float rolloff); + virtual void setLoop(bool status) OVERRIDE; + virtual void reallySetLoop(bool status) OVERRIDE; + virtual void stop() OVERRIDE; + virtual void reallyStopNow() OVERRIDE; + virtual void pause() OVERRIDE; + virtual void reallyPauseNow() OVERRIDE; + virtual void resume() OVERRIDE; + virtual void reallyResumeNow() OVERRIDE; + virtual void deleteSFX() OVERRIDE; + virtual void setSpeed(float factor) OVERRIDE; + virtual void reallySetSpeed(float factor) OVERRIDE; + virtual void setPosition(const Vec3 &position) OVERRIDE; + virtual void reallySetPosition(const Vec3 &p) OVERRIDE; + virtual void setSpeedPosition(float factor, const Vec3 &p) OVERRIDE; + virtual void reallySetSpeedPosition(float f,const Vec3 &p) OVERRIDE; + virtual void setVolume(float volume) OVERRIDE; + virtual void reallySetVolume(float volume) OVERRIDE; + virtual void setMasterVolume(float volume) OVERRIDE; + virtual void reallySetMasterVolumeNow(float volue) OVERRIDE; + virtual void onSoundEnabledBack() OVERRIDE; + virtual void setRolloff(float rolloff) OVERRIDE; // ------------------------------------------------------------------------ /** Returns if this sfx is looped or not. */ - virtual bool isLooped() { return m_loop; } + virtual bool isLooped() OVERRIDE { return m_loop; } // ------------------------------------------------------------------------ /** Returns the status of this sfx. */ - virtual SFXStatus getStatus() { return m_status; } + virtual SFXStatus getStatus() OVERRIDE { return m_status; } // ------------------------------------------------------------------------ /** Returns the buffer associated with this sfx. */ - virtual const SFXBuffer* getBuffer() const { return m_sound_buffer; } + virtual const SFXBuffer* getBuffer() const OVERRIDE + { return m_sound_buffer; } }; // SFXOpenAL