From 9afdcfaf50bc080421bdb0b7326d002a4048064d Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 27 Nov 2011 01:14:16 +0000 Subject: [PATCH] Apply patch that is a bit similar to what xapantu did, but in a IMHO more modular way git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10264 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- CMakeLists.txt | 2 + src/Makefile.am | 2 + src/audio/dummy_sfx.hpp | 58 +++++++++++++++++++ src/audio/music_dummy.hpp | 48 +++++++++++++++ src/audio/music_information.cpp | 15 ++++- src/audio/music_manager.cpp | 21 ++++--- src/audio/music_ogg.hpp | 4 ++ src/audio/sfx_buffer.hpp | 2 +- src/audio/sfx_manager.cpp | 29 +++++++--- src/audio/sfx_openal.cpp | 4 +- src/audio/sfx_openal.hpp | 3 + .../Xcode/STK_XCode.xcodeproj/project.pbxproj | 4 ++ 12 files changed, 173 insertions(+), 19 deletions(-) create mode 100644 src/audio/dummy_sfx.hpp create mode 100644 src/audio/music_dummy.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3814537e7..5ad4d1815 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,9 @@ set( SRCS ${SRCS} src/main.cpp src/animations/ipo.hpp src/animations/three_d_animation.cpp src/animations/three_d_animation.hpp + src/audio/dummy_sfx.hpp src/audio/music.hpp + src/audio/music_dummy.hpp src/audio/music_information.cpp src/audio/music_information.hpp src/audio/music_manager.cpp diff --git a/src/Makefile.am b/src/Makefile.am index ecc6294c4..d83241a85 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,7 +34,9 @@ supertuxkart_SOURCES = \ animations/ipo.hpp \ animations/three_d_animation.cpp \ animations/three_d_animation.hpp \ + audio/dummy_sfx.hpp \ audio/music.hpp \ + audio/music_dummy.hpp \ audio/music_information.cpp \ audio/music_information.hpp \ audio/music_manager.cpp \ diff --git a/src/audio/dummy_sfx.hpp b/src/audio/dummy_sfx.hpp new file mode 100644 index 000000000..02fedf22b --- /dev/null +++ b/src/audio/dummy_sfx.hpp @@ -0,0 +1,58 @@ +// $Id$ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006 Patrick Ammann +// Copyright (C) 2008 Joerg Henrichs, Patrick Ammann +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_DUMMY_SFX_HPP +#define HEADER_DUMMY_SFX_HPP + +#include "audio/sfx_base.hpp" + + + +/** + * \brief Dummy sound when ogg or openal aren't available + * \ingroup audio + */ +class DummySFX : public SFXBase +{ +public: + virtual ~DummySFX() {} + + /** Late creation, if SFX was initially disabled */ + virtual bool init() { return true; } + + virtual void position(const Vec3 &position) {} + virtual void setLoop(bool status) {} + virtual void play() {} + virtual void stop() {} + virtual void pause() {} + virtual void resume() {} + virtual void speed(float factor) {} + virtual void volume(float gain) {} + virtual SFXManager::SFXStatus getStatus() { return SFXManager::SFX_STOPPED; } + virtual void onSoundEnabledBack() {} + virtual void setRolloff(float rolloff) {} + + virtual const SFXBuffer* getBuffer() { return NULL; } + +}; // DummySFX + + +#endif // HEADER_SFX_HPP + diff --git a/src/audio/music_dummy.hpp b/src/audio/music_dummy.hpp new file mode 100644 index 000000000..414f192a0 --- /dev/null +++ b/src/audio/music_dummy.hpp @@ -0,0 +1,48 @@ +// $Id$ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2006 Patrick Ammann +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_MUSIC_DUMMY_HPP +#define HEADER_MUSIC_DUMMY_HPP + +#include + +#include "audio/music.hpp" +/** + * \brief Dummy object used when ogg vorbis support is not available + * \ingroup audio + */ +class MusicDummy : public Music +{ +public: + virtual bool load (const std::string& filename) { return true; } + virtual bool playMusic () { return true; } + virtual bool stopMusic () { return true; } + virtual bool pauseMusic () { return true; } + virtual bool resumeMusic () { return true; } + virtual void volumeMusic (float gain) {} + virtual void updateFading(float percent) {} + virtual void updateFaster(float percent, float pitch) {} + virtual void update () {} + virtual bool isPlaying () { return false; } + + virtual ~MusicDummy () {} +}; + +#endif // HEADER_MUSIC_HPP + diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index b2b0608e0..f7b6c9d07 100644 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -22,6 +22,7 @@ #include #include +#include "audio/music_dummy.hpp" #include "audio/music_ogg.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" @@ -152,8 +153,13 @@ void MusicInformation::startMusic() } if (m_normal_music != NULL) delete m_normal_music; + +#if HAVE_OGGVORBIS m_normal_music = new MusicOggStream(); - +#else + m_normal_music = new MusicDummy(); +#endif + if((m_normal_music->load(m_normal_filename)) == false) { delete m_normal_music; @@ -181,7 +187,12 @@ void MusicInformation::startMusic() m_fast_filename.c_str()); return; } - m_fast_music= new MusicOggStream(); + +#if HAVE_OGGVORBIS + m_fast_music = new MusicOggStream(); +#else + m_fast_music = new MusicDummy(); +#endif if((m_fast_music->load(m_fast_filename)) == false) { diff --git a/src/audio/music_manager.cpp b/src/audio/music_manager.cpp index 95bf52c99..99113fb9d 100644 --- a/src/audio/music_manager.cpp +++ b/src/audio/music_manager.cpp @@ -22,12 +22,15 @@ #include #include -#ifdef __APPLE__ -# include -# include -#else -# include -# include + +#if HAVE_OGGVORBIS +# ifdef __APPLE__ +# include +# include +# else +# include +# include +# endif #endif #include "audio/music_ogg.hpp" @@ -45,6 +48,7 @@ MusicManager::MusicManager() setMasterMusicVolume(UserConfigParams::m_music_volume); //FIXME: I'm not sure that this code goes here +#if HAVE_OGGVORBIS ALCdevice* device = alcOpenDevice ( NULL ); //The default sound device if( device == NULL ) { @@ -69,7 +73,8 @@ MusicManager::MusicManager() } alGetError(); //Called here to clear any non-important errors found - +#endif + loadMusicInformation(); } // MusicManager @@ -85,6 +90,7 @@ MusicManager::~MusicManager() i->second = NULL; } +#if HAVE_OGGVORBIS if(m_initialized) { ALCcontext* context = alcGetCurrentContext(); @@ -95,6 +101,7 @@ MusicManager::~MusicManager() alcCloseDevice( device ); } +#endif } // ~MusicManager //----------------------------------------------------------------------------- diff --git a/src/audio/music_ogg.hpp b/src/audio/music_ogg.hpp index a7c94920e..a93ca8c88 100644 --- a/src/audio/music_ogg.hpp +++ b/src/audio/music_ogg.hpp @@ -20,6 +20,8 @@ #ifndef HEADER_MUSICOGG_HPP #define HEADER_MUSICOGG_HPP +#if HAVE_OGGVORBIS + #include #include @@ -87,4 +89,6 @@ private: static const int m_buffer_size = 11025*4;//one full second of audio at 44100 samples per second }; +#endif + #endif // HEADER_MUSICOGG_HPP diff --git a/src/audio/sfx_buffer.hpp b/src/audio/sfx_buffer.hpp index 7d6dd0436..7e5ac9c35 100644 --- a/src/audio/sfx_buffer.hpp +++ b/src/audio/sfx_buffer.hpp @@ -88,7 +88,7 @@ public: bool isLoaded() const { return m_loaded; } /** Only returns a valid buffer if isLoaded() returned true */ - ALuint getBuffer() const { return m_buffer; } + ALuint getBufferID() const { return m_buffer; } bool isPositional() const { return m_positional; } float getRolloff() const { return m_rolloff; } diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 6a6bbc26d..381507922 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -17,6 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "audio/dummy_sfx.hpp" #include "audio/music_manager.hpp" #include "audio/sfx_buffer.hpp" @@ -29,12 +30,14 @@ #include #include -#ifdef __APPLE__ -# include -# include -#else -# include -# include +#if HAVE_OGGVORBIS +# ifdef __APPLE__ +# include +# include +# else +# include +# include +# endif #endif #include "audio/sfx_openal.hpp" @@ -274,8 +277,12 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer, // positional, // race_manager->getNumLocalPlayers(), buffer->isPositional()); - assert( alIsBuffer(buffer->getBuffer()) ); +#if HAVE_OGGVORBIS + assert( alIsBuffer(buffer->getBufferID()) ); SFXBase* sfx = new SFXOpenAL(buffer, positional, buffer->getGain()); +#else + SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain()); +#endif sfx->volume(m_master_gain); @@ -401,6 +408,7 @@ void SFXManager::resumeAll() */ bool SFXManager::checkError(const std::string &context) { +#if HAVE_OGGVORBIS // Check (and clear) the error flag int error = alGetError(); @@ -410,6 +418,7 @@ bool SFXManager::checkError(const std::string &context) context.c_str(), SFXManager::getErrorString(error).c_str()); return false; } +#endif return true; } // checkError @@ -447,6 +456,7 @@ void SFXManager::setMasterSFXVolume(float gain) //----------------------------------------------------------------------------- const std::string SFXManager::getErrorString(int err) { +#if HAVE_OGGVORBIS switch(err) { case AL_NO_ERROR: return std::string("AL_NO_ERROR" ); @@ -457,12 +467,16 @@ const std::string SFXManager::getErrorString(int err) case AL_OUT_OF_MEMORY: return std::string("AL_OUT_OF_MEMORY" ); default: return std::string("UNKNOWN"); }; +#else + return std::string("sound disabled"); +#endif } // getErrorString //----------------------------------------------------------------------------- void SFXManager::positionListener(const Vec3 &position, const Vec3 &front) { +#if HAVE_OGGVORBIS if (!UserConfigParams::m_sfx || !m_initialized) return; //forward vector @@ -477,6 +491,7 @@ void SFXManager::positionListener(const Vec3 &position, const Vec3 &front) alListener3f(AL_POSITION, position.getX(), position.getY(), position.getZ()); alListenerfv(AL_ORIENTATION, m_listenerVec); +#endif } //----------------------------------------------------------------------------- diff --git a/src/audio/sfx_openal.cpp b/src/audio/sfx_openal.cpp index b26c8fc88..14838c802 100644 --- a/src/audio/sfx_openal.cpp +++ b/src/audio/sfx_openal.cpp @@ -72,13 +72,13 @@ bool SFXOpenAL::init() alGenSources(1, &m_soundSource ); if (!SFXManager::checkError("generating a source")) return false; - assert( alIsBuffer(m_soundBuffer->getBuffer()) ); + assert( alIsBuffer(m_soundBuffer->getBufferID()) ); assert( alIsSource(m_soundSource) ); //std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff // << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl; - alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer->getBuffer()); + alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer->getBufferID()); if (!SFXManager::checkError("attaching the buffer to the source")) return false; diff --git a/src/audio/sfx_openal.hpp b/src/audio/sfx_openal.hpp index 15c8fb803..0c7a4df2b 100644 --- a/src/audio/sfx_openal.hpp +++ b/src/audio/sfx_openal.hpp @@ -20,6 +20,8 @@ #ifndef HEADER_SFX_OPENAL_HPP #define HEADER_SFX_OPENAL_HPP +#if HAVE_OGGVORBIS + #include #ifdef __APPLE__ # include @@ -77,5 +79,6 @@ public: }; // SFXOpenAL +#endif #endif // HEADER_SFX_OPENAL_HPP diff --git a/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj b/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj index 776e6cf86..689392cd5 100644 --- a/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj +++ b/src/ide/Xcode/STK_XCode.xcodeproj/project.pbxproj @@ -1147,6 +1147,8 @@ 95A1187C0F78026D00B18B3D /* device_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = device_manager.hpp; path = ../../input/device_manager.hpp; sourceTree = SOURCE_ROOT; }; 95A5402D1481BD950086FE38 /* inetwork_http.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = inetwork_http.hpp; path = ../../addons/inetwork_http.hpp; sourceTree = SOURCE_ROOT; }; 95A540411481BEB60086FE38 /* dummy_network_http.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dummy_network_http.hpp; path = ../../addons/dummy_network_http.hpp; sourceTree = SOURCE_ROOT; }; + 95A540581481C4760086FE38 /* dummy_sfx.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dummy_sfx.hpp; path = ../../audio/dummy_sfx.hpp; sourceTree = SOURCE_ROOT; }; + 95A5405B1481C4DB0086FE38 /* music_dummy.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = music_dummy.hpp; path = ../../audio/music_dummy.hpp; sourceTree = SOURCE_ROOT; }; 95AAD97E12BAD36300B7B8A3 /* tutorial_screen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tutorial_screen.cpp; path = ../../states_screens/tutorial_screen.cpp; sourceTree = SOURCE_ROOT; }; 95AAD97F12BAD36300B7B8A3 /* tutorial_screen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tutorial_screen.hpp; path = ../../states_screens/tutorial_screen.hpp; sourceTree = SOURCE_ROOT; }; 95B5CD12102DE08F00EF2001 /* device_config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = device_config.hpp; path = ../../config/device_config.hpp; sourceTree = SOURCE_ROOT; }; @@ -2373,7 +2375,9 @@ 95C2AC260F296540000D3E5D /* audio */ = { isa = PBXGroup; children = ( + 95A540581481C4760086FE38 /* dummy_sfx.hpp */, 95C2AC270F296540000D3E5D /* music.hpp */, + 95A5405B1481C4DB0086FE38 /* music_dummy.hpp */, 95C2AC280F296540000D3E5D /* music_information.cpp */, 95C2AC290F296540000D3E5D /* music_information.hpp */, 958BD76E117F6AE90095B483 /* music_manager.cpp */,