SuperTuxKart
|
Classes | |
class | SpeedDecrease |
An internal class to store and handle speed decrease related data. More... | |
class | SpeedIncrease |
An internal class to store and handle speed increase related data. More... | |
Public Member Functions | |
MaxSpeed (AbstractKart *kart) | |
This class handles maximum speed for karts. | |
void | increaseMaxSpeed (unsigned int category, float add_speed, float engine_force, int duration, int fade_out_time) |
Sets an increased maximum speed for a category. | |
void | instantSpeedIncrease (unsigned int category, float add_speed, float speed_boost, float engine_force, int duration, int fade_out_time) |
This adjusts the top speed using increaseMaxSpeed, but additionally causes an instant speed boost, which can be smaller than add-max-speed. | |
void | setSlowdown (unsigned int category, float max_speed_fraction, int fade_in_time, int duration=-1) |
Defines a slowdown, which is in fraction of top speed. | |
int | getSpeedIncreaseTicksLeft (unsigned int category) |
Returns how much increased speed time is left over in the given category. | |
int | isSpeedIncreaseActive (unsigned int category) |
Returns if increased speed is active in the given category. | |
int | isSpeedDecreaseActive (unsigned int category) |
Returns if decreased speed is active in the given category. | |
void | update (int ticks) |
Updates all speed increase and decrease objects, and determines the current maximum speed. | |
void | reset () |
Reset to prepare for a restart. | |
void | saveState (BareNetworkString *buffer) const |
Saves the speed data in a network string for rewind. | |
void | rewindTo (BareNetworkString *buffer) |
Restore a saved state. | |
void | setMinSpeed (float s) |
Sets the minimum speed a kart should have. | |
float | getCurrentMaxSpeed () const |
Returns the current maximum speed for this kart. | |
float | getCurrentAdditionalEngineForce () const |
Returns the additional engine force. | |
Private Attributes | |
AbstractKart * | m_kart |
A pointer to the kart to which this speed handling object belongs. | |
float | m_current_max_speed |
The current maximum speed. | |
float | m_add_engine_force |
Additional engine force, summed from all SpeedIncrease engine forces. | |
float | m_min_speed |
If >0 then the minimum speed a kart should have (used for zippers). | |
SpeedDecrease | m_speed_decrease [MS_DECREASE_MAX] |
Stores all speed decrease related information for each possible category. | |
SpeedIncrease | m_speed_increase [MS_INCREASE_MAX] |
Stores all speed increase related information for each possible category. | |
Friends | |
class | KartRewinder |
MaxSpeed::MaxSpeed | ( | AbstractKart * | kart | ) |
This class handles maximum speed for karts.
Several factors can influence the maximum speed a kart can drive, some will decrease the maximum speed, some will increase the maximum speed. Slowdowns are specified in fraction of the (kart specific) maximum speed of that kart. The following categories are defined:
int MaxSpeed::getSpeedIncreaseTicksLeft | ( | unsigned int | category | ) |
Returns how much increased speed time is left over in the given category.
category | Which category to report on. |
void MaxSpeed::increaseMaxSpeed | ( | unsigned int | category, |
float | add_speed, | ||
float | engine_force, | ||
int | duration, | ||
int | fade_out_time | ||
) |
Sets an increased maximum speed for a category.
category | The category for which to set the higher maximum speed. |
add_speed | How much speed (in m/s) is added to the maximum speed. |
duration | How long the speed increase will last. |
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 | engine_force, | ||
int | duration, | ||
int | fade_out_time | ||
) |
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
category | The category for which the speed is increased. |
add_max_speed | Increase of the maximum allowed speed. |
speed_boost | An instant speed increase for this kart. |
engine_force | Additional engine force. |
duration | Duration of the increased speed. |
fade_out_time | How long the maximum speed will fade out linearly. |
int MaxSpeed::isSpeedDecreaseActive | ( | unsigned int | category | ) |
Returns if decreased speed is active in the given category.
category | Which category to report on. |
int MaxSpeed::isSpeedIncreaseActive | ( | unsigned int | category | ) |
Returns if increased speed is active in the given category.
category | Which category to report on. |
void MaxSpeed::reset | ( | ) |
Reset to prepare for a restart.
It just overwrites each entry with a newly constructed values, i.e. values that don't cause any slowdown or speedup.
void MaxSpeed::rewindTo | ( | BareNetworkString * | buffer | ) |
Restore a saved state.
buffer | Saved state. |
void MaxSpeed::saveState | ( | BareNetworkString * | buffer | ) | const |
Saves the speed data in a network string for rewind.
buffer | Pointer to the network string to store the data. |
|
inline |
Sets the minimum speed a kart should have.
This is used to guarantee that e.g. zippers on ramps will always fast enough for the karts to reach the other end. If set to a negative number, it will have no effect.
void MaxSpeed::setSlowdown | ( | unsigned int | category, |
float | max_speed_fraction, | ||
int | fade_in_ticks, | ||
int | duration = -1 |
||
) |
Defines a slowdown, which is in fraction of top speed.
category | The category for which the speed is increased. |
max_speed_fraction | Fraction of top speed to allow only. |
fade_in_time | How long till maximum speed is capped. |
duration | How long the effect will lasts. The value of -1 (default) indicates that this effect stays active forever (i.e. till its value is changed to something else). |
void MaxSpeed::update | ( | int | ticks | ) |
Updates all speed increase and decrease objects, and determines the current maximum speed.
Note that the function can be called with dt=0, in which case the maximum speed will be updated, but no change to any of the speed increase/decrease objects will be done.
dt | Time step size (dt=0 only updates the current maximum speed). |