From 8dfb56889bfa71013b23b25472d1d6d32c588bb0 Mon Sep 17 00:00:00 2001 From: VirxEC Date: Thu, 27 Jul 2023 01:40:35 -0400 Subject: [PATCH] Update to new use rocketsim binds --- Cargo.lock | 2 +- Cargo.toml | 2 +- pytest.py | 4 +-- src/bytes.rs | 7 ++--- src/lib.rs | 9 +++--- src/rocketsim.rs | 74 ------------------------------------------------ 6 files changed, 11 insertions(+), 87 deletions(-) delete mode 100644 src/rocketsim.rs diff --git a/Cargo.lock b/Cargo.lock index 4aa8157..d9453b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,7 +175,7 @@ dependencies = [ [[package]] name = "rlviser-py" -version = "0.2.3" +version = "0.3.0" dependencies = [ "glam", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 12430da..c5d62bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/pytest.py b/pytest.py index e081a07..97c0e27 100644 --- a/pytest.py +++ b/pytest.py @@ -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 @@ -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())) diff --git a/src/bytes.rs b/src/bytes.rs index 89a8c85..8a68578 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -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, @@ -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, @@ -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] @@ -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], ), diff --git a/src/lib.rs b/src/lib.rs index 8b86e42..dd4c7a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ mod bytes; mod gym; -mod rocketsim; mod socket; use crate::{ @@ -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() @@ -165,7 +164,7 @@ fn render( id, team: Team::from_u8(team), config, - state: state.into(), + state, }) .collect(), }; diff --git a/src/rocketsim.rs b/src/rocketsim.rs deleted file mode 100644 index 32896fb..0000000 --- a/src/rocketsim.rs +++ /dev/null @@ -1,74 +0,0 @@ -use pyo3::FromPyObject; - -use crate::bytes::{BallHitInfo, CarControls, CarState as bCarState, RotMat, Vec3}; - -#[derive(Clone, Copy, Debug, FromPyObject)] -pub struct CarState { - pub pos: Vec3, - pub rot_mat: RotMat, - pub vel: Vec3, - pub ang_vel: Vec3, - pub is_on_ground: bool, - pub has_jumped: bool, - pub has_double_jumped: bool, - pub has_flipped: bool, - 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, - pub boost: f32, - pub time_spent_boosting: f32, - pub is_supersonic: bool, - pub supersonic_time: f32, - pub handbrake_val: f32, - pub is_auto_flipping: bool, - pub auto_flip_timer: f32, - pub auto_flip_torque_scale: f32, - pub has_world_contact: bool, - // pub contact_normal: Vec, - pub car_contact_id: u32, - pub car_contact_cooldown_timer: f32, - pub is_demoed: bool, - pub demo_respawn_timer: f32, - pub ball_hit_info: BallHitInfo, - pub last_controls: CarControls, -} - -impl From for bCarState { - #[inline] - fn from(value: CarState) -> Self { - Self { - pos: value.pos, - rot_mat: value.rot_mat, - vel: value.vel, - ang_vel: value.ang_vel, - is_on_ground: value.is_on_ground, - has_jumped: value.has_jumped, - has_double_jumped: value.has_double_jumped, - has_flipped: value.has_flipped, - last_rel_dodge_torque: value.last_rel_dodge_torque, - jump_time: value.jump_time, - flip_time: value.flip_time, - is_jumping: value.is_jumping, - air_time_since_jump: value.air_time_since_jump, - boost: value.boost, - time_spent_boosting: value.time_spent_boosting, - is_supersonic: value.is_supersonic, - supersonic_time: value.supersonic_time, - handbrake_val: value.handbrake_val, - is_auto_flipping: value.is_auto_flipping, - auto_flip_timer: value.auto_flip_timer, - auto_flip_torque_scale: value.auto_flip_torque_scale, - has_world_contact: value.has_world_contact, - car_contact_id: value.car_contact_id, - car_contact_cooldown_timer: value.car_contact_cooldown_timer, - is_demoed: value.is_demoed, - demo_respawn_timer: value.demo_respawn_timer, - ball_hit_info: value.ball_hit_info, - last_controls: value.last_controls, - ..Default::default() - } - } -}