SuperTuxKart
Loading...
Searching...
No Matches
skidding.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2012-2015 Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_SKIDDING_HPP
20#define HEADER_SKIDDING_HPP
21
22#include "karts/controller/kart_control.hpp"
23#include "utils/leak_check.hpp"
24#include "utils/no_copy.hpp"
25#include "utils/types.hpp"
26
28class Kart;
29class ShowCurve;
30
31#include <vector>
32
37#undef SKID_DEBUG
38
40{
41friend class KartRewinder;
42public:
43 LEAK_CHECK();
44private:
47
51
55
58
61 uint16_t m_skid_time;
62
66
69
70 float m_graphical_remaining_jump_time;
71
72 float m_prev_visual_rotation;
73
74 float m_smoothing_time;
75
76 float m_smoothing_dt;
77
78 int m_skid_bonus_end_ticks;
79
80public:
89 enum SkidState { SKID_NONE, SKID_ACCUMULATE_LEFT, SKID_ACCUMULATE_RIGHT,
90 SKID_SHOW_GFX_LEFT, SKID_SHOW_GFX_RIGHT, SKID_BREAK} ;
91
92private:
95
98
99#ifdef SKID_DEBUG
100 ShowCurve *m_predicted_curve;
101 ShowCurve *m_actual_curve;
102#endif
103
104 unsigned int getSkidBonus(float *bonus_time, float *bonus_speed,
105 float *bonus_force) const;
106 float updateSteering(float steer, int ticks);
107public:
108 Skidding(Kart *kart);
109 ~Skidding();
110 void reset();
111 float updateGraphics(float dt);
112 void update(int dt, bool is_on_ground, float steer,
113 KartControl::SkidControl skidding);
114 void saveState(BareNetworkString *buffer);
115 void rewindTo(BareNetworkString *buffer);
116 // ------------------------------------------------------------------------
121 {
122 if (m_smoothing_dt >= 0.0f)
123 {
124 return m_smoothing_dt * m_visual_rotation +
125 (1.0f - m_smoothing_dt) * m_prev_visual_rotation;
126 }
127 return m_visual_rotation;
128 }
129 // ------------------------------------------------------------------------
131 float getSkidFactor() const { return m_skid_factor; }
132 // ------------------------------------------------------------------------
134 bool isSkidding() const { return m_skid_factor>1.0f; }
135 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
143 float getSteeringWhenSkidding(float steering) const;
144 // ------------------------------------------------------------------------
148 bool getSkidBonusReady() const { return m_skid_bonus_ready; }
149 // ------------------------------------------------------------------------
150 bool isJumping() const { return m_graphical_remaining_jump_time > 0; }
151 // ------------------------------------------------------------------------
152 void prepareSmoothing();
153 // ------------------------------------------------------------------------
154 void checkSmoothing();
155
156}; // Skidding
157
158
159#endif
160
161/* EOF */
162
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
SkidControl
The skidding control state: SC_NONE: not pressed; SC_NO_DIRECTION: pressed, but no steering; SC_LEFT/...
Definition: kart_control.hpp:35
Definition: kart_rewinder.hpp:30
The main kart class.
Definition: kart.hpp:69
This class is used for debugging.
Definition: show_curve.hpp:46
Definition: skidding.hpp:40
bool getSkidBonusReady() const
Returns if the kart has skidded long enough to get a skid bonus if it stopped skidding now.
Definition: skidding.hpp:148
SkidState getSkidState() const
Returns the skidding state.
Definition: skidding.hpp:141
float m_visual_rotation
An additional rotation (heading) of the kart while skidding.
Definition: skidding.hpp:54
bool m_skid_bonus_ready
True if the kart has skidded long enough to get a skid bonus if it stopped skidding now.
Definition: skidding.hpp:65
float getVisualSkidRotation() const
Determines how much the graphics model of the kart should be rotated additionally (for skidding),...
Definition: skidding.hpp:120
float m_skid_factor
Accumulated skidding factor.
Definition: skidding.hpp:57
void update(int dt, bool is_on_ground, float steer, KartControl::SkidControl skidding)
Updates skidding status.
Definition: skidding.cpp:346
float updateGraphics(float dt)
Called once per rendered frame to potentially update the graphical jump height.
Definition: skidding.cpp:257
float m_skid_reduce_turn_delta
This is m_skid_reduce_turn_max - m_skid_reduce_turn_min.
Definition: skidding.hpp:46
float m_real_steering
This is the actual steering (in fraction of max-steering-angle) to be used by this kart.
Definition: skidding.hpp:50
void rewindTo(BareNetworkString *buffer)
Restores the skidding state of a kart.
Definition: skidding.cpp:114
float getSkidFactor() const
Returns the current skid factor in [1, skid_max_for_this_kart].
Definition: skidding.hpp:131
SkidState m_skid_state
The current skidding state.
Definition: skidding.hpp:94
float updateSteering(float steer, int ticks)
Computes the actual steering fraction to be used in the physics, and stores it in m_real_skidding.
Definition: skidding.cpp:148
uint16_t m_skid_time
Keeps track on how long a kart has been skidding, in order to trigger the skidding bonus.
Definition: skidding.hpp:61
float m_remaining_jump_time
Set to >0 when a graphical jump is to be done.
Definition: skidding.hpp:68
float getSteeringWhenSkidding(float steering) const
Returns the steering value necessary to set in KartControls.m_steer in order to actually to steer the...
Definition: skidding.cpp:226
bool isSkidding() const
Returns true if the kart is skidding.
Definition: skidding.hpp:134
void reset()
Resets all skidding related values.
Definition: skidding.cpp:68
SkidState
SKID_NONE: Kart is currently not skidding.
Definition: skidding.hpp:89
float getSteeringFraction()
Returns the steering fraction to be used by the physics.
Definition: skidding.hpp:138
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.
Definition: skidding.cpp:598
void saveState(BareNetworkString *buffer)
Save the skidding state of a kart.
Definition: skidding.cpp:102
Kart * m_kart
A read-only pointer to the kart's properties.
Definition: skidding.hpp:97
Declares the general types that are used by the network.