Skip to content

Commit

Permalink
Update to new use rocketsim binds
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jul 27, 2023
1 parent 3872326 commit 8dfb568
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 87 deletions.
2 changes: 1 addition & 1 deletion 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.2.3"
version = "0.3.0"
edition = "2021"
description = "Python implementation that manages a UDP connection to RLViser"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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)))
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))

# Run for 3 seconds
Expand All @@ -25,7 +25,7 @@
# 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)
vis.render(steps, arena.tick_rate, pad_states, arena.ball.get_state(), arena.ball.get_rot(), 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()))
Expand Down
7 changes: 3 additions & 4 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ pub struct CarState {
pub last_rel_dodge_torque: Vec3,
pub jump_time: f32,
pub flip_time: f32,

pub is_flipping: bool,
pub is_jumping: bool,
pub air_time_since_jump: f32,
Expand All @@ -178,7 +177,7 @@ pub struct CarState {
pub auto_flip_timer: f32,
pub auto_flip_torque_scale: f32,
pub has_world_contact: bool,
pub contact_normal: Vec3,
pub world_contact_normal: Vec3,
pub car_contact_id: u32,
pub car_contact_cooldown_timer: f32,
pub is_demoed: bool,
Expand Down Expand Up @@ -398,7 +397,7 @@ impl ToBytesExact<{ Self::NUM_BYTES }> for CarState {
// contact_normal: Vec3,
bytes[Vec3::NUM_BYTES * 4 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 9
..Vec3::NUM_BYTES * 5 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 9]
.copy_from_slice(&self.contact_normal.to_bytes());
.copy_from_slice(&self.world_contact_normal.to_bytes());
// other_car_id: u32,
bytes[Vec3::NUM_BYTES * 5 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 9
..Vec3::NUM_BYTES * 5 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 9 + u32::NUM_BYTES]
Expand Down Expand Up @@ -695,7 +694,7 @@ impl FromBytesExact for CarState {
..Vec3::NUM_BYTES * 4 + RotMat::NUM_BYTES + 8 + f32::NUM_BYTES * 9],
),
has_world_contact: bytes[Vec3::NUM_BYTES * 4 + RotMat::NUM_BYTES + 8 + f32::NUM_BYTES * 9] != 0,
contact_normal: Vec3::from_bytes(
world_contact_normal: Vec3::from_bytes(
&bytes[Vec3::NUM_BYTES * 4 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 8
..Vec3::NUM_BYTES * 5 + RotMat::NUM_BYTES + 9 + f32::NUM_BYTES * 9],
),
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod bytes;
mod gym;
mod rocketsim;
mod socket;

use crate::{
Expand Down Expand Up @@ -137,14 +136,14 @@ fn render(
tick_rate: f32,
boost_pad_states: [bool; BOOST_PADS_LENGTH],
ball: BallState,
cars: Vec<(u32, u8, CarConfig, rocketsim::CarState)>,
ball_rot: [f32; 4],
cars: Vec<(u32, u8, CarConfig, CarState)>,
) {
let game_state = GameState {
tick_count,
tick_rate,
ball,
// no way of getting rotation right now
ball_rot: Quat::IDENTITY,
ball_rot: Quat::from_array(ball_rot),
pads: BOOST_PAD_LOCATIONS
.read()
.unwrap()
Expand All @@ -165,7 +164,7 @@ fn render(
id,
team: Team::from_u8(team),
config,
state: state.into(),
state,
})
.collect(),
};
Expand Down
74 changes: 0 additions & 74 deletions src/rocketsim.rs

This file was deleted.

0 comments on commit 8dfb568

Please sign in to comment.