Skip to content

Commit e01d3a2

Browse files
committed
Don't freeze BallPrediction or FieldInfo
1 parent c1a4ed5 commit e01d3a2

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot-flatbuffers-py"
3-
version = "0.11.3"
3+
version = "0.11.4"
44
edition = "2021"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
@@ -21,7 +21,7 @@ crate-type = ["cdylib"]
2121
[dependencies]
2222
pyo3 = { version = "0.23.0", features = [] }
2323
serde = "1.0.197"
24-
flatbuffers = "24.3.25"
24+
flatbuffers = "=24.3.25"
2525
# get-size appears to be unmaintained but it's too useful here
2626
# forked and updated deps
2727
get-size = { git = "https://github.com/VirxEC/get-size", branch = "update", features = ["derive"] }

codegen/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ pub enum PythonBindType {
2525

2626
impl PythonBindType {
2727
pub const BASE_TYPES: [&'static str; 6] = ["bool", "i32", "u32", "f32", "String", "u8"];
28-
pub const FROZEN_TYPES: [&'static str; 21] = [
29-
"FieldInfo",
30-
"BoostPad",
28+
pub const FROZEN_TYPES: [&'static str; 17] = [
3129
"GoalInfo",
3230
"GamePacket",
3331
"PlayerInfo",
@@ -41,8 +39,6 @@ impl PythonBindType {
4139
"BoostPadState",
4240
"GameInfo",
4341
"TeamInfo",
44-
"BallPrediction",
45-
"PredictionSlice",
4642
"Physics",
4743
"Vector2",
4844
"ControllableInfo",

pybench.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def test_ballpred():
3939

4040
times = []
4141

42-
ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(960)])
42+
ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(120 * 8)])
43+
44+
print(len(ballPred.pack()))
4345

4446
for _ in range(100_000):
4547
start = time_ns()
@@ -55,7 +57,41 @@ def test_ballpred():
5557
print(f"Minimum time per: {min(times) / 1000:.1f}us")
5658

5759

60+
def find_slice_at_time(ball_prediction: flat.BallPrediction, game_time: float):
61+
"""
62+
This will find the future position of the ball at the specified time. The returned
63+
Slice object will also include the ball's velocity, etc.
64+
"""
65+
start_time = ball_prediction.slices[0].game_seconds
66+
approx_index = int(
67+
(game_time - start_time) * 120
68+
) # We know that there are 120 slices per second.
69+
if 0 <= approx_index < len(ball_prediction.slices):
70+
return ball_prediction.slices[approx_index]
71+
return None
72+
73+
74+
def test_loop():
75+
times = []
76+
77+
ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(120 * 6)])
78+
79+
for _ in range(100):
80+
start = time_ns()
81+
82+
li = [find_slice_at_time(ballPred, t / 60) for t in range(1, 301)]
83+
84+
times.append(time_ns() - start)
85+
86+
print(f"Total time: {sum(times) / 1_000_000_000:.3f}s")
87+
avg_time_ns = sum(times) / len(times)
88+
print(f"Average time per: {avg_time_ns / 1000:.1f}us")
89+
print(f"Minimum time per: {min(times) / 1000:.1f}us")
90+
91+
5892
if __name__ == "__main__":
5993
test_gtp()
6094
print()
6195
test_ballpred()
96+
print()
97+
test_loop()

0 commit comments

Comments
 (0)