From dc62ba44675b8ece88adbf995d0e0f2ca460dfb8 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 11 Apr 2022 22:07:31 +0100 Subject: [PATCH] Rename rng::next to rng::gen --- agb/src/hash_map.rs | 6 +++--- agb/src/rng.rs | 10 +++++----- examples/the-purple-night/src/main.rs | 22 +++++++++++----------- examples/the-purple-night/src/sfx.rs | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index e6e98532..56bfa062 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -961,9 +961,9 @@ mod test { let mut answers: [Option; 128] = [None; 128]; for _ in 0..5_000 { - let command = rng.next().rem_euclid(2); - let key = rng.next().rem_euclid(answers.len() as i32); - let value = rng.next(); + let command = rng.gen().rem_euclid(2); + let key = rng.gen().rem_euclid(answers.len() as i32); + let value = rng.gen(); match command { 0 => { diff --git a/agb/src/rng.rs b/agb/src/rng.rs index bbbc2ae3..8d73a819 100644 --- a/agb/src/rng.rs +++ b/agb/src/rng.rs @@ -32,7 +32,7 @@ impl RandomNumberGenerator { } /// Returns the next value for the random number generator - pub fn next(&mut self) -> i32 { + pub fn gen(&mut self) -> i32 { let result = (self.state[0].wrapping_add(self.state[3])) .rotate_left(7) .wrapping_mul(9); @@ -54,8 +54,8 @@ static GLOBAL_RNG: Mutex> = Mutex::new(RefCell::new(RandomNumberGenerator::new())); /// Using a global random number generator, provides the next random number -pub fn next() -> i32 { - free(|cs| GLOBAL_RNG.borrow(*cs).borrow_mut().next()) +pub fn gen() -> i32 { + free(|cs| GLOBAL_RNG.borrow(*cs).borrow_mut().gen()) } #[cfg(test)] @@ -69,7 +69,7 @@ mod test { let mut rng = RandomNumberGenerator::new(); for _ in 0..500 { - values[(rng.next().rem_euclid(16)) as usize] += 1; + values[(rng.gen().rem_euclid(16)) as usize] += 1; } for (i, &value) in values.iter().enumerate() { @@ -87,7 +87,7 @@ mod test { let mut values: [u32; 16] = Default::default(); for _ in 0..500 { - values[super::next().rem_euclid(16) as usize] += 1; + values[super::gen().rem_euclid(16) as usize] += 1; } for (i, &value) in values.iter().enumerate() { diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index e4e8d516..388d02d6 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -1115,7 +1115,7 @@ impl MiniFlameData { self.sprite_offset = 0; self.state = MiniFlameState::Dead; - if rng::next() % 4 == 0 { + if rng::gen() % 4 == 0 { instruction = UpdateInstruction::CreateParticle( ParticleData::new_health(), entity.position, @@ -1138,7 +1138,7 @@ impl MiniFlameData { self.sprite_offset = 0; self.state = MiniFlameState::Dead; - if rng::next() % 4 == 0 { + if rng::gen() % 4 == 0 { instruction = UpdateInstruction::CreateParticle( ParticleData::new_health(), entity.position, @@ -1703,7 +1703,7 @@ impl<'a> Boss<'a> { Self { entity, health: 5, - target_location: rng::next().rem_euclid(5) as u8, + target_location: rng::gen().rem_euclid(5) as u8, state: BossActiveState::Damaged(60), timer: 0, screen_coords, @@ -1804,9 +1804,9 @@ impl<'a> Boss<'a> { fn commit(&mut self, offset: Vector2D) { let shake = if self.shake_magnitude != 0.into() { ( - Number::from_raw(rng::next()).rem_euclid(self.shake_magnitude) + Number::from_raw(rng::gen()).rem_euclid(self.shake_magnitude) - self.shake_magnitude / 2, - Number::from_raw(rng::next()).rem_euclid(self.shake_magnitude) + Number::from_raw(rng::gen()).rem_euclid(self.shake_magnitude) - self.shake_magnitude / 2, ) .into() @@ -1819,8 +1819,8 @@ impl<'a> Boss<'a> { } fn explode(&self, enemies: &mut Arena>, object_controller: &'a ObjectController) { for _ in 0..(6 - self.health) { - let x_offset: Number = Number::from_raw(rng::next()).rem_euclid(2.into()) - 1; - let y_offset: Number = Number::from_raw(rng::next()).rem_euclid(2.into()) - 1; + let x_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1; + let y_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1; let mut flame = Enemy::new( object_controller, EnemyData::MiniFlame(MiniFlameData::new()), @@ -1833,7 +1833,7 @@ impl<'a> Boss<'a> { fn get_next_target_location(&self) -> u8 { loop { - let a = rng::next().rem_euclid(5) as u8; + let a = rng::gen().rem_euclid(5) as u8; if a != self.target_location { break a; } @@ -1978,8 +1978,8 @@ impl<'a> Game<'a> { if self.shake_time > 0 { let size = self.shake_time.min(4) as i32; let offset: Vector2D = ( - Number::from_raw(rng::next()) % size - Number::new(size) / 2, - Number::from_raw(rng::next()) % size - Number::new(size) / 2, + Number::from_raw(rng::gen()) % size - Number::new(size) / 2, + Number::from_raw(rng::gen()) % size - Number::new(size) / 2, ) .into(); this_frame_offset += offset; @@ -2296,7 +2296,7 @@ fn game_with_level(gba: &mut agb::Gba) { } } - rng::next(); // advance RNG to make it less predictable between runs + rng::gen(); // advance RNG to make it less predictable between runs }; game.clear(&mut vram); diff --git a/examples/the-purple-night/src/sfx.rs b/examples/the-purple-night/src/sfx.rs index 544e09c7..d7f6d089 100644 --- a/examples/the-purple-night/src/sfx.rs +++ b/examples/the-purple-night/src/sfx.rs @@ -85,7 +85,7 @@ impl<'a> Sfx<'a> { } pub fn jump(&mut self) { - let r = rng::next() % 3; + let r = rng::gen() % 3; let channel = match r { 0 => SoundChannel::new(JUMP1),