Skip to content

Commit

Permalink
Update to new rl_ball_sym
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jun 14, 2024
1 parent 9d53734 commit e61ef23
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 85 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

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

13 changes: 4 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rl_ball_sym_pybinds"
version = "3.0.0"
version = "3.1.0"
edition = "2021"
rust-version = "1.73"
license = "MIT"
Expand All @@ -13,14 +13,9 @@ exclude = [".github/", "*.bat", "*.sh", ".git*", "*.py", "*.png", "rustfmt.toml"
crate-type = ["cdylib"]
path = "src/lib.rs"

[dependencies.rl_ball_sym]
version = "4.0.0"
default-features = false
features = ["compression", "standard", "hoops", "dropshot", "throwback"]

[dependencies.pyo3]
version = "0.21.2"
features = ["extension-module", "abi3-py310"]
[dependencies]
pyo3 = "0.21.0"
rl_ball_sym = { version = "4.1.0", features = ["compression"] }

[profile.release]
codegen-units=1
Expand Down
15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[build-system]
requires = ["maturin>=1.0,<2.0"]
requires = ["maturin>=1.3,<2.0"]
build-backend = "maturin"

[project]
name = "rl_ball_sym_pybinds"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[tool.maturin]
features = ["pyo3/extension-module", "pyo3/abi3-py310"]
6 changes: 6 additions & 0 deletions rl_ball_sym_pybinds.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def load_standard_throwback() -> None:
"""


def load_standard_heatseeker() -> None:
"""
Loads the geometry of a standard field for Heatseeker
"""


try:
from rlbot_flatbuffers import GameTickPacket
except ImportError:
Expand Down
120 changes: 64 additions & 56 deletions script.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,89 @@
from traceback import print_exc
from typing import Sequence

import RocketSim as rs
# import RocketSim as rs
from rlbot.managers.script import Script
from rlbot_flatbuffers import BallPrediction, GameTickPacket, PolyLine3D, Vector3
from rlbot_flatbuffers import (
BallPrediction,
GameTickPacket,
PolyLine3D,
PredictionSlice,
Vector3,
)

import rl_ball_sym_pybinds as rlbs
# import rl_ball_sym_pybinds as rlbs


class rl_ball_sym(Script):
def __init__(self):
super().__init__("rl_ball_sym")

rlbs.load_standard()
# rlbs.load_standard()
# rlbs.load_standard_heatseeker()

self.arena = rs.Arena(rs.GameMode.SOCCAR)
self.framework_prediction = BallPrediction()
# self.arena = rs.Arena(rs.GameMode.HEATSEEKER)
self.framework_prediction: Sequence[PredictionSlice] = []

def handle_ball_prediction(self, ball_prediction: BallPrediction):
self.framework_prediction = ball_prediction
self.framework_prediction = ball_prediction.slices

def handle_packet(self, packet: GameTickPacket):
try:
rlbs.tick(packet)

ball = self.arena.ball.get_state()
ball.pos.x = packet.ball.physics.location.x
ball.pos.y = packet.ball.physics.location.y
ball.pos.z = packet.ball.physics.location.z
ball.vel.x = packet.ball.physics.velocity.x
ball.vel.y = packet.ball.physics.velocity.y
ball.vel.z = packet.ball.physics.velocity.z
ball.ang_vel.x = packet.ball.physics.angular_velocity.x
ball.ang_vel.y = packet.ball.physics.angular_velocity.y
ball.ang_vel.z = packet.ball.physics.angular_velocity.z
self.arena.ball.set_state(ball)

self.renderer.begin_rendering("rocketsim")

rocketsim_prediction = []
for i in range(0, 120 * 6):
self.arena.step()
pos = self.arena.ball.get_state().pos
if i % 8 == 0:
rocketsim_prediction.append(Vector3(pos.x, pos.y, pos.z))

self.renderer.draw(
PolyLine3D(
rocketsim_prediction,
self.renderer.yellow,
)
)

self.renderer.end_rendering()

self.renderer.begin_rendering("rl_ball_sym")

custom_prediction = rlbs.get_ball_prediction_struct()
self.renderer.draw(
PolyLine3D(
[
Vector3(*custom_prediction.slices[i].location)
for i in range(0, custom_prediction.num_slices, 4)
],
self.renderer.red,
)
)

self.renderer.end_rendering()

if len(self.framework_prediction.slices) > 2:
# rlbs.tick(packet)

# ball = self.arena.ball.get_state()
# ball.pos.x = packet.ball.physics.location.x
# ball.pos.y = packet.ball.physics.location.y
# ball.pos.z = packet.ball.physics.location.z
# ball.vel.x = packet.ball.physics.velocity.x
# ball.vel.y = packet.ball.physics.velocity.y
# ball.vel.z = packet.ball.physics.velocity.z
# ball.ang_vel.x = packet.ball.physics.angular_velocity.x
# ball.ang_vel.y = packet.ball.physics.angular_velocity.y
# ball.ang_vel.z = packet.ball.physics.angular_velocity.z
# self.arena.ball.set_state(ball)

# self.renderer.begin_rendering("rocketsim")

# rocketsim_prediction = []
# for i in range(0, 120 * 6):
# self.arena.step()
# pos = self.arena.ball.get_state().pos
# if i % 8 == 0:
# rocketsim_prediction.append(Vector3(pos.x, pos.y, pos.z))

# self.renderer.draw(
# PolyLine3D(
# rocketsim_prediction,
# self.renderer.yellow,
# )
# )

# self.renderer.end_rendering()

# self.renderer.begin_rendering("rl_ball_sym")

# custom_prediction = rlbs.get_ball_prediction_struct()
# self.renderer.draw(
# PolyLine3D(
# [
# Vector3(*custom_prediction.slices[i].location)
# for i in range(0, custom_prediction.num_slices, 4)
# ],
# self.renderer.red,
# )
# )

# self.renderer.end_rendering()

if len(self.framework_prediction) > 2:
self.renderer.begin_rendering("rlbot")

self.renderer.draw(
PolyLine3D(
tuple(
slice.physics.location
for slice in self.framework_prediction.slices[::2]
for slice in self.framework_prediction[::4]
),
self.renderer.green,
)
Expand Down

0 comments on commit e61ef23

Please sign in to comment.