diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index 71582aa4b..5bab9703c 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -45,6 +45,7 @@ class KartModel; class KartProperties; class Material; class Powerup; +class SFXBuffer; class Skidding; class SlipStream; class TerrainInfo; @@ -472,7 +473,8 @@ public: // ------------------------------------------------------------------------ /** Returns whether this kart is jumping. */ virtual bool isJumping() const = 0; - + // ------------------------------------------------------------------------ + virtual void playSound(SFXBuffer* buffer) = 0; }; // AbstractKart diff --git a/src/karts/controller/local_player_controller.cpp b/src/karts/controller/local_player_controller.cpp index 01eb0879f..2c8b96b47 100644 --- a/src/karts/controller/local_player_controller.cpp +++ b/src/karts/controller/local_player_controller.cpp @@ -65,11 +65,11 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart, // the right camera once per frame later. Camera *camera = Camera::createCamera(kart); m_camera_index = camera->getIndex(); - m_bzzt_sound = SFXManager::get()->createSoundSource("bzzt"); m_wee_sound = SFXManager::get()->createSoundSource("wee"); - m_ugh_sound = SFXManager::get()->createSoundSource("ugh"); - m_grab_sound = SFXManager::get()->createSoundSource("grab_collectable"); - m_full_sound = SFXManager::get()->createSoundSource("energy_bar_full"); + m_bzzt_sound = SFXManager::get()->getBuffer("bzzt"); + m_ugh_sound = SFXManager::get()->getBuffer("ugh"); + m_grab_sound = SFXManager::get()->getBuffer("grab_collectable"); + m_full_sound = SFXManager::get()->getBuffer("energy_bar_full"); // Attach Particle System Track *track = Track::getCurrentTrack(); @@ -97,11 +97,8 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart, */ LocalPlayerController::~LocalPlayerController() { - m_bzzt_sound->deleteSFX(); - m_wee_sound ->deleteSFX(); - m_ugh_sound ->deleteSFX(); - m_grab_sound->deleteSFX(); - m_full_sound->deleteSFX(); + m_wee_sound->deleteSFX(); + if (m_sky_particles_emitter) delete m_sky_particles_emitter; } // ~LocalPlayerController @@ -228,7 +225,7 @@ void LocalPlayerController::update(float dt) else if (!m_kart->getKartAnimation() && m_sound_schedule == true) { m_sound_schedule = false; - m_bzzt_sound->play(); + m_kart->playSound(m_bzzt_sound); } } // update @@ -246,7 +243,7 @@ void LocalPlayerController::displayPenaltyWarning() m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f, GUIEngine::getSkin()->getColor("font::normal")); } - m_bzzt_sound->play(); + m_kart->playSound(m_bzzt_sound); } // displayPenaltyWarning //----------------------------------------------------------------------------- @@ -326,31 +323,31 @@ void LocalPlayerController::collectedItem(const Item &item, int add_info, if (old_energy < m_kart->getKartProperties()->getNitroMax() && m_kart->getEnergy() == m_kart->getKartProperties()->getNitroMax()) { - m_full_sound->play(); + m_kart->playSound(m_full_sound); } else if (race_manager->getCoinTarget() > 0 && old_energy < race_manager->getCoinTarget() && m_kart->getEnergy() == race_manager->getCoinTarget()) { - m_full_sound->play(); + m_kart->playSound(m_full_sound); } else { switch(item.getType()) { case Item::ITEM_BANANA: - m_ugh_sound->play(); + m_kart->playSound(m_ugh_sound); break; case Item::ITEM_BUBBLEGUM: //More sounds are played by the kart class //See Kart::collectedItem() - m_ugh_sound->play(); + m_kart->playSound(m_ugh_sound); break; case Item::ITEM_TRIGGER: // no default sound for triggers break; default: - m_grab_sound->play(); + m_kart->playSound(m_grab_sound); break; } } diff --git a/src/karts/controller/local_player_controller.hpp b/src/karts/controller/local_player_controller.hpp index 5493e1b2d..fbe327030 100644 --- a/src/karts/controller/local_player_controller.hpp +++ b/src/karts/controller/local_player_controller.hpp @@ -26,6 +26,7 @@ class AbstractKart; class ParticleEmitter; class SFXBase; +class SFXBuffer; /** PlayerKart manages control events from the player and moves * them to the Kart @@ -47,11 +48,11 @@ private: * camera object is managed in the Camera class, so no need to free it. */ int m_camera_index; - SFXBase *m_bzzt_sound; - SFXBase *m_wee_sound; - SFXBase *m_ugh_sound; - SFXBase *m_grab_sound; - SFXBase *m_full_sound; + SFXBase *m_wee_sound; + SFXBuffer *m_bzzt_sound; + SFXBuffer *m_ugh_sound; + SFXBuffer *m_grab_sound; + SFXBuffer *m_full_sound; virtual void steer(float, int) OVERRIDE; virtual void displayPenaltyWarning() OVERRIDE; diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 5e20d8a67..a1097cd58 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2994,4 +2994,11 @@ const Vec3& Kart::getNormal() const return m_terrain_info->getNormal(); } // getNormal +// ------------------------------------------------------------------------ + +void Kart::playSound(SFXBuffer* buffer) +{ + getNextEmitter()->play(getXYZ(), buffer); +} + /* EOF */ diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index 6d364bd01..5b7d8902d 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -241,7 +241,6 @@ protected: float getActualWheelForce(); void playCrashSFX(const Material* m, AbstractKart *k); void loadData(RaceManager::KartType type, bool animatedModel); - SFXBase* getNextEmitter(); public: Kart(const std::string& ident, unsigned int world_kart_id, @@ -478,7 +477,10 @@ public: // ------------------------------------------------------------------------ /** Returns whether this kart is jumping. */ virtual bool isJumping() const { return m_is_jumping; }; - + // ------------------------------------------------------------------------ + SFXBase* getNextEmitter(); + // ------------------------------------------------------------------------ + virtual void playSound(SFXBuffer* buffer); }; // Kart