SuperTuxKart
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Skidding Class Reference

Public Types

enum  SkidState {
  SKID_NONE, SKID_ACCUMULATE_LEFT, SKID_ACCUMULATE_RIGHT, SKID_SHOW_GFX_LEFT,
  SKID_SHOW_GFX_RIGHT, SKID_BREAK
}
 SKID_NONE: Kart is currently not skidding. More...
 

Public Member Functions

 LEAK_CHECK ()
 
 Skidding (Kart *kart)
 Constructor of the skidding object.
 
void reset ()
 Resets all skidding related values.
 
float updateGraphics (float dt)
 Called once per rendered frame to potentially update the graphical jump height. More...
 
void update (int dt, bool is_on_ground, float steer, KartControl::SkidControl skidding)
 Updates skidding status. More...
 
void saveState (BareNetworkString *buffer)
 Save the skidding state of a kart. More...
 
void rewindTo (BareNetworkString *buffer)
 Restores the skidding state of a kart. More...
 
float getVisualSkidRotation () const
 Determines how much the graphics model of the kart should be rotated additionally (for skidding), depending on how long the kart has been skidding etc. More...
 
float getSkidFactor () const
 Returns the current skid factor in [1, skid_max_for_this_kart]. More...
 
bool isSkidding () const
 Returns true if the kart is skidding. More...
 
float getSteeringFraction ()
 Returns the steering fraction to be used by the physics. More...
 
SkidState getSkidState () const
 Returns the skidding state. More...
 
float getSteeringWhenSkidding (float steering) const
 Returns the steering value necessary to set in KartControls.m_steer in order to actually to steer the specified amount in 'steering'. More...
 
bool getSkidBonusReady () const
 Returns if the kart has skidded long enough to get a skid bonus if it stopped skidding now. More...
 
bool isJumping () const
 
void prepareSmoothing ()
 
void checkSmoothing ()
 

Private Member Functions

unsigned int getSkidBonus (float *bonus_time, float *bonus_speed, float *bonus_force) const
 Determines the bonus time and speed given the currently accumulated m_skid_time. More...
 
float updateSteering (float steer, int ticks)
 Computes the actual steering fraction to be used in the physics, and stores it in m_real_skidding. More...
 

Private Attributes

float m_skid_reduce_turn_delta
 This is m_skid_reduce_turn_max - m_skid_reduce_turn_min. More...
 
float m_real_steering
 This is the actual steering (in fraction of max-steering-angle) to be used by this kart. More...
 
float m_visual_rotation
 An additional rotation (heading) of the kart while skidding. More...
 
float m_skid_factor
 Accumulated skidding factor. More...
 
uint16_t m_skid_time
 Keeps track on how long a kart has been skidding, in order to trigger the skidding bonus. More...
 
bool m_skid_bonus_ready
 True if the kart has skidded long enough to get a skid bonus if it stopped skidding now. More...
 
float m_remaining_jump_time
 Set to >0 when a graphical jump is to be done. More...
 
float m_graphical_remaining_jump_time
 
float m_prev_visual_rotation
 
float m_smoothing_time
 
float m_smoothing_dt
 
int m_skid_bonus_end_ticks
 
SkidState m_skid_state
 The current skidding state. More...
 
Kartm_kart
 A read-only pointer to the kart's properties. More...
 

Friends

class KartRewinder
 

Member Enumeration Documentation

◆ SkidState

SKID_NONE: Kart is currently not skidding.

SKID_ACCUMULATE_LEFT: Kart is skidding to the left and accumulating for bonus. SKID_ACCUMULATE_RIGHT: Similar for turning right SKID_SHOW_GFX_LEFT: Shows the gfx, while the bonus is active, and the kart was turning left. SKID_SHOW_GFX_RIGHT: Similar for turning right. SKID_BREAK: Skidding was stopped without bonus

Member Function Documentation

◆ getSkidBonus()

unsigned int Skidding::getSkidBonus ( float *  bonus_time,
float *  bonus_speed,
float *  bonus_force 
) const
private

Determines the bonus time and speed given the currently accumulated m_skid_time.

Parameters
bonus_timeOn return contains how long the bonus should be active.
bonus_speedHow much additional speed the kart should get.
bonus_forceAdditional engine force.
Returns
The bonus level: 0 = no bonus, 1 = first entry in bonus array etc.

◆ getSkidBonusReady()

bool Skidding::getSkidBonusReady ( ) const
inline

Returns if the kart has skidded long enough to get a skid bonus if it stopped skidding now.

This function returns false if the kart is actually using the skid bonus.

◆ getSkidFactor()

float Skidding::getSkidFactor ( ) const
inline

Returns the current skid factor in [1, skid_max_for_this_kart].

◆ getSkidState()

SkidState Skidding::getSkidState ( ) const
inline

Returns the skidding state.

◆ getSteeringFraction()

float Skidding::getSteeringFraction ( )
inline

Returns the steering fraction to be used by the physics.

This is a fraction of the maximum steering angle ( so in [-1, 1]).

◆ getSteeringWhenSkidding()

float Skidding::getSteeringWhenSkidding ( float  steering) const

Returns the steering value necessary to set in KartControls.m_steer in order to actually to steer the specified amount in 'steering'.

If the kart is not skidding, the return value is just 'steering'. Otherwise the return value will be (depending on current skidding direction) 'steering1', so that when the kart steers 'steering1', it will de facto steer by the original 'steering' amount. This function might return a result outside of [-1,1] if the specified steering can not be reached (e.g. due to skidding)

◆ getVisualSkidRotation()

float Skidding::getVisualSkidRotation ( ) const
inline

Determines how much the graphics model of the kart should be rotated additionally (for skidding), depending on how long the kart has been skidding etc.

◆ isSkidding()

bool Skidding::isSkidding ( ) const
inline

Returns true if the kart is skidding.

◆ rewindTo()

void Skidding::rewindTo ( BareNetworkString buffer)

Restores the skidding state of a kart.

Parameters
bufferBuffer with state information.

◆ saveState()

void Skidding::saveState ( BareNetworkString buffer)

Save the skidding state of a kart.

It only saves the important physics values including m_remaining_jump_time (while this is mostly a graphical effect, you can't skid while still doing a jump, so it does affect the state). Similarly m_real_steering is output of updateRewind() and will be recomputed every frame when update() is called, and similar for m_skid_bonus_ready

Parameters
bufferBuffer for the state information.

◆ update()

void Skidding::update ( int  ticks,
bool  is_on_ground,
float  steering,
KartControl::SkidControl  skidding 
)

Updates skidding status.

Parameters
ticksNumber of physics time steps - should be 1.
is_on_groundTrue if the kart is on ground.
steeringRaw steering of the kart [-1,1], i.e. not adjusted by the kart's max steering angle.
skiddingTrue if the skid button is pressed.

◆ updateGraphics()

float Skidding::updateGraphics ( float  dt)

Called once per rendered frame to potentially update the graphical jump height.

The jump at the start of a skid is graphical only.

Parameters
dtTime step size.
Returns
Current height of the jump.

◆ updateSteering()

float Skidding::updateSteering ( float  steer,
int  ticks 
)
private

Computes the actual steering fraction to be used in the physics, and stores it in m_real_skidding.

This is later used by kart to set the physical steering. The real steering takes skidding into account: if the kart skids either left or right, the steering fraction is bound by reduce-turn-min and reduce-turn-max.

Member Data Documentation

◆ m_kart

Kart* Skidding::m_kart
private

A read-only pointer to the kart's properties.

◆ m_real_steering

float Skidding::m_real_steering
private

This is the actual steering (in fraction of max-steering-angle) to be used by this kart.

◆ m_remaining_jump_time

float Skidding::m_remaining_jump_time
private

Set to >0 when a graphical jump is to be done.

◆ m_skid_bonus_ready

bool Skidding::m_skid_bonus_ready
private

True if the kart has skidded long enough to get a skid bonus if it stopped skidding now.

◆ m_skid_factor

float Skidding::m_skid_factor
private

Accumulated skidding factor.

◆ m_skid_reduce_turn_delta

float Skidding::m_skid_reduce_turn_delta
private

This is m_skid_reduce_turn_max - m_skid_reduce_turn_min.

◆ m_skid_state

SkidState Skidding::m_skid_state
private

The current skidding state.

◆ m_skid_time

uint16_t Skidding::m_skid_time
private

Keeps track on how long a kart has been skidding, in order to trigger the skidding bonus.

◆ m_visual_rotation

float Skidding::m_visual_rotation
private

An additional rotation (heading) of the kart while skidding.

This is only a graphical effect, the actual physics body is not rotated.


The documentation for this class was generated from the following files: