chore: update to rust 1.63.0

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-12-23 20:14:37 -06:00
parent 7784b9b6e2
commit a07e270fad
6 changed files with 1217 additions and 711 deletions

1881
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
[package] [package]
authors = ["paoda <musukarekai@gmail.com>"] authors = ["paoda <musukarekai@gmail.com>"]
edition = "2018" edition = "2021"
name = "chip8" name = "chip8"
version = "0.1.0" version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
pixels = "0.1.0" pixels = "0.11"
rand = "0.8.4" rand = "0.8"
winit = "0.22.2" winit = "0.27"
winit_input_helper = "0.7.0" winit_input_helper = "0.13"
rodio = "0.11.0" rodio = "0.16"
lazy_static = "1.4.0" lazy_static = "1.4.0"

View File

@ -422,7 +422,7 @@ impl Chip8 {
} }
fn to_digits(num: u8) -> [u8; 3] { fn to_digits(num: u8) -> [u8; 3] {
let mut cpy = num.clone(); let mut cpy = num;
let mut digits = [0, 0, 0]; let mut digits = [0, 0, 0];
for digit in digits.iter_mut() { for digit in digits.iter_mut() {

View File

@ -1,5 +1,5 @@
use chip8::{emu::Chip8, timer::Timer}; use chip8::{emu::Chip8, timer::Timer};
use pixels::{wgpu::Surface, Pixels, SurfaceTexture}; use pixels::{Pixels, SurfaceTexture};
use std::path::Path; use std::path::Path;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use winit::dpi::LogicalSize; use winit::dpi::LogicalSize;
@ -30,7 +30,7 @@ fn main() {
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
if let Event::RedrawRequested(_) = event { if let Event::RedrawRequested(_) = event {
draw(&chip8.display.buf, pixels.get_frame()); draw(&chip8.display.buf, pixels.get_frame_mut());
if pixels if pixels
.render() .render()
.map_err(|e| eprintln!("pixels.render() failed: {}", e)) .map_err(|e| eprintln!("pixels.render() failed: {}", e))
@ -45,7 +45,9 @@ fn main() {
handle_input(&mut chip8, &mut input, control_flow); handle_input(&mut chip8, &mut input, control_flow);
if let Some(size) = input.window_resized() { if let Some(size) = input.window_resized() {
pixels.resize(size.width, size.height); pixels
.resize_surface(size.width, size.height)
.expect("resize surface")
} }
if Instant::now().duration_since(start) > frametime { if Instant::now().duration_since(start) > frametime {
@ -181,8 +183,7 @@ fn handle_input(chip8: &mut Chip8, input: &mut WinitInputHelper, control_flow: &
} }
fn init_pixels(window: &Window) -> Pixels { fn init_pixels(window: &Window) -> Pixels {
let surface = Surface::create(window); let texture = SurfaceTexture::new(WIDTH, HEIGHT, window);
let texture = SurfaceTexture::new(WIDTH, HEIGHT, surface);
Pixels::new(WIDTH, HEIGHT, texture).unwrap() Pixels::new(WIDTH, HEIGHT, texture).unwrap()
} }

View File

@ -54,17 +54,11 @@ impl Default for Display {
} }
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Default, Copy, Clone)]
pub struct Keypad { pub struct Keypad {
keys: [bool; 16], keys: [bool; 16],
} }
impl Default for Keypad {
fn default() -> Self {
Self { keys: [false; 16] }
}
}
impl Keypad { impl Keypad {
pub fn get_any_pressed(&self) -> Option<u8> { pub fn get_any_pressed(&self) -> Option<u8> {
for (i, key) in self.keys.iter().enumerate() { for (i, key) in self.keys.iter().enumerate() {

View File

@ -1,4 +1,4 @@
use rodio::{source::SineWave, Sink, Source}; use rodio::{source::SineWave, OutputStream, Source};
use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::atomic::{AtomicU8, Ordering};
use std::thread; use std::thread;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -68,13 +68,11 @@ impl Timer {
} }
fn beep() { fn beep() {
const BEEP_FREQ: u32 = 440; // Hz (Middle A) const BEEP_FREQ: f32 = 440.0; // Hz (Middle A)
const BEEP_LENGTH: u64 = 150; // ms const BEEP_LENGTH: u64 = 150; // ms
let beep = SineWave::new(BEEP_FREQ) let beep = SineWave::new(BEEP_FREQ).take_duration(Duration::from_millis(BEEP_LENGTH));
.take_duration(Duration::from_millis(BEEP_LENGTH));
if let Some(device) = rodio::default_output_device() { let (_stream, stream_handle) = OutputStream::try_default().expect("find output stream");
rodio::play_raw(&device, beep); stream_handle.play_raw(beep).expect("play sine wave");
}
} }
} }