Remove Beep from Delay Timer

This commit is contained in:
Rekai Musuka 2020-07-15 15:08:02 -05:00
parent 37a2e89dab
commit 7acfaeb3a1
2 changed files with 12 additions and 2 deletions

View File

@ -28,7 +28,7 @@ impl Default for Chip8 {
stack: [0; 16], stack: [0; 16],
memory: [0; 4096], memory: [0; 4096],
delay: Default::default(), delay: Default::default(),
sound: Default::default(), sound: Timer::default().with_beep(),
key: Default::default(), key: Default::default(),
display: Default::default(), display: Default::default(),
request_redraw: false, request_redraw: false,

View File

@ -61,6 +61,7 @@ impl Default for Display {
pub struct Timer { pub struct Timer {
remaining: u8, remaining: u8,
enabled: bool, enabled: bool,
beep_enabled: bool,
} }
impl Default for Timer { impl Default for Timer {
@ -68,11 +69,17 @@ impl Default for Timer {
Timer { Timer {
remaining: 0, remaining: 0,
enabled: false, enabled: false,
beep_enabled: false,
} }
} }
} }
impl Timer { impl Timer {
pub fn with_beep(mut self) -> Self {
self.beep_enabled = true;
self
}
pub fn set(&mut self, secs: u8) { pub fn set(&mut self, secs: u8) {
self.remaining = secs; self.remaining = secs;
self.enabled = true; self.enabled = true;
@ -88,10 +95,13 @@ impl Timer {
if self.remaining == 0 { if self.remaining == 0 {
self.enabled = false; self.enabled = false;
if self.beep_enabled {
Self::beep(); Self::beep();
} }
} }
} }
}
fn beep() { fn beep() {
let maybe_device = rodio::default_output_device(); let maybe_device = rodio::default_output_device();