Skip to content

Commit aa596f4

Browse files
committed
misc; apply clippy lints
1 parent eb75b2f commit aa596f4

21 files changed

Lines changed: 58 additions & 85 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/components/input.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl ButtonState {
5353
}
5454
}
5555

56+
#[derive(Default)]
5657
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
5758
pub struct Input {
5859
external: ButtonState,
@@ -82,17 +83,12 @@ impl Input {
8283
pub fn load_replay(&mut self, file: Vec<u8>) {
8384
self.replay = ReplayState::Playback(InputReplay::load(String::from_utf8(file).unwrap()));
8485
}
85-
86-
pub fn new() -> Self {
87-
Self {
88-
external: ButtonState::default(),
89-
replay: ReplayState::None,
90-
}
91-
}
9286
}
9387

88+
#[derive(Default)]
9489
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9590
pub enum ReplayState {
91+
#[default]
9692
None,
9793
Recording(InputReplay),
9894
Playback(InputReplay),
@@ -142,7 +138,7 @@ impl InputReplay {
142138
.unwrap_or_default()
143139
}
144140

145-
pub fn to_string(&self) -> String {
141+
pub fn serialize(&self) -> String {
146142
self.states.iter().fold(
147143
format!("{}\n", self.file.to_str().unwrap()),
148144
|mut acc, e| {

common/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Default for EmulateOptions {
3131
rom_loaded: false,
3232
invert_audio_samples: false,
3333
speed_multiplier: 1,
34-
input: Input::new(),
34+
input: Input::default(),
3535
}
3636
}
3737
}

components/arm-cpu/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod lut;
2020
pub mod registers;
2121
mod waitloop;
2222

23-
use std::{sync::Arc, u8};
23+
use std::sync::Arc;
2424

2525
use access::{CODE, NONSEQ, SEQ};
2626
use common::{components::debugger::Severity, numutil::NumExt};
@@ -76,17 +76,17 @@ impl<S: ArmSystem> Cpu<S> {
7676
return;
7777
}
7878

79-
let mut gg = SysWrapper::new(gg);
79+
let gg = SysWrapper::new(gg);
8080
if gg.cpu().cache.enabled {
8181
if let Some(cache) = gg.cpu().cache.get(pc) {
82-
Cpu::run_cache(&mut gg, cache);
82+
Cpu::run_cache(gg, cache);
8383
return;
8484
} else if S::can_cache_at(pc) {
85-
Cpu::try_make_cache(&mut gg);
85+
Cpu::try_make_cache(gg);
8686
return;
8787
}
8888
}
89-
Self::execute_next_inst(&mut gg);
89+
Self::execute_next_inst(gg);
9090
}
9191

9292
/// Execute the next instruction and advance the scheduler.
@@ -266,8 +266,7 @@ impl<S: ArmSystem> Cpu<S> {
266266
pub fn check_if_interrupt(gg: &mut S) {
267267
if gg.cpur().is_interrupt_pending() {
268268
gg.cpu().inc_pc_by(4);
269-
let mut wrapper = SysWrapper::new(gg);
270-
Cpu::exception_occurred(&mut wrapper, Exception::Irq);
269+
Cpu::exception_occurred(SysWrapper::new(gg), Exception::Irq);
271270
}
272271
}
273272

cores/gga/src/audio/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ impl Apu {
133133
a = (mplayer[0] * 512.) as i16 * a_vol_mul;
134134
b = (mplayer[1] * 512.) as i16 * b_vol_mul;
135135
} else {
136-
a = self.current_samples[0] as i16 * a_vol_mul * 2;
137-
b = self.current_samples[1] as i16 * b_vol_mul * 2;
136+
a = self.current_samples[0] * a_vol_mul * 2;
137+
b = self.current_samples[1] * b_vol_mul * 2;
138138
}
139139

140140
if cnt.a_right_en() {
@@ -167,11 +167,7 @@ impl Apu {
167167

168168
fn bias(mut sample: i16, bias: i16) -> i16 {
169169
sample += bias;
170-
if sample > 0x3ff {
171-
sample = 0x3ff;
172-
} else if sample < 0 {
173-
sample = 0;
174-
}
170+
sample = sample.clamp(0, 0x3ff);
175171
sample -= bias;
176172
sample
177173
}

cores/gga/src/audio/mplayer.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn find_mp2k(rom: &[u8]) -> Option<u32> {
5858
}
5959
}
6060

61-
return !crc;
61+
!crc
6262
}
6363

6464
const CRC32: u32 = 0x27EA7FCF;
@@ -393,21 +393,19 @@ impl MusicPlayer {
393393
sampler.should_fetch_sample = false;
394394
}
395395

396-
let sample;
397396
let mu = sampler.resample_phase;
398-
399-
if self.use_cubic_filter {
397+
let sample = if self.use_cubic_filter {
400398
// http://paulbourke.net/miscellaneous/interpolation/
401399
let mu2 = mu * mu;
402400
let a0 = sample_history[0] - sample_history[1] - sample_history[3]
403401
+ sample_history[2];
404402
let a1 = sample_history[3] - sample_history[2] - a0;
405403
let a2 = sample_history[1] - sample_history[3];
406404
let a3 = sample_history[2];
407-
sample = a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3;
405+
a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3
408406
} else {
409-
sample = sample_history[0] * mu + sample_history[1] * (1.0 - mu);
410-
}
407+
sample_history[0] * mu + sample_history[1] * (1.0 - mu)
408+
};
411409

412410
self.buffer[destination + (j * 2 + 0) as usize] += sample * volume_r;
413411
self.buffer[destination + (j * 2 + 1) as usize] += sample * volume_l;
@@ -495,7 +493,7 @@ impl MusicPlayer {
495493
self.buffer_read_index = 0;
496494
}
497495

498-
return [sample[0], sample[1]];
496+
[sample[0], sample[1]]
499497
}
500498
}
501499

cores/gga/src/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ impl GameGirlAdv {
402402

403403
// Treat as halfword
404404
_ if addr.is_bit(0) => {
405-
self.set::<u16>(addr, Self::get::<u16>(&self, addr).set_high(value));
405+
self.set::<u16>(addr, Self::get::<u16>(self, addr).set_high(value));
406406
}
407-
_ => self.set::<u16>(addr, Self::get::<u16>(&self, addr).set_low(value)),
407+
_ => self.set::<u16>(addr, Self::get::<u16>(self, addr).set_low(value)),
408408
}
409409
}
410410

cores/gga/src/ppu/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Layer = [Colour; WIDTH];
4343
pub enum PpuRendererKind {
4444
#[default]
4545
Invalid,
46-
SingleCore(PpuRender),
46+
SingleCore(Box<PpuRender>),
4747
Threaded {
4848
sender: Sender<PpuRegisters>,
4949
last: Arc<Mutex<Option<Vec<Colour>>>>,
@@ -88,7 +88,7 @@ impl PpuRendererKind {
8888

8989
Self::Threaded { sender, last }
9090
} else {
91-
Self::SingleCore(render)
91+
Self::SingleCore(Box::new(render))
9292
}
9393
}
9494
}

cores/gga/src/ppu/render/modes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl PpuRender {
110110

111111
if !point.inbounds(160, 127) {
112112
if wrap {
113-
point.0 = point.0.rem_euclid(160 as i32);
114-
point.1 = point.1.rem_euclid(127 as i32);
113+
point.0 = point.0.rem_euclid(160);
114+
point.1 = point.1.rem_euclid(127);
115115
} else {
116116
continue;
117117
}

cores/gga/src/ppu/render/objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl PpuRender {
145145

146146
let rotscal = self.get_rotscal(obj.rotscal());
147147
let (half_w, half_h) = (bounds_w / 2, bounds_h / 2);
148-
let iy = line - (position.1 + half_h as i32);
148+
let iy = line - (position.1 + half_h);
149149

150150
for ix in (-half_w)..half_w {
151151
let screen_x = position.0 + half_w + ix;

0 commit comments

Comments
 (0)