Skip to content

Commit

Permalink
Update rl_ball_sym & add Heatseeker
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jun 14, 2024
1 parent 2727577 commit 29d3545
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[package]
name = "rl_ball_sym_dll"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

[lib]
name = "rl_ball_sym"
crate-type = ["cdylib", "staticlib"]

[dependencies.rl_ball_sym]
version = "4.0.0"
default-features = false
features = ["compression", "standard", "hoops", "dropshot", "throwback"]
[dependencies]
rl_ball_sym = { version = "4.1.0", features = ["compression"] }

[profile.release]
codegen-units=1
Expand Down
28 changes: 26 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use rl_ball_sym::{Ball, Game, Vec3A};
use std::sync::RwLock;
use std::sync::{
atomic::{AtomicBool, Ordering},
RwLock,
};

const TPS: usize = 120;
const DT: f32 = 1.0 / TPS as f32;

static GAME: RwLock<Option<Game>> = RwLock::new(None);
static BALL: RwLock<Ball> = RwLock::new(Ball::const_default());
static HEATSEEKER: AtomicBool = AtomicBool::new(false);

fn set_game_and_ball((game, ball): (Game, Ball)) {
let mut game_lock = GAME.write().unwrap();
Expand All @@ -15,24 +19,34 @@ fn set_game_and_ball((game, ball): (Game, Ball)) {
*ball_lock = ball;
}

#[no_mangle]
pub extern "C" fn load_heatseeker() {
set_game_and_ball(rl_ball_sym::load_standard_heatseeker());
HEATSEEKER.store(true, Ordering::Relaxed);
}

#[no_mangle]
pub extern "C" fn load_standard() {
set_game_and_ball(rl_ball_sym::load_standard());
HEATSEEKER.store(false, Ordering::Relaxed);
}

#[no_mangle]
pub extern "C" fn load_dropshot() {
set_game_and_ball(rl_ball_sym::load_dropshot());
HEATSEEKER.store(false, Ordering::Relaxed);
}

#[no_mangle]
pub extern "C" fn load_hoops() {
set_game_and_ball(rl_ball_sym::load_hoops());
HEATSEEKER.store(false, Ordering::Relaxed);
}

#[no_mangle]
pub extern "C" fn load_standard_throwback() {
set_game_and_ball(rl_ball_sym::load_standard_throwback());
HEATSEEKER.store(false, Ordering::Relaxed);
}

#[repr(C)]
Expand Down Expand Up @@ -82,6 +96,12 @@ impl From<Ball> for BallSlice {
}
}

#[no_mangle]
pub extern "C" fn set_heatseeker_target(blue_goal: u8) {
let mut ball = *BALL.write().unwrap();
ball.set_heatseeker_target(blue_goal == 1);
}

#[no_mangle]
pub extern "C" fn step(current_ball: BallSlice) -> BallSlice {
let game_lock = GAME.read().unwrap();
Expand All @@ -98,6 +118,10 @@ pub extern "C" fn step(current_ball: BallSlice) -> BallSlice {
current_ball.angular_velocity.into(),
);

ball.step(game, DT);
if HEATSEEKER.load(Ordering::Relaxed) {
ball.step_heatseeker(game, DT);
} else {
ball.step(game, DT);
}
ball.into()
}

0 comments on commit 29d3545

Please sign in to comment.