Allow custom skid sound for newly exported karts
This commit is contained in:
parent
0a97efc37c
commit
48b73520f0
@ -180,7 +180,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
|
||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||
m_emitters[i] = SFXManager::get()->createSoundSource("crash");
|
||||
|
||||
m_skid_sound = SFXManager::get()->createSoundSource( "skid" );
|
||||
m_skid_sound = NULL;
|
||||
m_nitro_sound = SFXManager::get()->createSoundSource( "nitro" );
|
||||
m_terrain_sound = NULL;
|
||||
m_last_sound_material = NULL;
|
||||
@ -196,29 +196,33 @@ void Kart::init(RaceManager::KartType type)
|
||||
{
|
||||
m_type = type;
|
||||
|
||||
if (!m_engine_sound)
|
||||
Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!");
|
||||
|
||||
loadData(type, UserConfigParams::m_animated_characters);
|
||||
// m_skid_sound is loaded in loadData
|
||||
initSound();
|
||||
reset();
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Kart::initSound()
|
||||
{
|
||||
// In multiplayer mode, sounds are NOT positional
|
||||
if (RaceManager::get()->getNumLocalPlayers() > 1)
|
||||
{
|
||||
float factor = 1.0f / RaceManager::get()->getNumberOfKarts();
|
||||
// players have louder sounds than AIs
|
||||
if (type == RaceManager::KT_PLAYER)
|
||||
if (m_type == RaceManager::KT_PLAYER)
|
||||
factor = std::min(1.0f, RaceManager::get()->getNumLocalPlayers()/2.0f);
|
||||
|
||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||
m_emitters[i]->setVolume(factor);
|
||||
|
||||
m_skid_sound->setVolume(factor);
|
||||
if (m_skid_sound)
|
||||
m_skid_sound->setVolume(factor);
|
||||
m_nitro_sound->setVolume(factor);
|
||||
} // if getNumLocalPlayers > 1
|
||||
|
||||
if(!m_engine_sound)
|
||||
{
|
||||
Log::error("Kart","Could not allocate a sfx object for the kart. Further errors may ensue!");
|
||||
}
|
||||
|
||||
loadData(type, UserConfigParams::m_animated_characters);
|
||||
reset();
|
||||
} // init
|
||||
} // initSound
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Kart::changeKart(const std::string& new_ident,
|
||||
@ -230,6 +234,7 @@ void Kart::changeKart(const std::string& new_ident,
|
||||
|
||||
scene::ISceneNode* old_node = m_node;
|
||||
loadData(m_type, UserConfigParams::m_animated_characters);
|
||||
initSound();
|
||||
m_wheel_box = NULL;
|
||||
|
||||
if (LocalPlayerController* lpc =
|
||||
@ -270,7 +275,8 @@ Kart::~Kart()
|
||||
}*/
|
||||
|
||||
m_engine_sound->deleteSFX();
|
||||
m_skid_sound ->deleteSFX();
|
||||
if (m_skid_sound)
|
||||
m_skid_sound->deleteSFX();
|
||||
|
||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||
m_emitters[i]->deleteSFX();
|
||||
@ -2606,10 +2612,10 @@ void Kart::updatePhysics(int ticks)
|
||||
m_skidding->getSkidState() == Skidding::SKID_ACCUMULATE_RIGHT ) &&
|
||||
!m_skidding->isJumping() )
|
||||
{
|
||||
if(m_skid_sound->getStatus()!=SFXBase::SFX_PLAYING && !isWheeless())
|
||||
if(m_skid_sound && m_skid_sound->getStatus()!=SFXBase::SFX_PLAYING)
|
||||
m_skid_sound->play(getSmoothedXYZ());
|
||||
}
|
||||
else if(m_skid_sound->getStatus()==SFXBase::SFX_PLAYING)
|
||||
else if(m_skid_sound && m_skid_sound->getStatus()==SFXBase::SFX_PLAYING)
|
||||
{
|
||||
m_skid_sound->stop();
|
||||
}
|
||||
@ -3010,6 +3016,17 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
|
||||
if (!GUIEngine::isNoGraphics())
|
||||
m_stars_effect.reset(new Stars(this));
|
||||
|
||||
// Clear previous skid sound if exists
|
||||
if (m_skid_sound)
|
||||
{
|
||||
m_skid_sound->deleteSFX();
|
||||
m_skid_sound = NULL;
|
||||
}
|
||||
if (!m_kart_properties->getSkidSound().empty())
|
||||
{
|
||||
m_skid_sound = SFXManager::get()->createSoundSource(
|
||||
m_kart_properties->getSkidSound());
|
||||
}
|
||||
} // loadData
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -3220,7 +3237,8 @@ void Kart::updateGraphics(float dt)
|
||||
|
||||
for (int i = 0; i < EMITTER_COUNT; i++)
|
||||
m_emitters[i]->setPosition(getXYZ());
|
||||
m_skid_sound->setPosition(getSmoothedXYZ());
|
||||
if (m_skid_sound)
|
||||
m_skid_sound->setPosition(getSmoothedXYZ());
|
||||
m_nitro_sound->setPosition(getSmoothedXYZ());
|
||||
|
||||
m_attachment->updateGraphics(dt);
|
||||
|
@ -289,6 +289,7 @@ protected:
|
||||
void playCrashSFX(const Material* m, AbstractKart *k);
|
||||
void loadData(RaceManager::KartType type, bool animatedModel);
|
||||
void updateWeight();
|
||||
void initSound();
|
||||
public:
|
||||
Kart(const std::string& ident, unsigned int world_kart_id,
|
||||
int position, const btTransform& init_transform,
|
||||
|
@ -449,6 +449,7 @@ public:
|
||||
getInverseBoneMatrix(const std::string& bone_name) const;
|
||||
// ------------------------------------------------------------------------
|
||||
const std::string& getExhaustXML() const { return m_exhaust_xml; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
bool hasWheel() const { return !m_wheel_filename[0].empty(); }
|
||||
}; // KartModel
|
||||
#endif
|
||||
|
@ -473,9 +473,36 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
//TODO: listed as an attribute in the xml file after wheel-radius
|
||||
//TODO: same goes for their rear equivalents
|
||||
|
||||
|
||||
bool fallback_skid_sound = true;
|
||||
if(const XMLNode *sounds_node= root->getNode("sounds"))
|
||||
{
|
||||
std::string custom_skid_sound;
|
||||
// Newly exported kart: custom skid sound
|
||||
if (const XMLNode* skid_node = sounds_node->getNode("skid"))
|
||||
{
|
||||
skid_node->get("name", &custom_skid_sound);
|
||||
std::string full_path = m_root + custom_skid_sound;
|
||||
if (file_manager->fileExists(full_path) &&
|
||||
StringUtils::getExtension(custom_skid_sound) == "ogg")
|
||||
{
|
||||
m_skid_sound = m_ident + "_skid";
|
||||
// Default values for skid sound option if not found
|
||||
float rolloff = 0.5;
|
||||
float max_dist = 300.0f;
|
||||
float gain = 1.0;
|
||||
skid_node->get("rolloff", &rolloff);
|
||||
skid_node->get("max_dist", &max_dist);
|
||||
skid_node->get("volume", &gain);
|
||||
SFXManager::get()->addSingleSfx(m_skid_sound, full_path,
|
||||
true/*positional*/, rolloff, max_dist, gain);
|
||||
}
|
||||
else if (custom_skid_sound == "default")
|
||||
{
|
||||
// Default skid sound
|
||||
m_skid_sound = "skid";
|
||||
}
|
||||
fallback_skid_sound = false;
|
||||
}
|
||||
std::string s;
|
||||
sounds_node->get("engine", &s);
|
||||
if (s == "custom")
|
||||
@ -547,6 +574,13 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
|
||||
if(m_kart_model)
|
||||
m_kart_model->loadInfo(*root);
|
||||
// For fallback skid sound found in old exported kart, give skid sound for
|
||||
// karts having wheel
|
||||
if (fallback_skid_sound)
|
||||
{
|
||||
if (m_kart_model && m_kart_model->hasWheel())
|
||||
m_skid_sound = "skid";
|
||||
}
|
||||
} // getAllData
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -170,6 +170,8 @@ private:
|
||||
/** Engine sound effect. */
|
||||
std::string m_engine_sfx_type;
|
||||
|
||||
std::string m_skid_sound;
|
||||
|
||||
// bullet physics data
|
||||
// -------------------
|
||||
float m_friction_slip;
|
||||
@ -294,6 +296,9 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the engine type (used to change sfx depending on kart size). */
|
||||
const std::string& getEngineSfxType () const {return m_engine_sfx_type;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the skid sound */
|
||||
const std::string& getSkidSound () const {return m_skid_sound; }
|
||||
|
||||
// Bullet physics get functions
|
||||
//-----------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user