From 54b9f2778c02cfadf4ec3ce2bf018c208ac31047 Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sun, 2 Jan 2022 13:17:17 -0600 Subject: [PATCH] Appease Clippy --- src/game.rs | 16 +++++++--------- src/main.rs | 4 ++-- src/systems.rs | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/game.rs b/src/game.rs index b488d6b..225ddef 100644 --- a/src/game.rs +++ b/src/game.rs @@ -86,15 +86,13 @@ impl DungeonLevel { .all(|(_x, _y, tile)| *tile != &DungeonTile::Floor) { ' ' + } else if neighborhood + .iter() + .any(|(tile_x, _y, tile)| *tile_x == x && *tile == &DungeonTile::Floor) + { + '-' } else { - if neighborhood - .iter() - .any(|(tile_x, _y, tile)| *tile_x == x && *tile == &DungeonTile::Floor) - { - '-' - } else { - '|' - } + '|' } } DungeonTile::Hallway => '#', @@ -109,7 +107,7 @@ impl Display for DungeonLevel { write!(f, "{}", self.render_tile(x, y))?; } - write!(f, "\n")?; + writeln!(f)?; } Ok(()) diff --git a/src/main.rs b/src/main.rs index c62920d..249aa2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use components::{register_all, Position, CharRender}; +use components::{register_all, CharRender, Position}; use game::{BranchConfig, DungeonLevel}; use specs::prelude::*; @@ -31,6 +31,6 @@ fn main() { .build(); loop { - dispatcher.dispatch(&mut world); + dispatcher.dispatch(&world); } } diff --git a/src/systems.rs b/src/systems.rs index 5f3c6d6..47abb9a 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -1,12 +1,15 @@ //! ECS systems. -use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, Ordering}; use lazy_static::lazy_static; -use pancurses::{Window, endwin, initscr}; +use pancurses::{endwin, initscr, Window}; use specs::prelude::*; -use crate::{components::{Position, CharRender}, game::DungeonLevel}; +use crate::{ + components::{CharRender, Position}, + game::DungeonLevel, +}; /// System for drawing the state of the game, and potentially waiting /// (blocking) for user input. @@ -15,18 +18,16 @@ pub struct IOSystem { } lazy_static! { - static ref WINDOW_INITIALIZED: Mutex = Mutex::new(false); + static ref WINDOW_INITIALIZED: AtomicBool = AtomicBool::new(false); } impl IOSystem { pub fn new() -> Self { - let mut init = WINDOW_INITIALIZED.lock().unwrap(); - if *init { - // See the note on `impl Send for IOSystem`. + // See the note on `impl Send for IOSystem`. + if WINDOW_INITIALIZED.swap(true, Ordering::Relaxed) { panic!("Refusing to initialize the renderer twice"); } - *init = true; Self { window: initscr() } } } @@ -34,7 +35,7 @@ impl IOSystem { impl Drop for IOSystem { fn drop(&mut self) { endwin(); - *WINDOW_INITIALIZED.lock().unwrap() = false; + WINDOW_INITIALIZED.store(false, Ordering::Relaxed); } } @@ -70,4 +71,3 @@ impl<'a> System<'a> for IOSystem { self.window.getch(); } } -