Skip to content

Commit

Permalink
update rand
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 23, 2024
1 parent 525f0f6 commit 527496a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 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.

4 changes: 2 additions & 2 deletions gamercade_console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ bytemuck = "1.15.0"
# Scripting
wasmtime = "20.0.0"

# Random TODO Update This
fastrand = "1.9.0"
# Random
fastrand = "2.0.2"

# Audio
cpal = "0.15.3"
Expand Down
8 changes: 4 additions & 4 deletions gamercade_console/src/api/random_api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub trait RandomApi {
fn set_seed(&self, seed: i32);
fn set_seed(&mut self, seed: i32);

fn random_int_range(&self, min: i32, max: i32) -> i32;
fn random_int_range(&mut self, min: i32, max: i32) -> i32;

fn random_float(&self) -> f32;
fn random_float_range(&self, min: f32, max: f32) -> f32;
fn random_float(&mut self) -> f32;
fn random_float_range(&mut self, min: f32, max: f32) -> f32;
}

macro_rules! derive_bind_random_api {
Expand Down
4 changes: 2 additions & 2 deletions gamercade_console/src/console/bindings/random_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ macro_rules! derive_random_api_binding {
self.func_wrap(
"env",
stringify!($ident),
|caller: Caller<'_, Contexts>, $($name: $args,)*| {
caller.data().random_context.$ident($($name,)*)
|mut caller: Caller<'_, Contexts>, $($name: $args,)*| {
caller.data_mut().random_context.$ident($($name,)*)
}).unwrap();
}
)*
Expand Down
8 changes: 4 additions & 4 deletions gamercade_console/src/console/contexts/random_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ impl RandomContext {
}

impl RandomApi for RandomContext {
fn set_seed(&self, seed: i32) {
fn set_seed(&mut self, seed: i32) {
self.shared_rng.seed(seed as u64);
}

fn random_int_range(&self, min: i32, max: i32) -> i32 {
fn random_int_range(&mut self, min: i32, max: i32) -> i32 {
self.shared_rng.i32(min..max)
}

fn random_float(&self) -> f32 {
fn random_float(&mut self) -> f32 {
self.shared_rng.f32()
}

fn random_float_range(&self, min: f32, max: f32) -> f32 {
fn random_float_range(&mut self, min: f32, max: f32) -> f32 {
let range = max - min;
let scale = self.shared_rng.f32() * max;
(scale * range) + min
Expand Down

0 comments on commit 527496a

Please sign in to comment.