Applied Stephen's 3d sound patch.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2329 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
167107fcbc
commit
0ae024508a
@ -36,7 +36,7 @@ class SFXBase
|
||||
{
|
||||
public:
|
||||
virtual ~SFXBase() {}
|
||||
void position(const Vec3 &position) {};
|
||||
virtual void position(const Vec3 &position) = 0;
|
||||
virtual void loop() = 0;
|
||||
virtual void play() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
@ -46,13 +46,12 @@ SFXOpenAL::SFXOpenAL(ALuint buffer) : SFXBase()
|
||||
alGenSources(1, &m_soundSource );
|
||||
if(!SFXManager::checkError("generating a source")) return;
|
||||
|
||||
// not 3D yet
|
||||
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
|
||||
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 5.0);
|
||||
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, 0.2f );
|
||||
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE );
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, 0.1f );
|
||||
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE );//sound position is *not* relative to the camera.
|
||||
|
||||
m_ok = SFXManager::checkError("setting up the source");
|
||||
} // SFXOpenAL
|
||||
@ -145,12 +144,12 @@ void SFXOpenAL::play()
|
||||
/** Sets the position where this sound effects is played.
|
||||
* \param position Position of the sound effect.
|
||||
*/
|
||||
void SFXOpenAL::position(Vec3 position)
|
||||
void SFXOpenAL::position(const Vec3 &position)
|
||||
{
|
||||
if(!sfx_manager->sfxAllowed()||!m_ok) return;
|
||||
|
||||
alSource3f(m_soundSource, AL_POSITION,
|
||||
position.getX(), position.getY(), position.getZ());
|
||||
(float)position.getX(), (float)position.getY(), (float)position.getZ());
|
||||
SFXManager::checkError("positioning");
|
||||
} // position
|
||||
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
virtual void pause();
|
||||
virtual void resume();
|
||||
virtual void speed(float factor);
|
||||
virtual void position(Vec3 position);
|
||||
virtual void position(const Vec3 &position);
|
||||
virtual SFXManager::SFXStatus getStatus();
|
||||
|
||||
}; // SFXOpenAL
|
||||
|
@ -166,9 +166,20 @@ MusicInformation* SoundManager::getMusicInformation(const std::string& filename)
|
||||
} // SoundManager
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void SoundManager::positionListener(Vec3 position)
|
||||
void SoundManager::positionListener(Vec3 position, Vec3 front)
|
||||
{
|
||||
if(!user_config->doSFX() || !m_initialized) return;
|
||||
|
||||
//forward vector
|
||||
listenerVec[0] = front.getX();
|
||||
listenerVec[1] = front.getY();
|
||||
listenerVec[2] = front.getZ();
|
||||
//up vector
|
||||
listenerVec[3] = 0;
|
||||
listenerVec[4] = 0;
|
||||
listenerVec[5] = 1;
|
||||
|
||||
alListener3f(AL_POSITION, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
alListenerfv(AL_ORIENTATION, listenerVec);
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,12 @@ private:
|
||||
m_allMusic;
|
||||
|
||||
void loadMusicInformation();
|
||||
float listenerVec[6];
|
||||
public:
|
||||
SoundManager();
|
||||
virtual ~SoundManager();
|
||||
|
||||
void positionListener(Vec3 position);
|
||||
void positionListener(Vec3 position, Vec3 front);
|
||||
void startMusic(MusicInformation* mi);
|
||||
void stopMusic();
|
||||
bool initialized() const {return m_initialized; }
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "user_config.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "race_manager.hpp"
|
||||
#include "audio/sound_manager.hpp"
|
||||
|
||||
Camera::Camera(int camera_index, const Kart* kart)
|
||||
{
|
||||
@ -48,6 +49,12 @@ Camera::Camera(int camera_index, const Kart* kart)
|
||||
setScreenPosition(camera_index);
|
||||
} // Camera
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Camera::~Camera()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Camera::setScreenPosition(int camera_index)
|
||||
{
|
||||
@ -136,6 +143,7 @@ void Camera::reset()
|
||||
m_last_pitch = 0.0f;
|
||||
m_xyz = m_kart->getXYZ();
|
||||
m_hpr = Vec3(0,0,0);
|
||||
sound_manager->positionListener(m_xyz, m_xyz);
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -199,7 +207,7 @@ void Camera::update (float dt)
|
||||
m_xyz = c.getXYZ();
|
||||
m_hpr = c.getHPR();
|
||||
m_context -> setCamera(&c.toSgCoord());
|
||||
//sound_manager->positionListener(kart->getXYZ());
|
||||
sound_manager->positionListener(m_xyz, kart_xyz - m_xyz);
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
void finalCamera (float dt); // handle the final camera
|
||||
public:
|
||||
Camera (int camera_index, const Kart* kart);
|
||||
~Camera ();
|
||||
void setMode (Mode mode_); /** Set the camera to the given mode */
|
||||
Mode getMode();
|
||||
void setScreenPosition(int pos);
|
||||
|
@ -90,10 +90,8 @@ void Collectable::use()
|
||||
case COLLECT_HOMING:
|
||||
case COLLECT_BOWLING:
|
||||
case COLLECT_MISSILE:
|
||||
if(m_owner->isPlayerKart())
|
||||
{
|
||||
m_sound_shot->play();
|
||||
}
|
||||
m_sound_shot->position(m_owner->getXYZ());
|
||||
m_sound_shot->play();
|
||||
projectile_manager->newProjectile(m_owner, m_type);
|
||||
break ;
|
||||
|
||||
@ -109,11 +107,8 @@ void Collectable::use()
|
||||
{
|
||||
kart->attach(ATTACH_ANVIL, stk_config->m_anvil_time);
|
||||
kart->adjustSpeedWeight(stk_config->m_anvil_speed_factor*0.5f);
|
||||
|
||||
if(kart->isPlayerKart())
|
||||
{
|
||||
m_sound_use_anvil->play();
|
||||
}
|
||||
m_sound_use_anvil->position(m_owner->getXYZ());
|
||||
m_sound_use_anvil->play();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -122,7 +117,7 @@ void Collectable::use()
|
||||
|
||||
case COLLECT_PARACHUTE:
|
||||
{
|
||||
bool player_affected = false;
|
||||
Kart* player_kart = NULL;
|
||||
//Attach a parachutte(that last as twice as the
|
||||
//one from the bananas) to all the karts that
|
||||
//are in front of this one.
|
||||
@ -135,13 +130,13 @@ void Collectable::use()
|
||||
kart->attach(ATTACH_PARACHUTE, stk_config->m_parachute_time_other);
|
||||
|
||||
if(kart->isPlayerKart())
|
||||
player_affected = true;
|
||||
player_kart = kart;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(player_affected)
|
||||
if(player_kart)
|
||||
{
|
||||
m_sound_use_parachute->position(player_kart->getXYZ());
|
||||
m_sound_use_parachute->play();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ Explosion::~Explosion()
|
||||
//-----------------------------------------------------------------------------
|
||||
void Explosion::init(const Vec3& coord)
|
||||
{
|
||||
m_explode_sound->position(coord);
|
||||
m_explode_sound->play();
|
||||
|
||||
sgCoord c;
|
||||
@ -55,16 +56,20 @@ void Explosion::init(const Vec3& coord)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Explosion::update (float dt)
|
||||
void Explosion::update(float dt)
|
||||
{
|
||||
|
||||
if ( ++m_step >= m_seq->getNumKids() )
|
||||
if(++m_step >= m_seq->getNumKids())
|
||||
{
|
||||
scene->remove((ssgTransform*)this);
|
||||
projectile_manager->FinishedExplosion();
|
||||
return ;
|
||||
//be sure that the sound is not prematurely stopped
|
||||
if(m_explode_sound->getStatus() != SFXManager::SFX_PLAYING)
|
||||
{
|
||||
scene->remove((ssgTransform*)this);
|
||||
projectile_manager->FinishedExplosion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_seq->selectStep(m_step);
|
||||
}
|
||||
|
||||
m_seq -> selectStep ( m_step ) ;
|
||||
|
||||
}
|
||||
|
28
src/kart.cpp
28
src/kart.cpp
@ -106,6 +106,8 @@ Kart::Kart (const std::string& kart_name, int position,
|
||||
m_wheel_rear_r = NULL;
|
||||
|
||||
m_engine_sound = sfx_manager->newSFX(SFXManager::SOUND_ENGINE);
|
||||
m_beep_sound = sfx_manager->newSFX(SFXManager::SOUND_BEEP);
|
||||
m_crash_sound = sfx_manager->newSFX(SFXManager::SOUND_CRASH);
|
||||
|
||||
if(!m_engine_sound)
|
||||
{
|
||||
@ -271,6 +273,9 @@ Kart::~Kart()
|
||||
m_engine_sound->stop();
|
||||
}
|
||||
sfx_manager->deleteSFX(m_engine_sound);
|
||||
sfx_manager->deleteSFX(m_beep_sound);
|
||||
sfx_manager->deleteSFX(m_crash_sound);
|
||||
|
||||
|
||||
if(m_smokepuff) delete m_smokepuff;
|
||||
if(m_smoke_system != NULL) delete m_smoke_system;
|
||||
@ -551,6 +556,10 @@ void Kart::update(float dt)
|
||||
|
||||
Moveable::update(dt);
|
||||
|
||||
m_engine_sound->position(getXYZ());
|
||||
m_beep_sound->position(getXYZ());
|
||||
m_crash_sound->position(getXYZ());
|
||||
|
||||
// Check if a kart is (nearly) upside down and not moving much --> automatic rescue
|
||||
if((fabs(getHPR().getRoll())>60 && fabs(getSpeed())<3.0f) )
|
||||
{
|
||||
@ -600,6 +609,7 @@ void Kart::update(float dt)
|
||||
herring_manager->hitHerring(this);
|
||||
|
||||
processSkidMarks();
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set zipper time, and apply one time additional speed boost
|
||||
@ -701,8 +711,19 @@ void Kart::crashed(Kart *k)
|
||||
// After a collision disable the engine for a short time so that karts
|
||||
// can 'bounce back' a bit (without this the engine force will prevent
|
||||
// karts from bouncing back, they will instead stuck towards the obstable).
|
||||
m_bounce_back_time = 0.5f;
|
||||
if(m_bounce_back_time<=0.0f)
|
||||
{
|
||||
m_crash_sound->play();
|
||||
m_bounce_back_time = 0.5f;
|
||||
}
|
||||
} // crashed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Kart::beep()
|
||||
{
|
||||
m_beep_sound->play();
|
||||
} // beep
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Kart::updatePhysics (float dt)
|
||||
{
|
||||
@ -817,10 +838,9 @@ void Kart::updatePhysics (float dt)
|
||||
if(m_engine_sound && sfx_manager->sfxAllowed())
|
||||
{
|
||||
m_engine_sound->speed((float)((m_rpm * 2) / m_max_gear_rpm));
|
||||
//m_engine_sound->position(m_curr_track_coords);
|
||||
m_engine_sound->position(getXYZ());
|
||||
}
|
||||
// FIXME: what if sfx are disabled in the option menu??
|
||||
// The engine sound will still play!
|
||||
|
||||
} // updatePhysics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -94,6 +94,8 @@ private:
|
||||
bool m_eliminated;
|
||||
|
||||
SFXBase *m_engine_sound;
|
||||
SFXBase *m_beep_sound;
|
||||
SFXBase *m_crash_sound;
|
||||
|
||||
protected:
|
||||
float m_rescue_pitch, m_rescue_roll;
|
||||
@ -216,6 +218,7 @@ public:
|
||||
|
||||
virtual void update (float dt);
|
||||
virtual void raceFinished (float time);
|
||||
void beep ();
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,8 +43,6 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position, Player *playe
|
||||
m_camera->setMode(Camera::CM_NORMAL);
|
||||
|
||||
m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT );
|
||||
m_beep_sound = sfx_manager->newSFX(SFXManager::SOUND_BEEP );
|
||||
m_crash_sound = sfx_manager->newSFX(SFXManager::SOUND_CRASH);
|
||||
m_wee_sound = sfx_manager->newSFX(SFXManager::SOUND_WEE );
|
||||
m_ugh_sound = sfx_manager->newSFX(SFXManager::SOUND_UGH );
|
||||
m_grab_sound = sfx_manager->newSFX(SFXManager::SOUND_GRAB );
|
||||
@ -57,8 +55,6 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position, Player *playe
|
||||
PlayerKart::~PlayerKart()
|
||||
{
|
||||
sfx_manager->deleteSFX(m_bzzt_sound);
|
||||
sfx_manager->deleteSFX(m_beep_sound);
|
||||
sfx_manager->deleteSFX(m_crash_sound);
|
||||
sfx_manager->deleteSFX(m_wee_sound);
|
||||
sfx_manager->deleteSFX(m_ugh_sound);
|
||||
sfx_manager->deleteSFX(m_grab_sound);
|
||||
@ -77,7 +73,6 @@ void PlayerKart::reset()
|
||||
m_controls.wheelie = false;
|
||||
m_controls.jump = false;
|
||||
m_penalty_time = 0;
|
||||
m_time_last_crash_sound = -10.0f;
|
||||
Kart::reset();
|
||||
m_camera->reset();
|
||||
} // reset
|
||||
@ -176,6 +171,13 @@ void PlayerKart::update(float dt)
|
||||
if(!history->replayHistory())
|
||||
steer(dt, m_steer_val);
|
||||
|
||||
//position the generic sounds at the kart's position
|
||||
m_bzzt_sound->position(getXYZ());
|
||||
m_wee_sound->position(getXYZ());
|
||||
m_ugh_sound->position(getXYZ());
|
||||
m_grab_sound->position(getXYZ());
|
||||
m_full_sound->position(getXYZ());
|
||||
|
||||
if(RaceManager::getWorld()->isStartPhase())
|
||||
{
|
||||
if(m_controls.accel!=0.0 || m_controls.brake!=false ||
|
||||
@ -207,7 +209,7 @@ void PlayerKart::update(float dt)
|
||||
if ( m_controls.fire && !isRescue())
|
||||
{
|
||||
if (m_collectable.getType()==COLLECT_NOTHING)
|
||||
m_beep_sound->play();
|
||||
Kart::beep();
|
||||
}
|
||||
|
||||
// We can't restrict rescue to fulfil isOnGround() (which would be more like
|
||||
@ -215,7 +217,7 @@ void PlayerKart::update(float dt)
|
||||
// up sitting on a brick wall, with all wheels in the air :((
|
||||
if ( m_controls.rescue )
|
||||
{
|
||||
m_beep_sound->play();
|
||||
//m_beep_sound->play();
|
||||
forceRescue();
|
||||
m_controls.rescue=false;
|
||||
}
|
||||
@ -233,17 +235,6 @@ void PlayerKart::update(float dt)
|
||||
void PlayerKart::crashed(Kart *kart)
|
||||
{
|
||||
Kart::crashed(kart);
|
||||
// A collision is usually reported several times, even when hitting
|
||||
// something only once. This results in a kind of 'machine gun'
|
||||
// noise by playing the crash sound over and over again. To prevent
|
||||
// this, the crash sound is only played if there was at least 0.5
|
||||
// seconds since the last time it was played (for this kart)
|
||||
|
||||
if(RaceManager::getWorld()->getTime() - m_time_last_crash_sound > 0.5f)
|
||||
{
|
||||
m_crash_sound->play();
|
||||
m_time_last_crash_sound = RaceManager::getWorld()->getTime();
|
||||
}
|
||||
} // crashed
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -253,7 +244,17 @@ void PlayerKart::setPosition(int p)
|
||||
{
|
||||
if(getPosition()<p)
|
||||
{
|
||||
m_beep_sound->play();
|
||||
//have the kart that did the passing beep.
|
||||
//I'm not sure if this method of finding the passing kart is fail-safe.
|
||||
for(unsigned int i = 0 ; i < race_manager->getNumKarts(); i++ )
|
||||
{
|
||||
Kart *kart = RaceManager::getWorld()->getKart(i);
|
||||
if(kart->getPosition() == p + 1)
|
||||
{
|
||||
kart->beep();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Kart::setPosition(p);
|
||||
} // setPosition
|
||||
|
@ -38,12 +38,9 @@ private:
|
||||
|
||||
Player *m_player;
|
||||
float m_penalty_time;
|
||||
float m_time_last_crash_sound;
|
||||
Camera *m_camera;
|
||||
|
||||
SFXBase *m_bzzt_sound;
|
||||
SFXBase *m_beep_sound;
|
||||
SFXBase *m_crash_sound;
|
||||
SFXBase *m_wee_sound;
|
||||
SFXBase *m_ugh_sound;
|
||||
SFXBase *m_grab_sound;
|
||||
|
@ -184,7 +184,7 @@ void Scene::draw(float dt)
|
||||
0.0f, 0.0f, 1.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
for (World::Karts::size_type i = 0 ; i < race_manager->getNumKarts(); ++i)
|
||||
for (int i = 0 ; i < race_manager->getNumKarts(); ++i)
|
||||
{
|
||||
Kart *kart=RaceManager::getKart((int)i);
|
||||
if(!kart->isEliminated()) kart->draw();
|
||||
|
Loading…
Reference in New Issue
Block a user