19 #ifndef HEADER_KART_CONTROL_HPP 20 #define HEADER_KART_CONTROL_HPP 35 enum SkidControl {SC_NONE, SC_NO_DIRECTION, SC_LEFT, SC_RIGHT};
87 return m_steer == other.
m_steer &&
106 return (m_brake ? 1 : 0)
110 + (m_look_back ? 16 : 0)
119 m_brake = (c & 1) != 0;
120 m_nitro = (c & 2) != 0;
121 m_rescue = (c & 4) != 0;
122 m_fire = (c & 8) != 0;
123 m_look_back = (c & 16) != 0;
128 float getSteer()
const {
return (
float)m_steer / 32767.0f; }
131 float getAccel()
const {
return (
float)m_accel / 65535.0f; }
void saveState(BareNetworkString *buffer) const
Copies the important data from this objects into a memory buffer.
Definition: kart_control.cpp:84
SkidControl getSkidControl() const
Returns the skidding control state: SC_NONE: not pressed; SC_NO_DIRECTION: pressed, but no steering; SC_LEFT/RIGHT: pressed in the specified direction.
Definition: kart_control.hpp:142
bool m_nitro
True if the kart activates nitro.
Definition: kart_control.hpp:45
bool m_fire
True if fire is selected.
Definition: kart_control.hpp:51
SkidControl
The skidding control state: SC_NONE: not pressed; SC_NO_DIRECTION: pressed, but no steering; SC_LEFT/...
Definition: kart_control.hpp:35
void setBrake(bool b)
Sets if the kart is braking.
Definition: kart_control.cpp:43
void setFire(bool b)
Sets if the kart wants to fire.
Definition: kart_control.cpp:71
void reset()
Resets all controls.
Definition: kart_control.hpp:71
bool getFire() const
Returns if fire is selected.
Definition: kart_control.hpp:148
void setButtonsCompressed(char c)
Sets the buttons from a compressed (1 byte) representation.
Definition: kart_control.hpp:117
Declares the general types that are used by the network.
void setSteer(float f)
Sets the current steering value.
Definition: kart_control.cpp:27
char getButtonsCompressed() const
Compresses all buttons into a single byte.
Definition: kart_control.hpp:104
Definition: kart_control.hpp:29
bool m_brake
True if the kart brakes.
Definition: kart_control.hpp:43
SkidControl m_skid
Skidding control state.
Definition: kart_control.hpp:47
bool getLookBack() const
Returns if the kart wants to look back (which also implies that it will fire backwards.
Definition: kart_control.hpp:152
bool getBrake() const
Returns if the kart is braking.
Definition: kart_control.hpp:134
int16_t m_steer
The current steering value in [-32767, 32767].
Definition: kart_control.hpp:39
float getAccel() const
Returns current acceleration in [0, 1].
Definition: kart_control.hpp:131
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
bool getRescue() const
Returns true if the kart triggered rescue.
Definition: kart_control.hpp:145
void setRescue(bool b)
Returns if this kart wants to get rescued.
Definition: kart_control.cpp:64
void setSkidControl(SkidControl sc)
Sets the skid control for this kart.
Definition: kart_control.cpp:57
void setLookBack(bool b)
Sets if the kart wants to look (and therefore also fires) backwards.
Definition: kart_control.cpp:78
float getSteer() const
Returns the current steering value in [-1, 1].
Definition: kart_control.hpp:128
bool operator==(const KartControl &other)
Tests if two KartControls are equal.
Definition: kart_control.hpp:85
bool getNitro() const
Returns if the kart activates nitro.
Definition: kart_control.hpp:137
void setAccel(float f)
Sets the acceleration.
Definition: kart_control.cpp:35
bool m_rescue
True if rescue is selected.
Definition: kart_control.hpp:49
bool m_look_back
True if the kart looks (and shoots) backwards.
Definition: kart_control.hpp:53
void rewindTo(BareNetworkString *buffer)
Restores this object from a previously saved memory buffer.
Definition: kart_control.cpp:93
uint16_t m_accel
Acceleration, in [0, 65535].
Definition: kart_control.hpp:41
void setNitro(bool b)
Sets if the kart activates nitro.
Definition: kart_control.cpp:50