Skip to content

Commit 4fbd19b

Browse files
authored
Merge pull request #10 from RLBot/0.17
Update to the newest schema
2 parents 9460dfb + c665bd2 commit 4fbd19b

File tree

11 files changed

+355
-558
lines changed

11 files changed

+355
-558
lines changed

Cargo.lock

Lines changed: 176 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.16.1"
3+
version = "0.17.0"
44
edition = "2024"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
@@ -18,7 +18,7 @@ all = "warn"
1818
crate-type = ["cdylib"]
1919

2020
[dependencies]
21-
pyo3 = { version = "0.24.0", features = [] }
21+
pyo3 = "0.25.0"
2222
serde = "1.0.217"
2323
flatbuffers = "=25.2.10"
2424
# get-size appears to be unmaintained but it's too useful here
@@ -27,7 +27,7 @@ get-size = { git = "https://github.com/VirxEC/get-size", branch = "update", feat
2727

2828
[build-dependencies]
2929
reqwest = { version = "0.12.15", features = ["blocking", "rustls-tls"], default-features = false }
30-
zip = { version = "2.6.1", features = ["deflate"], default-features = false }
30+
zip = { version = "4.0.0", features = ["deflate"], default-features = false }
3131

3232
[profile.dev]
3333
opt-level = 2

codegen/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl EnumBindGenerator {
6464
Cow::Borrowed("use crate::{flat_err_to_py, generated::rlbot::flat};"),
6565
Cow::Borrowed("use flatbuffers::root;"),
6666
Cow::Borrowed(
67-
"use pyo3::{exceptions::PyValueError, pyclass, pymethods, types::PyBytes, Bound, PyResult, Python};",
67+
"use pyo3::{Bound, PyResult, Python, exceptions::PyValueError, pyclass, pymethods, types::PyBytes};",
6868
),
6969
Cow::Borrowed(""),
7070
];

codegen/main.rs

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ use std::{borrow::Cow, env::set_current_dir, fs, io, path::Path, process::Comman
1212
use structs::StructBindGenerator;
1313
use zip::ZipArchive;
1414

15-
const FLATC_BINARY: &str = if cfg!(windows) { "flatc.exe" } else { "flatc" };
16-
const OUT_FOLDER: &str = "./src/generated";
15+
const FLATC_DOWNLOAD_URL: &str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/";
16+
1717
const SCHEMA_FOLDER: &str = "./flatbuffers-schema";
1818
const SCHEMA_FOLDER_BACKUP: &str = "../flatbuffers-schema";
19+
const RLBOT_FBS: &str = "schema/rlbot.fbs";
20+
const FLATC_BINARY: &str = if cfg!(windows) {
21+
"binaries\\flatc.exe"
22+
} else {
23+
"binaries/flatc"
24+
};
1925

20-
const FLATC_DOWNLOAD_URL: &str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/";
21-
26+
const OUT_FOLDER: &str = "./src/generated";
2227
pub const PYTHON_OUT_FOLDER: &str = "./src/python";
2328

2429
pub enum PythonBindType {
@@ -29,15 +34,14 @@ pub enum PythonBindType {
2934

3035
impl PythonBindType {
3136
pub const BASE_TYPES: [&'static str; 6] = ["bool", "i32", "u32", "f32", "String", "u8"];
32-
pub const FROZEN_TYPES: [&'static str; 6] = [
37+
pub const FROZEN_TYPES: [&'static str; 26] = [
38+
"ControllableInfo",
39+
"ControllableTeamInfo",
40+
"PredictionSlice",
41+
"BallPrediction",
3342
"GoalInfo",
3443
"BoostPad",
3544
"FieldInfo",
36-
"ControllableInfo",
37-
"ControllableTeamInfo",
38-
"PlayerClass",
39-
];
40-
pub const NO_SET_TYPES: [&'static str; 16] = [
4145
"Physics",
4246
"GamePacket",
4347
"PlayerInfo",
@@ -52,13 +56,25 @@ impl PythonBindType {
5256
"MatchInfo",
5357
"TeamInfo",
5458
"Vector2",
55-
"PredictionSlice",
56-
"BallPrediction",
59+
"CoreMessage",
60+
"InterfaceMessage",
61+
"CorePacket",
62+
"InterfacePacket",
63+
"PlayerInput",
64+
];
65+
pub const NO_SET_TYPES: [&'static str; 1] = ["PlayerClass"];
66+
pub const UNIONS: [&'static str; 6] = [
67+
"PlayerClass",
68+
"CollisionShape",
69+
"RelativeAnchor",
70+
"RenderType",
71+
"CoreMessage",
72+
"InterfaceMessage",
5773
];
58-
pub const UNIONS: [&'static str; 4] = ["PlayerClass", "CollisionShape", "RelativeAnchor", "RenderType"];
5974

6075
pub const OPTIONAL_UNIONS: [&'static str; 1] = ["RelativeAnchor"];
6176
pub const DEFAULT_OVERRIDES: [(&'static str, &'static str, &'static str); 1] = [("Color", "a", "255")];
77+
pub const FIELD_ALIASES: [(&'static str, &'static str, &'static str); 1] = [("PlayerInfo", "player_id", "spawn_id")];
6278
pub const FREELIST_TYPES: [(&'static str, usize); 0] = [];
6379

6480
fn new(path: &Path) -> Option<Self> {
@@ -176,15 +192,15 @@ fn mod_rs_generator(type_data: &[PythonBindType]) -> io::Result<()> {
176192
Ok(())
177193
}
178194

179-
fn run_flatc() -> io::Result<()> {
195+
fn run_flatc() {
180196
println!("cargo:rerun-if-changed=flatbuffers-schema/comms.fbs");
181197
println!("cargo:rerun-if-changed=flatbuffers-schema/gamedata.fbs");
182198
println!("cargo:rerun-if-changed=flatbuffers-schema/gamestatemanip.fbs");
183199
println!("cargo:rerun-if-changed=flatbuffers-schema/matchconfig.fbs");
184200
println!("cargo:rerun-if-changed=flatbuffers-schema/rendering.fbs");
185201
println!("cargo:rerun-if-changed=flatbuffers-schema/rlbot.fbs");
186202

187-
set_current_dir(env!("CARGO_MANIFEST_DIR"))?;
203+
set_current_dir(env!("CARGO_MANIFEST_DIR")).unwrap();
188204

189205
let mut schema_folder = Path::new(SCHEMA_FOLDER);
190206
if !schema_folder.exists() {
@@ -197,51 +213,58 @@ fn run_flatc() -> io::Result<()> {
197213
let flatc_path = Path::new(&flatc_str);
198214

199215
if !flatc_path.exists() {
216+
fs::create_dir_all(flatc_path).unwrap();
217+
200218
// if the flatc binary isn't found, download it
201219
let file_name = if cfg!(windows) {
202220
"Windows.flatc.binary.zip"
203221
} else {
204222
"Linux.flatc.binary.g++-13.zip"
205223
};
206-
let response = reqwest::blocking::get(format!("{FLATC_DOWNLOAD_URL}/{file_name}")).map_err(|e| {
207-
eprintln!("Failed to download flatc binary: {e}");
208-
io::Error::other("Failed to download flatc binary")
209-
})?;
210-
let bytes = response.bytes().map_err(|e| {
211-
eprintln!("Failed to read response stream when downloading flatc binary: {e}");
212-
io::Error::other("Failed to read response stream when downloading flatc binary")
213-
})?;
224+
let response = reqwest::blocking::get(format!("{FLATC_DOWNLOAD_URL}/{file_name}"))
225+
.map_err(|e| {
226+
eprintln!("Failed to download flatc binary: {e}");
227+
io::Error::other("Failed to download flatc binary")
228+
})
229+
.unwrap();
230+
let bytes = response
231+
.bytes()
232+
.map_err(|e| {
233+
eprintln!("Failed to read response stream when downloading flatc binary: {e}");
234+
io::Error::other("Failed to read response stream when downloading flatc binary")
235+
})
236+
.unwrap();
214237

215238
// extract zip
216-
let mut zip = ZipArchive::new(io::Cursor::new(bytes))?;
217-
zip.extract(schema_folder)?;
239+
let mut zip = ZipArchive::new(io::Cursor::new(bytes)).unwrap();
240+
zip.extract(schema_folder).unwrap();
218241

219242
assert!(flatc_path.exists(), "Failed to download flatc binary");
220243
}
221244

222245
let mut proc = Command::new(flatc_str);
223246

224247
proc.args([
225-
"--rust",
226-
"--gen-object-api",
227-
"--gen-all",
228-
"--filename-suffix",
229-
"",
230-
"--rust-module-root-file",
231-
"-o",
232-
OUT_FOLDER,
233-
&format!("{schema_folder_str}/rlbot.fbs"),
248+
"--rust".as_ref(),
249+
"--gen-object-api".as_ref(),
250+
"--gen-all".as_ref(),
251+
"--filename-suffix".as_ref(),
252+
"".as_ref(),
253+
"--rust-module-root-file".as_ref(),
254+
"-o".as_ref(),
255+
OUT_FOLDER.as_ref(),
256+
schema_folder.join(RLBOT_FBS).as_os_str(),
234257
])
235-
.spawn()?
236-
.wait()?;
237-
238-
assert!(proc.status()?.success(), "flatc failed to run");
258+
.spawn()
259+
.unwrap()
260+
.wait()
261+
.unwrap();
239262

240-
Ok(())
263+
assert!(proc.status().unwrap().success(), "flatc failed to run");
241264
}
242265

243-
fn main() -> io::Result<()> {
244-
run_flatc()?;
266+
fn main() {
267+
run_flatc();
245268

246269
let out_folder = Path::new(OUT_FOLDER).join("rlbot").join("flat");
247270

@@ -252,9 +275,11 @@ fn main() -> io::Result<()> {
252275
);
253276

254277
// read the current contents of the generated folder
255-
let generated_files = fs::read_dir(out_folder)?
278+
let generated_files = fs::read_dir(out_folder)
279+
.unwrap()
256280
.map(|res| res.map(|e| e.path()))
257-
.collect::<Result<Vec<_>, io::Error>>()?;
281+
.collect::<Result<Vec<_>, io::Error>>()
282+
.unwrap();
258283

259284
let mut type_data = Vec::new();
260285

@@ -263,13 +288,11 @@ fn main() -> io::Result<()> {
263288
continue;
264289
};
265290

266-
bind_generator.generate(&path)?;
291+
bind_generator.generate(&path).unwrap();
267292
type_data.push(bind_generator);
268293
}
269294

270-
mod_rs_generator(&type_data)?;
271-
pyi::generator(&type_data)?;
272-
class_inject::classes_to_lib_rs(&type_data)?;
273-
274-
Ok(())
295+
mod_rs_generator(&type_data).unwrap();
296+
pyi::generator(&type_data).unwrap();
297+
class_inject::classes_to_lib_rs(&type_data).unwrap();
275298
}

codegen/pyi.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,6 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
309309
write_str!(file, " Serializes this instance into a byte array");
310310
write_str!(file, " \"\"\"");
311311

312-
if !bind.is_frozen {
313-
write_str!(file, " def unpack_with(self, data: bytes) -> None:");
314-
write_str!(file, " \"\"\"");
315-
write_str!(file, " Deserializes the data into this instance\n");
316-
write_str!(
317-
file,
318-
" :raises InvalidFlatbuffer: If the `data` is invalid for this type"
319-
);
320-
write_str!(file, " \"\"\"");
321-
}
322-
323312
write_str!(file, " @staticmethod");
324313
write_fmt!(file, " def unpack(data: bytes) -> {type_name}:");
325314
write_str!(file, " \"\"\"");

0 commit comments

Comments
 (0)