Remove Beep from Delay Timer
This commit is contained in:
parent
37a2e89dab
commit
7acfaeb3a1
|
@ -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,
|
||||||
|
|
|
@ -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,7 +95,10 @@ impl Timer {
|
||||||
|
|
||||||
if self.remaining == 0 {
|
if self.remaining == 0 {
|
||||||
self.enabled = false;
|
self.enabled = false;
|
||||||
Self::beep();
|
|
||||||
|
if self.beep_enabled {
|
||||||
|
Self::beep();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue