Skip to content

Commit

Permalink
Don't freeze BallPrediction or FieldInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Dec 25, 2024
1 parent c1a4ed5 commit e01d3a2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rlbot-flatbuffers-py"
version = "0.11.3"
version = "0.11.4"
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 All @@ -21,7 +21,7 @@ crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.23.0", features = [] }
serde = "1.0.197"
flatbuffers = "24.3.25"
flatbuffers = "=24.3.25"
# get-size appears to be unmaintained but it's too useful here
# forked and updated deps
get-size = { git = "https://github.com/VirxEC/get-size", branch = "update", features = ["derive"] }
Expand Down
6 changes: 1 addition & 5 deletions codegen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ pub enum PythonBindType {

impl PythonBindType {
pub const BASE_TYPES: [&'static str; 6] = ["bool", "i32", "u32", "f32", "String", "u8"];
pub const FROZEN_TYPES: [&'static str; 21] = [
"FieldInfo",
"BoostPad",
pub const FROZEN_TYPES: [&'static str; 17] = [
"GoalInfo",
"GamePacket",
"PlayerInfo",
Expand All @@ -41,8 +39,6 @@ impl PythonBindType {
"BoostPadState",
"GameInfo",
"TeamInfo",
"BallPrediction",
"PredictionSlice",
"Physics",
"Vector2",
"ControllableInfo",
Expand Down
38 changes: 37 additions & 1 deletion pybench.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_ballpred():

times = []

ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(960)])
ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(120 * 8)])

print(len(ballPred.pack()))

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


def find_slice_at_time(ball_prediction: flat.BallPrediction, game_time: float):
"""
This will find the future position of the ball at the specified time. The returned
Slice object will also include the ball's velocity, etc.
"""
start_time = ball_prediction.slices[0].game_seconds
approx_index = int(
(game_time - start_time) * 120
) # We know that there are 120 slices per second.
if 0 <= approx_index < len(ball_prediction.slices):
return ball_prediction.slices[approx_index]
return None


def test_loop():
times = []

ballPred = flat.BallPrediction([flat.PredictionSlice(1) for _ in range(120 * 6)])

for _ in range(100):
start = time_ns()

li = [find_slice_at_time(ballPred, t / 60) for t in range(1, 301)]

times.append(time_ns() - start)

print(f"Total time: {sum(times) / 1_000_000_000:.3f}s")
avg_time_ns = sum(times) / len(times)
print(f"Average time per: {avg_time_ns / 1000:.1f}us")
print(f"Minimum time per: {min(times) / 1000:.1f}us")


if __name__ == "__main__":
test_gtp()
print()
test_ballpred()
print()
test_loop()

0 comments on commit e01d3a2

Please sign in to comment.