fix feedback offroad #2761 (#2806)

* Fix updateenginesfx

smooth engine sound and fix https://github.com/supertuxkart/stk-code/issues/2761

* update enginesfx

* remove m_last_max_speed useless

* forgot : float max_speed

* Add missing space around =

* add space around = m_last_factor_engine_sound
This commit is contained in:
rogue-spectre 2017-03-11 15:04:38 +01:00 committed by auriamg
parent 62d64847c4
commit d33d72dfb8
2 changed files with 29 additions and 14 deletions

View File

@ -153,6 +153,7 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
m_reset_transform = init_transform; m_reset_transform = init_transform;
m_speed = 0.0f; m_speed = 0.0f;
m_smoothed_speed = 0.0f; m_smoothed_speed = 0.0f;
m_last_factor_engine_sound = 0.0f;
m_kart_model->setKart(this); m_kart_model->setKart(this);
@ -1375,6 +1376,7 @@ void Kart::update(float dt)
fabs(getSpeed()) < 3.0f) fabs(getSpeed()) < 3.0f)
{ {
new RescueAnimation(this, /*is_auto_rescue*/true); new RescueAnimation(this, /*is_auto_rescue*/true);
m_last_factor_engine_sound = 0.0f;
} }
} }
@ -1439,7 +1441,10 @@ void Kart::update(float dt)
if((min->getY() - getXYZ().getY() > 17 || dist_to_sector > 25) && !m_flying && if((min->getY() - getXYZ().getY() > 17 || dist_to_sector > 25) && !m_flying &&
!getKartAnimation()) !getKartAnimation())
{
new RescueAnimation(this); new RescueAnimation(this);
m_last_factor_engine_sound = 0.0f;
}
} }
else else
{ {
@ -1458,7 +1463,10 @@ void Kart::update(float dt)
} // if !flying } // if !flying
handleMaterialSFX(material); handleMaterialSFX(material);
if (material->isDriveReset() && isOnGround()) if (material->isDriveReset() && isOnGround())
{
new RescueAnimation(this); new RescueAnimation(this);
m_last_factor_engine_sound = 0.0f;
}
else if(material->isZipper() && isOnGround()) else if(material->isZipper() && isOnGround())
{ {
handleZipper(material); handleZipper(material);
@ -2094,6 +2102,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
if (m->getCollisionReaction() == Material::RESCUE) if (m->getCollisionReaction() == Material::RESCUE)
{ {
new RescueAnimation(this); new RescueAnimation(this);
m_last_factor_engine_sound = 0.0f;
} }
else if (m->getCollisionReaction() == Material::PUSH_BACK) else if (m->getCollisionReaction() == Material::PUSH_BACK)
{ {
@ -2285,7 +2294,7 @@ void Kart::updatePhysics(float dt)
m_max_speed->update(dt); m_max_speed->update(dt);
updateEngineSFX(); updateEngineSFX(dt);
#ifdef XX #ifdef XX
Log::info("Kart","angVel %f %f %f heading %f suspension %f %f %f %f" Log::info("Kart","angVel %f %f %f heading %f suspension %f %f %f %f"
,m_body->getAngularVelocity().getX() ,m_body->getAngularVelocity().getX()
@ -2304,7 +2313,7 @@ void Kart::updatePhysics(float dt)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Adjust the engine sound effect depending on the speed of the kart. /** Adjust the engine sound effect depending on the speed of the kart.
*/ */
void Kart::updateEngineSFX() void Kart::updateEngineSFX(float dt)
{ {
// when going faster, use higher pitch for engine // when going faster, use higher pitch for engine
if(!m_engine_sound || !SFXManager::get()->sfxAllowed()) if(!m_engine_sound || !SFXManager::get()->sfxAllowed())
@ -2312,7 +2321,7 @@ void Kart::updateEngineSFX()
if(isOnGround()) if(isOnGround())
{ {
float max_speed = m_max_speed->getCurrentMaxSpeed(); float max_speed = m_kart_properties->getEngineMaxSpeed();
// Engine noise is based half in total speed, half in fake gears: // Engine noise is based half in total speed, half in fake gears:
// With a sawtooth graph like /|/|/| we get 3 even spaced gears, // With a sawtooth graph like /|/|/| we get 3 even spaced gears,
@ -2320,20 +2329,23 @@ void Kart::updateEngineSFX()
// good enough brrrBRRRbrrrBRRR sound effect. Speed factor makes // good enough brrrBRRRbrrrBRRR sound effect. Speed factor makes
// it a "staired sawtooth", so more acoustically rich. // it a "staired sawtooth", so more acoustically rich.
float f = max_speed > 0 ? m_speed/max_speed : 1.0f; float f = max_speed > 0 ? m_speed/max_speed : 1.0f;
// Speed at this stage is not yet capped, so it can be > 1, which // Speed at this stage is not yet capped, reduce the amount beyond 1
// results in odd engine sfx. if (f> 1.0f) f = 1.0f + (1.0f-1.0f/f);
if (f>1.0f) f=1.0f;
float gears = 3.0f * fmod(f, 0.333334f); float fc = f;
if (fc>1.0f) fc = 1.0f;
float gears = 3.0f * fmod(fc, 0.333334f);
assert(!std::isnan(f)); assert(!std::isnan(f));
m_engine_sound->setSpeedPosition(0.6f + (f + gears) * 0.35f, getXYZ()); m_last_factor_engine_sound = (0.9*f + gears) * 0.35f;
m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ());
} }
else else
{ {
// When flying, fixed value but not too high pitch // When flying, reduce progressively the sound engine (since we can't accelerate)
// This gives some variation (vs previous "on wheels" one) m_last_factor_engine_sound *= (1.0f-0.1*dt);
m_engine_sound->setSpeedPosition(0.9f, getXYZ()); m_engine_sound->setSpeedPosition(0.6f + m_last_factor_engine_sound, getXYZ());
} if (m_speed < 0.1f) m_last_factor_engine_sound = 0.0f;
}
} // updateEngineSFX } // updateEngineSFX
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -201,6 +201,9 @@ protected:
/** For camera handling an exponentially smoothened value is used, which /** For camera handling an exponentially smoothened value is used, which
* reduces stuttering of the camera. */ * reduces stuttering of the camera. */
float m_smoothed_speed; float m_smoothed_speed;
/** For smoothing engine sound**/
float m_last_factor_engine_sound;
std::vector<SFXBase*> m_custom_sounds; std::vector<SFXBase*> m_custom_sounds;
SFXBase *m_beep_sound; SFXBase *m_beep_sound;
@ -226,7 +229,7 @@ protected:
void updateFlying(); void updateFlying();
void updateSliding(); void updateSliding();
void updateEnginePowerAndBrakes(float dt); void updateEnginePowerAndBrakes(float dt);
void updateEngineSFX(); void updateEngineSFX(float dt);
void updateSpeed(); void updateSpeed();
void updateNitro(float dt); void updateNitro(float dt);
float getActualWheelForce(); float getActualWheelForce();