Continue optimizing OpenAL sources, see #2921

This commit is contained in:
auria.mg 2017-09-02 22:49:36 -04:00
parent cb2295c738
commit beb10863c4
5 changed files with 33 additions and 24 deletions

View File

@ -45,6 +45,7 @@ class KartModel;
class KartProperties; class KartProperties;
class Material; class Material;
class Powerup; class Powerup;
class SFXBuffer;
class Skidding; class Skidding;
class SlipStream; class SlipStream;
class TerrainInfo; class TerrainInfo;
@ -472,7 +473,8 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns whether this kart is jumping. */ /** Returns whether this kart is jumping. */
virtual bool isJumping() const = 0; virtual bool isJumping() const = 0;
// ------------------------------------------------------------------------
virtual void playSound(SFXBuffer* buffer) = 0;
}; // AbstractKart }; // AbstractKart

View File

@ -65,11 +65,11 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart,
// the right camera once per frame later. // the right camera once per frame later.
Camera *camera = Camera::createCamera(kart); Camera *camera = Camera::createCamera(kart);
m_camera_index = camera->getIndex(); m_camera_index = camera->getIndex();
m_bzzt_sound = SFXManager::get()->createSoundSource("bzzt");
m_wee_sound = SFXManager::get()->createSoundSource("wee"); m_wee_sound = SFXManager::get()->createSoundSource("wee");
m_ugh_sound = SFXManager::get()->createSoundSource("ugh"); m_bzzt_sound = SFXManager::get()->getBuffer("bzzt");
m_grab_sound = SFXManager::get()->createSoundSource("grab_collectable"); m_ugh_sound = SFXManager::get()->getBuffer("ugh");
m_full_sound = SFXManager::get()->createSoundSource("energy_bar_full"); m_grab_sound = SFXManager::get()->getBuffer("grab_collectable");
m_full_sound = SFXManager::get()->getBuffer("energy_bar_full");
// Attach Particle System // Attach Particle System
Track *track = Track::getCurrentTrack(); Track *track = Track::getCurrentTrack();
@ -97,11 +97,8 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart,
*/ */
LocalPlayerController::~LocalPlayerController() LocalPlayerController::~LocalPlayerController()
{ {
m_bzzt_sound->deleteSFX(); m_wee_sound->deleteSFX();
m_wee_sound ->deleteSFX();
m_ugh_sound ->deleteSFX();
m_grab_sound->deleteSFX();
m_full_sound->deleteSFX();
if (m_sky_particles_emitter) if (m_sky_particles_emitter)
delete m_sky_particles_emitter; delete m_sky_particles_emitter;
} // ~LocalPlayerController } // ~LocalPlayerController
@ -228,7 +225,7 @@ void LocalPlayerController::update(float dt)
else if (!m_kart->getKartAnimation() && m_sound_schedule == true) else if (!m_kart->getKartAnimation() && m_sound_schedule == true)
{ {
m_sound_schedule = false; m_sound_schedule = false;
m_bzzt_sound->play(); m_kart->playSound(m_bzzt_sound);
} }
} // update } // update
@ -246,7 +243,7 @@ void LocalPlayerController::displayPenaltyWarning()
m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f, m->addMessage(_("Don't accelerate before go"), m_kart, 2.0f,
GUIEngine::getSkin()->getColor("font::normal")); GUIEngine::getSkin()->getColor("font::normal"));
} }
m_bzzt_sound->play(); m_kart->playSound(m_bzzt_sound);
} // displayPenaltyWarning } // displayPenaltyWarning
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -326,31 +323,31 @@ void LocalPlayerController::collectedItem(const Item &item, int add_info,
if (old_energy < m_kart->getKartProperties()->getNitroMax() && if (old_energy < m_kart->getKartProperties()->getNitroMax() &&
m_kart->getEnergy() == 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 && else if (race_manager->getCoinTarget() > 0 &&
old_energy < race_manager->getCoinTarget() && old_energy < race_manager->getCoinTarget() &&
m_kart->getEnergy() == race_manager->getCoinTarget()) m_kart->getEnergy() == race_manager->getCoinTarget())
{ {
m_full_sound->play(); m_kart->playSound(m_full_sound);
} }
else else
{ {
switch(item.getType()) switch(item.getType())
{ {
case Item::ITEM_BANANA: case Item::ITEM_BANANA:
m_ugh_sound->play(); m_kart->playSound(m_ugh_sound);
break; break;
case Item::ITEM_BUBBLEGUM: case Item::ITEM_BUBBLEGUM:
//More sounds are played by the kart class //More sounds are played by the kart class
//See Kart::collectedItem() //See Kart::collectedItem()
m_ugh_sound->play(); m_kart->playSound(m_ugh_sound);
break; break;
case Item::ITEM_TRIGGER: case Item::ITEM_TRIGGER:
// no default sound for triggers // no default sound for triggers
break; break;
default: default:
m_grab_sound->play(); m_kart->playSound(m_grab_sound);
break; break;
} }
} }

View File

@ -26,6 +26,7 @@
class AbstractKart; class AbstractKart;
class ParticleEmitter; class ParticleEmitter;
class SFXBase; class SFXBase;
class SFXBuffer;
/** PlayerKart manages control events from the player and moves /** PlayerKart manages control events from the player and moves
* them to the Kart * them to the Kart
@ -47,11 +48,11 @@ private:
* camera object is managed in the Camera class, so no need to free it. */ * camera object is managed in the Camera class, so no need to free it. */
int m_camera_index; int m_camera_index;
SFXBase *m_bzzt_sound; SFXBase *m_wee_sound;
SFXBase *m_wee_sound; SFXBuffer *m_bzzt_sound;
SFXBase *m_ugh_sound; SFXBuffer *m_ugh_sound;
SFXBase *m_grab_sound; SFXBuffer *m_grab_sound;
SFXBase *m_full_sound; SFXBuffer *m_full_sound;
virtual void steer(float, int) OVERRIDE; virtual void steer(float, int) OVERRIDE;
virtual void displayPenaltyWarning() OVERRIDE; virtual void displayPenaltyWarning() OVERRIDE;

View File

@ -2994,4 +2994,11 @@ const Vec3& Kart::getNormal() const
return m_terrain_info->getNormal(); return m_terrain_info->getNormal();
} // getNormal } // getNormal
// ------------------------------------------------------------------------
void Kart::playSound(SFXBuffer* buffer)
{
getNextEmitter()->play(getXYZ(), buffer);
}
/* EOF */ /* EOF */

View File

@ -241,7 +241,6 @@ protected:
float getActualWheelForce(); float getActualWheelForce();
void playCrashSFX(const Material* m, AbstractKart *k); void playCrashSFX(const Material* m, AbstractKart *k);
void loadData(RaceManager::KartType type, bool animatedModel); void loadData(RaceManager::KartType type, bool animatedModel);
SFXBase* getNextEmitter();
public: public:
Kart(const std::string& ident, unsigned int world_kart_id, Kart(const std::string& ident, unsigned int world_kart_id,
@ -478,7 +477,10 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns whether this kart is jumping. */ /** Returns whether this kart is jumping. */
virtual bool isJumping() const { return m_is_jumping; }; virtual bool isJumping() const { return m_is_jumping; };
// ------------------------------------------------------------------------
SFXBase* getNextEmitter();
// ------------------------------------------------------------------------
virtual void playSound(SFXBuffer* buffer);
}; // Kart }; // Kart