-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller_state.rs
More file actions
183 lines (170 loc) · 5.3 KB
/
controller_state.rs
File metadata and controls
183 lines (170 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use crate::{FromGil, PyDefault, flat};
use pyo3::{prelude::*, types::*};
#[pyclass(module = "rlbot_flatbuffers", subclass, get_all)]
pub struct ControllerState {
/// -1 for full reverse, 1 for full forward.
pub throttle: Py<PyFloat>,
/// -1 for full left, 1 for full right.
pub steer: Py<PyFloat>,
/// -1 for nose down, 1 for nose up.
pub pitch: Py<PyFloat>,
/// -1 for full left, 1 for full right.
pub yaw: Py<PyFloat>,
/// -1 for roll left, 1 for roll right.
pub roll: Py<PyFloat>,
/// True if you want to press the jump button.
#[pyo3(set)]
pub jump: bool,
/// True if you want to press the boost button.
#[pyo3(set)]
pub boost: bool,
/// True if you want to press the handbrake button.
#[pyo3(set)]
pub handbrake: bool,
/// True if you want to press the 'use item' button. Used in Rumble and other game modes.
#[pyo3(set)]
pub use_item: bool,
}
impl crate::PyDefault for ControllerState {
fn py_default(py: Python) -> Py<Self> {
Py::new(
py,
Self {
throttle: crate::pyfloat_default(py),
steer: crate::pyfloat_default(py),
pitch: crate::pyfloat_default(py),
yaw: crate::pyfloat_default(py),
roll: crate::pyfloat_default(py),
jump: Default::default(),
boost: Default::default(),
handbrake: Default::default(),
use_item: Default::default(),
},
)
.unwrap()
}
}
impl FromGil<&flat::ControllerState> for ControllerState {
#[allow(unused_variables)]
fn from_gil(py: Python, flat_t: &flat::ControllerState) -> Self {
Self {
throttle: crate::float_to_py(py, flat_t.throttle),
steer: crate::float_to_py(py, flat_t.steer),
pitch: crate::float_to_py(py, flat_t.pitch),
yaw: crate::float_to_py(py, flat_t.yaw),
roll: crate::float_to_py(py, flat_t.roll),
jump: flat_t.jump,
boost: flat_t.boost,
handbrake: flat_t.handbrake,
use_item: flat_t.use_item,
}
}
}
impl FromGil<&ControllerState> for flat::ControllerState {
#[allow(unused_variables)]
fn from_gil(py: Python, py_type: &ControllerState) -> Self {
Self {
throttle: crate::float_from_py(py, &py_type.throttle),
steer: crate::float_from_py(py, &py_type.steer),
pitch: crate::float_from_py(py, &py_type.pitch),
yaw: crate::float_from_py(py, &py_type.yaw),
roll: crate::float_from_py(py, &py_type.roll),
jump: py_type.jump,
boost: py_type.boost,
handbrake: py_type.handbrake,
use_item: py_type.use_item,
}
}
}
#[pymethods]
impl ControllerState {
#[new]
#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (throttle=0.0, steer=0.0, pitch=0.0, yaw=0.0, roll=0.0, jump=false, boost=false, handbrake=false, use_item=false))]
pub fn new(
py: Python,
throttle: f64,
steer: f64,
pitch: f64,
yaw: f64,
roll: f64,
jump: bool,
boost: bool,
handbrake: bool,
use_item: bool,
) -> Self {
Self {
throttle: PyFloat::new(py, throttle).unbind(),
steer: PyFloat::new(py, steer).unbind(),
pitch: PyFloat::new(py, pitch).unbind(),
yaw: PyFloat::new(py, yaw).unbind(),
roll: PyFloat::new(py, roll).unbind(),
jump,
boost,
handbrake,
use_item,
}
}
#[setter]
pub fn throttle(&mut self, py: Python, value: f64) {
self.throttle = PyFloat::new(py, value).unbind();
}
#[setter]
pub fn steer(&mut self, py: Python, value: f64) {
self.steer = PyFloat::new(py, value).unbind();
}
#[setter]
pub fn pitch(&mut self, py: Python, value: f64) {
self.pitch = PyFloat::new(py, value).unbind();
}
#[setter]
pub fn yaw(&mut self, py: Python, value: f64) {
self.yaw = PyFloat::new(py, value).unbind();
}
#[setter]
pub fn roll(&mut self, py: Python, value: f64) {
self.roll = PyFloat::new(py, value).unbind();
}
pub fn __str__(&self, py: Python) -> String {
self.__repr__(py)
}
#[allow(unused_variables)]
pub fn __repr__(&self, py: Python) -> String {
format!(
"ControllerState(throttle={}, steer={}, pitch={}, yaw={}, roll={}, jump={}, boost={}, handbrake={}, use_item={})",
self.throttle,
self.steer,
self.pitch,
self.yaw,
self.roll,
crate::bool_to_str(self.jump),
crate::bool_to_str(self.boost),
crate::bool_to_str(self.handbrake),
crate::bool_to_str(self.use_item),
)
}
#[classattr]
fn __match_args__() -> (
&'static str,
&'static str,
&'static str,
&'static str,
&'static str,
&'static str,
&'static str,
&'static str,
&'static str,
) {
(
"throttle",
"steer",
"pitch",
"yaw",
"roll",
"jump",
"boost",
"handbrake",
"use_item",
)
}
}