Moved some audio code around because the previous organisation was confusing, there was some SFX code among the music code

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5227 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-04-21 17:16:49 +00:00
parent c70a8536d2
commit c12618a48a
6 changed files with 32 additions and 23 deletions

View File

@ -512,6 +512,26 @@ const std::string SFXManager::getErrorString(int err)
//-----------------------------------------------------------------------------
void SFXManager::positionListener(const Vec3 &position, const Vec3 &front)
{
if (!UserConfigParams::m_sfx || !m_initialized) return;
//forward vector
m_listenerVec[0] = front.getX();
m_listenerVec[1] = front.getY();
m_listenerVec[2] = front.getZ();
//up vector
m_listenerVec[3] = 0;
m_listenerVec[4] = 0;
m_listenerVec[5] = 1;
alListener3f(AL_POSITION, position.getX(), position.getY(), position.getZ());
alListenerfv(AL_ORIENTATION, m_listenerVec);
}
//-----------------------------------------------------------------------------
void SFXManager::quickSound(const char* soundType)
{
if(!sfxAllowed()) return;

View File

@ -110,6 +110,9 @@ private:
/** To play non-positional sounds without having to create a new object for each */
static std::map<std::string, SFXBase*> m_quick_sounds;
/** listener vector (position vector + up vector) */
float m_listenerVec[6];
bool m_initialized;
float m_master_gain;
@ -142,6 +145,8 @@ public:
static bool checkError(const std::string &context);
static const std::string getErrorString(int err);
void positionListener(const Vec3 &position, const Vec3 &front);
/** Positional sound is cool, but creating a new object just to play a simple
menu sound is not. This function allows for 'quick sounds' in a single call.*/
void quickSound(const char* soundName);

View File

@ -166,6 +166,7 @@ void SoundManager::setMasterMusicVolume(float gain)
}
//-----------------------------------------------------------------------------
MusicInformation* SoundManager::getMusicInformation(const std::string& filename)
{
if(filename=="")
@ -185,19 +186,3 @@ MusicInformation* SoundManager::getMusicInformation(const std::string& filename)
} // getMusicInformation
//----------------------------------------------------------------------------
void SoundManager::positionListener(const Vec3 &position, const Vec3 &front)
{
if(!UserConfigParams::m_sfx || !m_initialized) return;
//forward vector
m_listenerVec[0] = front.getX();
m_listenerVec[1] = front.getY();
m_listenerVec[2] = front.getZ();
//up vector
m_listenerVec[3] = 0;
m_listenerVec[4] = 0;
m_listenerVec[5] = 1;
alListener3f(AL_POSITION, position.getX(), position.getY(), position.getZ());
alListenerfv(AL_ORIENTATION, m_listenerVec);
}

View File

@ -43,14 +43,12 @@ private:
m_allMusic;
void loadMusicInformation();
float m_listenerVec[6];
float m_masterGain;
public:
SoundManager();
virtual ~SoundManager();
void positionListener(const Vec3 &position, const Vec3 &front);
void startMusic(MusicInformation* mi);
void stopMusic();
bool initialized() const {return m_initialized; }

View File

@ -201,9 +201,10 @@ void Camera::smoothMoveCamera(float dt, const Vec3 &wanted_position,
m_camera->setPosition(current_position);
m_camera->setTarget(current_target);
if(race_manager->getNumLocalPlayers() < 2)
sound_manager->positionListener(current_position,
current_target - current_position);
if (race_manager->getNumLocalPlayers() < 2)
{
sfx_manager->positionListener(current_position, current_target - current_position);
}
// The following settings give a debug camera which shows the track from
// high above the kart straight down.

View File

@ -213,7 +213,7 @@ void AbstractStateManager::resetAndGoToScreen(Screen* screen)
input_manager->setMode(InputManager::MENU);
m_menu_stack.push_back(name);
setGameState(MENU);
sound_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
sfx_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
switchToScreen(name.c_str());
getCurrentScreen()->init();
}
@ -237,7 +237,7 @@ void AbstractStateManager::resetAndSetStack(Screen* screens[])
setGameState(MENU);
sound_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
sfx_manager->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
switchToScreen(m_menu_stack[m_menu_stack.size()-1].c_str());
getCurrentScreen()->init();
}