diff --git a/data/stk_config.xml b/data/stk_config.xml index 0fd9985a4..f96fafba6 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -183,8 +183,8 @@ which is used to reduce the turn angle used to reduce the turn angle. --> diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 9ebe395ac..b7d67235f 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1338,15 +1338,9 @@ void Kart::handleZipper(const Material *material, bool play_sound) // Ignore a zipper that's activated while braking if(m_controls.m_brake || m_speed<0) return; - MaxSpeed::increaseMaxSpeed(MaxSpeed::MS_INCREASE_ZIPPER, - max_speed_increase, duration, fade_out_time); - // This will result in all max speed settings updated, but no - // changes to any slow downs since dt=0 - MaxSpeed::update(0); - float speed = std::min(m_speed + speed_gain, - MaxSpeed::getCurrentMaxSpeed() ); - - m_vehicle->activateZipper(speed); + MaxSpeed::instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER, + max_speed_increase, speed_gain, + duration, fade_out_time); // Play custom character sound (weee!) playCustomSFX(SFXManager::CUSTOM_ZIPPER); m_controller->handleZipper(play_sound); @@ -1611,10 +1605,9 @@ void Kart::updatePhysics(float dt) { m_has_started = true; float f = m_kart_properties->getStartupBoost(); - if(f>0) - m_vehicle->activateZipper(f); - MaxSpeed::increaseMaxSpeed(MS_INCREASE_ZIPPER, 0.9f*f, - 5.0f, 5.0f); + MaxSpeed::instantSpeedIncrease(MS_INCREASE_ZIPPER, 0.9f*f, + f, /*duration*/5.0f, + /*fade_out_time*/5.0f); } m_bounce_back_time-=dt; diff --git a/src/karts/max_speed.cpp b/src/karts/max_speed.cpp index 8325e263a..12f3bfe8e 100644 --- a/src/karts/max_speed.cpp +++ b/src/karts/max_speed.cpp @@ -22,6 +22,7 @@ #include #include "karts/kart.hpp" +#include "physics/btKart.hpp" /** This class handles maximum speed for karts. Several factors can influence * the maximum speed a kart can drive, some will decrease the maximum speed, @@ -89,6 +90,35 @@ void MaxSpeed::increaseMaxSpeed(unsigned int category, float add_speed, m_speed_increase[category].m_current_speedup = add_speed; } // increaseMaxSpeed +// ---------------------------------------------------------------------------- +/** This adjusts the top speed using increaseMaxSpeed, but additionally + * causes an instant speed boost, which can be smaller than add-max-speed. + * (e.g. a zipper can give an instant boost of 5 m/s, but over time would + * allow the speed to go up by 10 m/s). Note that bullet does not restrict + * speed (e.g. by simulating air resistance), so without capping the speed + * (which is done my this object) the speed would go arbitrary high over time + * \param category The category for which the speed is increased. + * \param add_max_speed Increase of the maximum allowed speed. + * \param speed_boost An instant speed increase for this kart. + * \param duration Duration of the increased speed. + * \param fade_out_time How long the maximum speed will fade out linearly. + */ +void MaxSpeed::instantSpeedIncrease(unsigned int category, + float add_max_speed, float speed_boost, + float duration, float fade_out_time) +{ + increaseMaxSpeed(category, add_max_speed, duration, fade_out_time); + // This will result in all max speed settings updated, but no + // changes to any slow downs since dt=0 + update(0); + float speed = std::min(m_kart->getSpeed()+ speed_boost, + MaxSpeed::getCurrentMaxSpeed() ); + + m_kart->getVehicle()->instantSpeedIncreaseTo(speed); + +} +// instantSpeedIncrease + // ---------------------------------------------------------------------------- /** Handles the update of speed increase objects. The m_duration variable * contains the remaining time - as long as this variable is positive diff --git a/src/karts/max_speed.hpp b/src/karts/max_speed.hpp index f7037fd82..b41e6c264 100644 --- a/src/karts/max_speed.hpp +++ b/src/karts/max_speed.hpp @@ -129,6 +129,9 @@ public: void increaseMaxSpeed(unsigned int category, float add_speed, float duration, float fade_out_time); + void instantSpeedIncrease(unsigned int category, + float add_speed, float speed_boost, + float duration, float fade_out_time=1.0f); void setSlowdown(unsigned int category, float max_speed_fraction, float fade_in_time); float getSpeedIncreaseTimeLeft(unsigned int category); diff --git a/src/karts/skidding.cpp b/src/karts/skidding.cpp index 316a4ae74..9760d0fee 100644 --- a/src/karts/skidding.cpp +++ b/src/karts/skidding.cpp @@ -170,9 +170,9 @@ void Skidding::update(float dt, bool is_on_ground, case SKID_ACCUMULATE_RIGHT: { m_skid_time += dt; - float bonus_time, bonus_force; + float bonus_time, bonus_speed; unsigned int level = getSkidBonus(&bonus_time, - &bonus_force); + &bonus_speed); // If at least level 1 bonus is reached, show appropriate gfx if(level>0) m_kart->getKartGFX()->setSkidLevel(level); // If player stops skidding, trigger bonus, and change state to @@ -192,12 +192,13 @@ void Skidding::update(float dt, bool is_on_ground, m_skid_time = t; if(bonus_time>0) { - m_kart->MaxSpeed::increaseMaxSpeed( - MaxSpeed::MS_INCREASE_SKIDDING, 10, bonus_time, 1); m_kart->getKartGFX() ->setCreationRateRelative(KartGFX::KGFX_SKID, 1.0f); - // FIXME hiker: for now just misuse the zipper code - m_kart->handleZipper(0); + m_kart->MaxSpeed:: + instantSpeedIncrease(MaxSpeed::MS_INCREASE_SKIDDING, + bonus_speed, bonus_speed, + bonus_time, + /*fade-out-time*/ 1.0f); } else m_kart->getKartGFX() diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index 6f9ad9c66..847e37b30 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -909,18 +909,12 @@ void btKart::setSliding(bool active) * specified speed. * \param speed The speed to reach. */ -void btKart::activateZipper(float speed) +void btKart::instantSpeedIncreaseTo(float speed) { m_zipper_active = true; m_zipper_velocity = speed; } // activateZipper -// ---------------------------------------------------------------------------- -void btKart::deactivateZipper() -{ - m_zipper_active = false; -} // deactivateZipper - // ---------------------------------------------------------------------------- //Shorter version of above raycast function. This is used when projecting //vehicles towards the ground at the start of a race diff --git a/src/physics/btKart.hpp b/src/physics/btKart.hpp index 544c771c5..01076fe86 100644 --- a/src/physics/btKart.hpp +++ b/src/physics/btKart.hpp @@ -167,8 +167,7 @@ public: virtual void updateFriction(btScalar timeStep); public: void setSliding(bool active); - void activateZipper(float speed); - void deactivateZipper(); + void instantSpeedIncreaseTo(float speed); bool projectVehicleToSurface(const btVector3& ray, bool translate_vehicle);