Skip to content

Commit

Permalink
make it so that on_ground holds over for tickskip instead of only one…
Browse files Browse the repository at this point in the history
… tick
  • Loading branch information
JeffA233 committed May 24, 2024
1 parent 5d2b8b9 commit 9bd4b7e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/sim_wrapper/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct RocketsimWrapper {
jump_timer: f32,
prev_touched_ticks: HashMap<u32, u64>,
car_id_map: HashMap<u32, i32>,
on_ground_vec: Vec<bool>,
}

impl RocketsimWrapper {
Expand Down Expand Up @@ -96,6 +97,10 @@ impl RocketsimWrapper {
}
}

// init on_ground array
let num_cars = if config.spawn_opponents { config.team_size * 2 } else { config.team_size };
let on_ground_vec = vec![false; num_cars];

// init stats
Self::STATS.with(|stats| {
let mut guard = stats.write().unwrap();
Expand Down Expand Up @@ -243,6 +248,7 @@ impl RocketsimWrapper {
jump_timer: 1.25,
prev_touched_ticks: HashMap::new(),
car_id_map,
on_ground_vec,
}
}

Expand Down Expand Up @@ -646,6 +652,17 @@ impl RocketsimWrapper {
// self.decode_gamestate(&rlsim_gamestate)
}

fn check_on_ground(&mut self) {
let new_iter = self.arena
.get_cars()
.into_iter()
.map(|id| self.arena.pin_mut().get_car(id).is_on_ground);

for (on_ground_arr, on_ground_new) in self.on_ground_vec.iter_mut().zip(new_iter) {
*on_ground_arr = *on_ground_arr || on_ground_new;
}
}

/// clone actions before this to set prev_acts
pub fn step(&mut self, actions: Vec<Vec<f32>>, get_sim_state: bool) -> (GameState_rlgym, Option<Vec<GameState_sim>>) {
let mut acts = Vec::<(u32, CarControls)>::new();
Expand All @@ -669,8 +686,12 @@ impl RocketsimWrapper {

self.arena.pin_mut().set_all_controls(&acts).unwrap();

self.on_ground_vec.fill(false);

self.arena.pin_mut().step(1);

self.check_on_ground();

let (gamestate_rlgym, gamestate_sim) = self.get_rlgym_gamestate(get_sim_state);

// originally was here
Expand All @@ -684,14 +705,18 @@ impl RocketsimWrapper {
if self.tick_skip > 1 {
for _ in 0..self.tick_skip-1 {
self.arena.pin_mut().step(1);
self.check_on_ground();
gamestate_sim_vec.push(self.arena.pin_mut().get_game_state());
}
}

(gamestate_rlgym, Some(gamestate_sim_vec))
} else {
if self.tick_skip > 1 {
self.arena.pin_mut().step((self.tick_skip - 1) as u32);
for _ in 0..self.tick_skip-1 {
self.arena.pin_mut().step(1);
self.check_on_ground();
}
}

(gamestate_rlgym, None)
Expand Down

0 comments on commit 9bd4b7e

Please sign in to comment.