Skip to content

Commit

Permalink
Update to new RocketSim
Browse files Browse the repository at this point in the history
Drop support for reading RLGym types directly
  • Loading branch information
VirxEC committed Oct 30, 2023
1 parent 5bda970 commit d977809
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 757 deletions.
18 changes: 9 additions & 9 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 = "rlviser-py"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
description = "Python implementation that manages a UDP connection to RLViser"
license = "MIT"
Expand Down
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
## rlviser-py

Python implementation that manages a UDP connection to RLViser, it launches the [RLViser binary](https://github.com/VirxEC/rlviser) from the current working directory upon first calling any render function.

Currently able to visualize RLGym GameState objects, but requires the boost pad locations to be sent first.
Python implementation that manages a UDP connection to RLViser, it launches the [RLViser binary](https://github.com/VirxEC/rlviser) from the current working directory upon first calling any render function.

The backbone of RLGym's `env.render()` functionality.

### Example usage

```python
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), boost=100))
arena.ball.set_state(rs.BallState(pos=rs.Vec(y=400, z=100), ang_vel=rs.Vec(x=5)))
car.set_controls(rs.CarControls(throttle=1, steer=1, boost=True))

# Run for 3 seconds
TIME = 3

steps = 0
starttime = time.time()
for i in range(round(TIME * 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()
```
21 changes: 0 additions & 21 deletions gym_renderer.py

This file was deleted.

61 changes: 0 additions & 61 deletions pygymtest.py

This file was deleted.

3 changes: 2 additions & 1 deletion pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
car.set_controls(rs.CarControls(throttle=1, steer=1, boost=True))

# Run for 3 seconds
TIME = 3

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

# Render the current game state
Expand Down
15 changes: 2 additions & 13 deletions rlviser_py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ 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
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:
from rlgym.rocket_league.engine.game_state import GameState

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

def quit() -> ...:
Expand Down
Loading

0 comments on commit d977809

Please sign in to comment.