From 8fb1b0ae181223367dbb48edfc43e46739ae94d1 Mon Sep 17 00:00:00 2001 From: VirxEC Date: Fri, 5 Jul 2024 00:36:05 -0400 Subject: [PATCH] Update to newest RocketSim --- Cargo.toml | 2 +- README.md | 7 ++++--- RocketSim | 2 +- arenar/arenar.cpp | 4 ++-- arenar/arenar.h | 2 +- examples/ball_bench.rs | 2 +- examples/basic_loop.rs | 2 +- examples/cpu_bench.rs | 2 +- examples/dump_ball.rs | 2 +- examples/real_bench.rs | 2 +- examples/rlviser_socket.rs | 2 +- examples/specific.rs | 2 +- examples/stat_tracker.rs | 2 +- examples/thread_bench.rs | 2 +- generate_consts.py | 26 +++++++++++++++++++++++--- src/consts.rs | 36 ++++++++++++++++++++++++++---------- src/ext.rs | 3 ++- src/lib.rs | 6 +++--- src/sim/mutator_config.rs | 3 ++- tests/unit.rs | 16 ++++++++-------- 20 files changed, 82 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1df118..69ea2d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rocketsim_rs" description = "Rust bindings for the RocketSim project" -version = "0.31.0" +version = "0.32.0" edition = "2021" license = "MIT" repository = "https://github.com/VirxEC/rocketsim-rs" diff --git a/README.md b/README.md index eb227b3..e25b1e1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ use rocketsim_rs::{ use std::time::Instant; // Load in the Rocket League assets from the collision_meshes folder in the current directory -rocketsim_rs::init(None); +rocketsim_rs::init(None, true); // Create a new arena with gamemode soccar and a tick rate of 120 let mut arena = Arena::default_standard(); @@ -107,10 +107,11 @@ Numbers _will_ vary depending on your system. Only default features are enabled. ``` - `cpu_bench`: + ```bash Running on 24 threads - Simulated 55.56 hours in 1.039 seconds - FPS: 23091926 + Simulated 55.56 hours in 0.907 seconds + FPS: 26474106 ``` - `thread_bench` (1 thread): diff --git a/RocketSim b/RocketSim index 0da0546..a142906 160000 --- a/RocketSim +++ b/RocketSim @@ -1 +1 @@ -Subproject commit 0da054634553b16745e56d9242c25280edf93823 +Subproject commit a142906a00029601db189b1ceaf3b0aa831ac1e5 diff --git a/arenar/arenar.cpp b/arenar/arenar.cpp index 83df3d9..eba6a7a 100644 --- a/arenar/arenar.cpp +++ b/arenar/arenar.cpp @@ -26,8 +26,8 @@ const CarConfig& getMerc() { return CAR_CONFIG_MERC; } -void Init(rust::Str collision_meshes_folder) { - RocketSim::Init(std::filesystem::path(std::string(collision_meshes_folder))); +void Init(rust::Str collision_meshes_folder, bool silent) { + RocketSim::Init(std::filesystem::path(std::string(collision_meshes_folder)), silent); } void InitFromMem(rust::Slice> soccar, rust::Slice> hoops) { diff --git a/arenar/arenar.h b/arenar/arenar.h index 3cb9235..fd4be1a 100644 --- a/arenar/arenar.h +++ b/arenar/arenar.h @@ -12,7 +12,7 @@ const CarConfig& getBreakout(); const CarConfig& getHybrid(); const CarConfig& getMerc(); -void Init(rust::Str collision_meshes_folder); +void Init(rust::Str collision_meshes_folder, bool silent); void InitFromMem(rust::Slice> soccar, rust::Slice> hoops); Angle AngleFromRotMat(RotMat mat); diff --git a/examples/ball_bench.rs b/examples/ball_bench.rs index a9c136d..b585fa0 100644 --- a/examples/ball_bench.rs +++ b/examples/ball_bench.rs @@ -5,7 +5,7 @@ fn main() { const RUNS: usize = 10000; const SECONDS_PER_RUN: u32 = 8; - rocketsim_rs::init(None); + rocketsim_rs::init(None, false); let mut arena = Arena::default_standard(); let mut times = Vec::with_capacity(RUNS); diff --git a/examples/basic_loop.rs b/examples/basic_loop.rs index 131e9e4..8101bce 100644 --- a/examples/basic_loop.rs +++ b/examples/basic_loop.rs @@ -4,7 +4,7 @@ const TICK_SKIP: u32 = 8; fn main() { // Load in the Rocket League assets from the collision_meshes folder in the current directory - rocketsim_rs::init(None); + rocketsim_rs::init(None, false); // Create a new arena with gamemode soccar and a tick rate of 120 let mut arena = Arena::default_standard(); diff --git a/examples/cpu_bench.rs b/examples/cpu_bench.rs index 6058870..c25be19 100644 --- a/examples/cpu_bench.rs +++ b/examples/cpu_bench.rs @@ -7,7 +7,7 @@ use std::{ fn main() { const TICKS: u32 = 1_000_000; - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); let num_cpu = available_parallelism().unwrap().get(); diff --git a/examples/dump_ball.rs b/examples/dump_ball.rs index 514959c..3355e31 100644 --- a/examples/dump_ball.rs +++ b/examples/dump_ball.rs @@ -22,7 +22,7 @@ fn write_ball(file: &mut fs::File, ball: BallState, time: f32) -> io::Result<()> } fn main() -> io::Result<()> { - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); let mut arena = Arena::default_standard(); let mut ball = arena.pin_mut().get_ball(); diff --git a/examples/real_bench.rs b/examples/real_bench.rs index cc4e886..78c6e6b 100644 --- a/examples/real_bench.rs +++ b/examples/real_bench.rs @@ -8,7 +8,7 @@ fn main() { const TICKS: u32 = 200_000; // load in assets - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); let num_cpu = available_parallelism().unwrap().get(); diff --git a/examples/rlviser_socket.rs b/examples/rlviser_socket.rs index 523363f..42c7dfa 100644 --- a/examples/rlviser_socket.rs +++ b/examples/rlviser_socket.rs @@ -63,7 +63,7 @@ fn ctrl_channel() -> Result, ctrlc::Error> { fn main() -> io::Result<()> { // Load rocketsim - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); let mut args = std::env::args(); let _ = args.next(); diff --git a/examples/specific.rs b/examples/specific.rs index ddc205b..a8f6402 100644 --- a/examples/specific.rs +++ b/examples/specific.rs @@ -6,7 +6,7 @@ use std::time::Instant; fn main() { // Load in the Rocket League assets from the collision_meshes folder in the current directory - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); // Create a new arena with gamemode soccar and a tick rate of 120 let mut arena = Arena::default_standard(); diff --git a/examples/stat_tracker.rs b/examples/stat_tracker.rs index 5b787e9..756d479 100644 --- a/examples/stat_tracker.rs +++ b/examples/stat_tracker.rs @@ -20,7 +20,7 @@ fn main() { static SCORE: Mutex<[u16; 2]> = Mutex::new([0; 2]); // Load in the Rocket League assets from the collision_meshes folder in the current directory - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); // Create a new arena with gamemode soccar and a tick rate of 120 let mut arena = Arena::default_standard(); diff --git a/examples/thread_bench.rs b/examples/thread_bench.rs index 725e55f..b6220a0 100644 --- a/examples/thread_bench.rs +++ b/examples/thread_bench.rs @@ -5,7 +5,7 @@ fn main() { const TICKS: u32 = 1_000_000; // load in assets - rocketsim_rs::init(None); + rocketsim_rs::init(None, true); let mut arena = Arena::default_standard(); diff --git a/generate_consts.py b/generate_consts.py index 7a900f2..39d357a 100644 --- a/generate_consts.py +++ b/generate_consts.py @@ -1,7 +1,10 @@ +import re + # read RocketSim/src/RLConst.h and generate src/consts.rs -def ensure_rust_float(val): +def ensure_rust_float(val: str): try: + val = val.strip() if str(int(val)) == val: val += "." except ValueError: @@ -145,6 +148,8 @@ def to_linear_piece_curve_str(vals, indent): if const_type == "float": if items[1] == "M_SQRT1_2": items[1] = "FRAC_1_SQRT_2" + else: + items[1] = items[1].replace("M_PI", "PI") if items[1].startswith("(") and items[1].endswith(")"): items[1] = items[1].removeprefix("(").removesuffix(")") @@ -153,10 +158,22 @@ def to_linear_piece_curve_str(vals, indent): for i, valz in enumerate(vals): if valz == "/": continue + elif valz == "<<": + vals[i+1] = vals[i+1] + " as f32" + continue vals[i] = ensure_rust_float(valz) - items[1] = " ".join(vals) + + vals = items[1].split("/") + for i, valz in enumerate(vals): + if valz == "/": + continue + + vals[i] = ensure_rust_float(valz) + + items[1] = " / ".join(vals) + elif const_type == "Vec": vals = items[1].removeprefix("Vec(").removesuffix(")").split(", ") @@ -176,7 +193,7 @@ def to_linear_piece_curve_str(vals, indent): "// This file was generated by generate_consts.py", "", "use crate::{math::Vec3, CarSpawnPos, LinearPieceCurve};", - "use std::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_4};", + "use std::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_4, PI};", "", ] @@ -200,6 +217,9 @@ def to_linear_piece_curve_str(vals, indent): if namespace in {"boostpads", "heatseeker"}: consts_rs.append(f"{indent}use crate::math::Vec3;") + + if namespace == "heatseeker": + consts_rs.append(f"{indent}use std::f32::consts::PI;") consts_rs.append("") for raw_item_type, vars in types.items(): diff --git a/src/consts.rs b/src/consts.rs index 9d3b145..b52fbd4 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,7 +1,7 @@ // This file was generated by generate_consts.py use crate::{math::Vec3, CarSpawnPos, LinearPieceCurve}; -use std::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_4}; +use std::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_4, PI}; pub const GRAVITY_Z: f32 = -650.; pub const ARENA_EXTENT_X: f32 = 4096.; @@ -39,10 +39,11 @@ pub const BOOST_MAX: f32 = 100.; pub const BOOST_USED_PER_SECOND: f32 = BOOST_MAX / 3.; /// Minimum time we can be boosting for pub const BOOST_MIN_TIME: f32 = 0.1; -pub const BOOST_ACCEL: f32 = 21.2; +/// uu/s for vel (on the ground) +pub const BOOST_ACCEL_GROUND: f32 = 2975. / 3.; +/// uu/s for vel (airborne) +pub const BOOST_ACCEL_AIR: f32 = 3175. / 3.; pub const BOOST_SPAWN_AMOUNT: f32 = BOOST_MAX / 3.; -pub const BOOST_ACCEL_GROUND_DECAY_MIN_VEL: f32 = 600.; -pub const BOOST_ACCEL_GROUND_DECAY_AMOUNT: f32 = 0.072; /// Car can never exceed this angular velocity (radians/s) pub const CAR_MAX_ANG_SPEED: f32 = 5.5; pub const SUPERSONIC_START_SPEED: f32 = 2200.; @@ -58,7 +59,7 @@ pub const STOPPING_FORWARD_VEL: f32 = 25.; pub const COASTING_BRAKE_FACTOR: f32 = 0.15; /// Throttle input of less than this is ignored pub const THROTTLE_DEADZONE: f32 = 0.001; -pub const THROTTLE_AIR_FORCE: f32 = 1. / 0.75; +pub const THROTTLE_AIR_ACCEL: f32 = 200. / 3.; pub const JUMP_ACCEL: f32 = 4375. / 3.; pub const JUMP_IMMEDIATE_FORCE: f32 = 875. / 3.; pub const JUMP_MIN_TIME: f32 = 0.025; @@ -87,7 +88,7 @@ pub const BALL_COLLISION_RADIUS_HOOPS: f32 = 96.3831; pub const BALL_COLLISION_RADIUS_DROPSHOT: f32 = 100.2565; pub const SOCCAR_GOAL_SCORE_BASE_THRESHOLD_Y: f32 = 5124.25; pub const HOOPS_GOAL_SCORE_THRESHOLD_Z: f32 = 270.; -pub const CAR_TORQUE_SCALE: f32 = 0.09587; +pub const CAR_TORQUE_SCALE: f32 = 2. * PI / (1 << 16) as f32 * 1000.; pub const CAR_AUTOFLIP_IMPULSE: f32 = 200.; pub const CAR_AUTOFLIP_TORQUE: f32 = 50.; pub const CAR_AUTOFLIP_TIME: f32 = 0.4; @@ -108,6 +109,7 @@ pub const DEMO_RESPAWN_TIME: f32 = 3.; pub const CAR_AIR_CONTROL_TORQUE: Vec3 = Vec3::new(130., 95., 400.); pub const CAR_AIR_CONTROL_DAMPING: Vec3 = Vec3::new(30., 20., 50.); pub const CAR_SPAWN_LOCATION_AMOUNT: i32 = 5; +pub const CAR_SPAWN_LOCATION_AMOUNT_HEATSEEKER: i32 = 4; pub const CAR_RESPAWN_LOCATION_AMOUNT: i32 = 4; pub const CAR_SPAWN_LOCATIONS_SOCCAR: [CarSpawnPos; CAR_SPAWN_LOCATION_AMOUNT as usize] = [ CarSpawnPos::new(-2560., -2560., FRAC_PI_4 * 1.), @@ -123,6 +125,12 @@ pub const CAR_SPAWN_LOCATIONS_HOOPS: [CarSpawnPos; CAR_SPAWN_LOCATION_AMOUNT as CarSpawnPos::new(-2816., -2816., FRAC_PI_4 * 2.), CarSpawnPos::new(-3200., -3200., FRAC_PI_4 * 2.), ]; +pub const CAR_SPAWN_LOCATIONS_HEATSEEKER: [CarSpawnPos; CAR_SPAWN_LOCATION_AMOUNT_HEATSEEKER as usize] = [ + CarSpawnPos::new(-4620., -4620., FRAC_PI_2), + CarSpawnPos::new(-4620., -4620., FRAC_PI_2), + CarSpawnPos::new(-4620., -4620., FRAC_PI_2), + CarSpawnPos::new(-4620., -4620., FRAC_PI_2), +]; pub const CAR_RESPAWN_LOCATIONS_SOCCAR: [CarSpawnPos; CAR_RESPAWN_LOCATION_AMOUNT as usize] = [ CarSpawnPos::new(-4608., -4608., FRAC_PI_2), CarSpawnPos::new(-4608., -4608., FRAC_PI_2), @@ -190,6 +198,7 @@ pub mod btvehicle { pub mod heatseeker { use crate::math::Vec3; + use std::f32::consts::PI; /// TODO: Verify pub const INITIAL_TARGET_SPEED: f32 = 2900.; @@ -207,11 +216,18 @@ pub mod heatseeker { pub const VERTICAL_BLEND: f32 = 0.78; /// Interpolation of acceleration towards target speed pub const SPEED_BLEND: f32 = 0.3; - pub const MAX_TURN_PITCH: f32 = 0.671; - /// Different from BALL_MAX_SPEED + /// Maximum pitch angle of turning + pub const MAX_TURN_PITCH: f32 = 7000. * PI / (1 << 15) as f32; + /// Maximum speed the ball can seek at (different from BALL_MAX_SPEED) pub const MAX_SPEED: f32 = 4600.; - /// Threshold of wall collision normal Y to change goal targets - pub const WALL_BOUNCE_CHANGE_NORMAL_Y: f32 = 0.75; + /// Threshold of wall collision Y backwall distance to change goal targets + pub const WALL_BOUNCE_CHANGE_Y_THRESH: f32 = 300.; + /// Threshold of Y normal to trigger bounce-back + pub const WALL_BOUNCE_CHANGE_Y_NORMAL: f32 = 0.5; + /// Scale of the extra wall bounce impulse (TODO: ???) + pub const WALL_BOUNCE_FORCE_SCALE: f32 = 1. / 3.; + /// Fraction of upward bounce impulse that goes straight up + pub const WALL_BOUNCE_UP_FRAC: f32 = 0.3; pub const BALL_START_POS: Vec3 = Vec3::new(-1000., -2220., 92.75); pub const BALL_START_VEL: Vec3 = Vec3::new(0., -65., 650.); } diff --git a/src/ext.rs b/src/ext.rs index cbd25ce..162d835 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -94,7 +94,8 @@ impl MutatorConfig { }, jump_accel: consts::JUMP_ACCEL, jump_immediate_force: consts::JUMP_IMMEDIATE_FORCE, - boost_accel: consts::BOOST_ACCEL, + boost_accel_ground: consts::BOOST_ACCEL_GROUND, + boost_accel_air: consts::BOOST_ACCEL_AIR, boost_used_per_second: consts::BOOST_USED_PER_SECOND, respawn_delay: consts::DEMO_RESPAWN_TIME, bump_cooldown_time: consts::BUMP_COOLDOWN_TIME, diff --git a/src/lib.rs b/src/lib.rs index dd7f010..1ed66c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ mod base { #[cxx_name = "GetStage"] pub fn get_stage() -> RocketSimStage; - fn Init(folder: &str); + fn Init(folder: &str, silent: bool); /// Initializes the collision mesh system for `RocketSim` from memory #[cxx_name = "InitFromMem"] @@ -103,6 +103,6 @@ pub use base::{get_stage, init_from_mem}; #[inline] /// Initializes the collision mesh system for `RocketSim` -pub fn init(collision_meshes_folder: Option<&str>) { - base::Init(collision_meshes_folder.unwrap_or("collision_meshes")); +pub fn init(collision_meshes_folder: Option<&str>, silent: bool) { + base::Init(collision_meshes_folder.unwrap_or("collision_meshes"), silent); } diff --git a/src/sim/mutator_config.rs b/src/sim/mutator_config.rs index 0b14c36..7d8d5c4 100644 --- a/src/sim/mutator_config.rs +++ b/src/sim/mutator_config.rs @@ -40,7 +40,8 @@ mod base { ball_world_restitution: f32, jump_accel: f32, jump_immediate_force: f32, - boost_accel: f32, + boost_accel_ground: f32, + boost_accel_air: f32, boost_used_per_second: f32, respawn_delay: f32, bump_cooldown_time: f32, diff --git a/tests/unit.rs b/tests/unit.rs index 52269f9..ad8e801 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -18,7 +18,7 @@ static INIT: Once = Once::new(); #[test] fn pads() { - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let arena = Arena::default_standard(); let statics = arena.iter_pad_config().collect::>(); @@ -30,7 +30,7 @@ fn pads() { #[test] fn cars() { - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); let car_id = arena.pin_mut().add_car(Team::Blue, CarConfig::octane()); @@ -76,7 +76,7 @@ fn cars() { #[test] fn ball() { - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); arena.pin_mut().set_ball(BallState { @@ -111,7 +111,7 @@ fn ball() { #[test] fn game_state() { - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); let _ = arena.pin_mut().add_car(Team::Orange, CarConfig::breakout()); let _ = arena.pin_mut().add_car(Team::Blue, CarConfig::hybrid()); @@ -138,7 +138,7 @@ fn game_state() { #[test] fn angles() { - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); let ids = [ arena.pin_mut().add_car(Team::Orange, CarConfig::breakout()), @@ -174,7 +174,7 @@ fn angles() { #[test] fn goal_score() { static SCORED: AtomicBool = AtomicBool::new(false); - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); arena.pin_mut().set_ball(BallState { @@ -200,7 +200,7 @@ fn goal_score() { #[test] fn demoed() { static DEMOED: AtomicBool = AtomicBool::new(false); - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); // set up two cars, one demoing the other @@ -324,7 +324,7 @@ fn demoed() { fn game_state_serialize() { use serde_json; - INIT.call_once(|| init(None)); + INIT.call_once(|| init(None, true)); let mut arena = Arena::default_standard(); let _ = arena.pin_mut().add_car(Team::Orange, CarConfig::breakout()); let _ = arena.pin_mut().add_car(Team::Blue, CarConfig::hybrid());