Skip to content

Commit

Permalink
Add rocketsim support
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jul 24, 2023
1 parent 06e7b72 commit 3872326
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 65 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ docs/_build/
.vscode/

# Pyenv
.python-version
.python-version

# RocketSim
collision_meshes/

# RLViser
rlviser*
umodel*
assets.path
assets/
settings.txt
58 changes: 29 additions & 29 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "rlviser-py"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
description = "Python implementation that manages a UDP connection to RLViser"
license = "MIT"
repository = "https://github.com/VirxEC/rlviser-py"
readme = "README.md"
keywords = ["rlviser", "rocket-league", "udp", "python", "rlbot"]
exclude = [".github", "pytest.py", "rustfmt.toml", ".gitignore"]
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
36 changes: 36 additions & 0 deletions pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import time

import rlviser_py as vis
import RocketSim as rs

# Create example arena
arena = rs.Arena(rs.GameMode.SOCCAR)

# Set boost pad locations
vis.set_boost_pad_locations([pad.get_pos().as_tuple() for pad in arena.get_boost_pads()])

# Setup example arena
car = arena.add_car(rs.Team.BLUE)
car.set_state(rs.CarState(pos=rs.Vec(z=17), vel=rs.Vec(x=50)))
arena.ball.set_state(rs.BallState(pos=rs.Vec(y=400, z=100)))
car.set_controls(rs.CarControls(throttle=1, steer=1))

# Run for 3 seconds

steps = 0
starttime = time.time()
for i in range(round(3 * arena.tick_rate)):
arena.step(1)

# Render the current game state
pad_states = [pad.get_state().is_active for pad in arena.get_boost_pads()]
car_data = [(car.id, car.team, car.get_config(), car.get_state()) for car in arena.get_cars()]
vis.render(steps, arena.tick_rate, pad_states, arena.ball.get_state(), car_data)

# sleep to simulate running real time (it will run a LOT after otherwise)
time.sleep(max(0, starttime + steps / arena.tick_rate - time.time()))
steps += 1

# Tell RLViser to exit
print("Exiting...")
vis.quit()
12 changes: 11 additions & 1 deletion rlviser_py.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
def set_boost_pad_locations(locations: list) -> ...:
from typing import List, Tuple

def set_boost_pad_locations(locations: List[Tuple[float, float, float]]) -> ...:
pass

try:
from RocketSim import BallState, CarConfig, CarState, Team

def render(tick_count: int, tick_rate: float, boost_pad_states: List[bool], ball: BallState, cars: List[Tuple[int, Team, CarConfig, CarState]]) -> ...:
pass
except ImportError:
pass

try:
Expand Down
Loading

0 comments on commit 3872326

Please sign in to comment.