Skip to content

Commit

Permalink
Update to new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Sep 17, 2024
1 parent 9819a5c commit 2a1fad6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 59 deletions.
88 changes: 38 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rlbot-flatbuffers-py"
version = "0.8.1"
version = "0.9.0"
edition = "2021"
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
Expand Down
26 changes: 23 additions & 3 deletions codegen/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ impl StructBindGenerator {
String::from("Option<crate::Floats>")
} else if inner_type == "Bool" {
String::from("Option<crate::Bools>")
} else if self.is_frozen {
format!("Option<super::{inner_type}>")
} else {
format!("Option<Py<super::{inner_type}>>")
}),
Expand Down Expand Up @@ -690,7 +692,13 @@ impl Generator for StructBindGenerator {
}
RustType::Option(InnerOptionType::BaseType, inner_type)
| RustType::Option(InnerOptionType::String, inner_type) => format!("Option<{inner_type}>"),
RustType::Option(_, inner_type) => format!("Option<Py<super::{inner_type}>>"),
RustType::Option(_, inner_type) => {
if self.is_frozen {
format!("Option<super::{inner_type}>")
} else {
format!("Option<Py<super::{inner_type}>>")
}
}
RustType::Base(inner_type) => inner_type.clone(),
RustType::String => String::from("String"),
RustType::Union(inner_type) | RustType::Custom(inner_type) => {
Expand Down Expand Up @@ -810,9 +818,15 @@ impl Generator for StructBindGenerator {
}
}
RustType::Option(InnerOptionType::Box, _) => {
let inner = if self.is_frozen {
"(*x).into()"
} else {
"crate::into_py_from(py, *x)"
};

write_fmt!(
self,
" {variable_name}: flat_t.{variable_name}.map(|x| crate::into_py_from(py, *x)),"
" {variable_name}: flat_t.{variable_name}.map(|x| {inner}),"
);
}
RustType::Option(InnerOptionType::String, _) => {
Expand Down Expand Up @@ -930,7 +944,13 @@ impl Generator for StructBindGenerator {
}
}
RustType::Option(InnerOptionType::Box, _) => {
write_fmt!(self, " {variable_name}: py_type.{variable_name}.as_ref().map(|x| Box::new(crate::from_py_into(py, x))),");
let inner = if self.is_frozen {
"x.into()"
} else {
"crate::from_py_into(py, x)"
};

write_fmt!(self, " {variable_name}: py_type.{variable_name}.as_ref().map(|x| Box::new({inner})),");
}
RustType::Option(InnerOptionType::String, _) => {
write_fmt!(self, " {variable_name}: py_type.{variable_name}.clone(),");
Expand Down
2 changes: 1 addition & 1 deletion flatbuffers-schema
Submodule flatbuffers-schema updated 1 files
+4 −8 rlbot.fbs
2 changes: 1 addition & 1 deletion pybench.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_gtp():
gtp = flat.GameTickPacket(
balls=[flat.BallInfo(shape=flat.SphereShape()) for _ in range(32)],
players=[flat.PlayerInfo() for _ in range(128)],
boost_pad_states=[flat.BoostPadState() for _ in range(128)],
boost_pads=[flat.BoostPadState() for _ in range(128)],
teams=[flat.TeamInfo() for _ in range(2)],
)

Expand Down
4 changes: 1 addition & 3 deletions pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def random_script_config():

print()

ballPred = BallPrediction([
PredictionSlice(1) for _ in range(5 * 120)
])
ballPred = BallPrediction([PredictionSlice(1) for _ in range(5 * 120)])
data = ballPred.pack()
print(f"BallPrediction size: {len(data)} bytes")

Expand Down

0 comments on commit 2a1fad6

Please sign in to comment.