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
This commit is contained in:
auria 2011-11-27 01:14:16 +00:00
parent c50e1a6c8b
commit 9afdcfaf50
12 changed files with 173 additions and 19 deletions

View File

@ -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

View File

@ -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 \

58
src/audio/dummy_sfx.hpp Normal file
View File

@ -0,0 +1,58 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Patrick Ammann <pammann@aro.ch>
// 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

48
src/audio/music_dummy.hpp Normal file
View File

@ -0,0 +1,48 @@
// $Id$
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Patrick Ammann <pammann@aro.ch>
//
// 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 <string>
#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

View File

@ -22,6 +22,7 @@
#include <stdexcept>
#include <iostream>
#include "audio/music_dummy.hpp"
#include "audio/music_ogg.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
@ -152,7 +153,12 @@ 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)
{
@ -181,7 +187,12 @@ void MusicInformation::startMusic()
m_fast_filename.c_str());
return;
}
#if HAVE_OGGVORBIS
m_fast_music = new MusicOggStream();
#else
m_fast_music = new MusicDummy();
#endif
if((m_fast_music->load(m_fast_filename)) == false)
{

View File

@ -22,6 +22,8 @@
#include <assert.h>
#include <fstream>
#if HAVE_OGGVORBIS
# ifdef __APPLE__
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
@ -29,6 +31,7 @@
# include <AL/al.h>
# include <AL/alc.h>
# endif
#endif
#include "audio/music_ogg.hpp"
#include "audio/sfx_openal.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,6 +73,7 @@ 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
//-----------------------------------------------------------------------------

View File

@ -20,6 +20,8 @@
#ifndef HEADER_MUSICOGG_HPP
#define HEADER_MUSICOGG_HPP
#if HAVE_OGGVORBIS
#include <string>
#include <ogg/ogg.h>
@ -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

View File

@ -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; }

View File

@ -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,6 +30,7 @@
#include <stdlib.h>
#include <math.h>
#if HAVE_OGGVORBIS
# ifdef __APPLE__
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
@ -36,6 +38,7 @@
# include <AL/al.h>
# include <AL/alc.h>
# endif
#endif
#include "audio/sfx_openal.hpp"
#include "config/user_config.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
}
//-----------------------------------------------------------------------------

View File

@ -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;

View File

@ -20,6 +20,8 @@
#ifndef HEADER_SFX_OPENAL_HPP
#define HEADER_SFX_OPENAL_HPP
#if HAVE_OGGVORBIS
#include <assert.h>
#ifdef __APPLE__
# include <OpenAL/al.h>
@ -77,5 +79,6 @@ public:
}; // SFXOpenAL
#endif
#endif // HEADER_SFX_OPENAL_HPP

View File

@ -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 */,