From a4f31c03975fdaa2dc889849f6b1c45668d91f6c Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Tue, 7 Jun 2016 23:54:15 +0200 Subject: [PATCH] Clean up some warnings. --- src/main.rs | 15 ++------------- src/player.rs | 42 ------------------------------------------ src/sprite.rs | 6 +++--- src/tile.rs | 1 - src/timer.rs | 3 +-- 5 files changed, 6 insertions(+), 61 deletions(-) delete mode 100644 src/player.rs diff --git a/src/main.rs b/src/main.rs index 5551615..b1cbb24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,9 @@ +#[deny(trivial_casts, trivial_numeric_casts)] extern crate sdl2; extern crate sdl2_image; - use std::path::Path; use std::cell::{Cell, RefCell}; -use std::collections::HashMap; use sdl2_image::LoadTexture; use sdl2::rect::Rect; @@ -15,7 +14,6 @@ use sdl2::render::{Renderer, Texture}; use tile::Layer; use camera::Camera; -// use player::Player; use keyboard::KeyboardHandler; use sprite::{Sprite, StaticSprite, AnimatedSprite}; use timer::Timer; @@ -24,11 +22,9 @@ use timer::Timer; mod timer; mod tile; mod camera; -mod player; mod keyboard; mod sprite; - const SCREEN_WIDTH : u32 = 960; const SCREEN_HEIGHT : u32 = 640; @@ -44,7 +40,6 @@ const PLAYER_ACCELERATION_X_START : f32 = 0.02; const PLAYER_ACCELERATION_X_STOP : f32 = 0.15; const PLAYER_ACCELERATION_X_CHANGE : f32 = 0.06; - struct GameObject<'a> { pub x: f32, pub y: f32, @@ -95,15 +90,13 @@ trait Renderable { fn render(&self, &GameObject, f64, &mut Renderer, &Rect); } - struct PlayerPhysicsComponent; impl Updatable for PlayerPhysicsComponent { - fn update(&self, object: &GameObject) { + fn update(&self, _: &GameObject) { } } - struct PlayerGraphicsComponent<'a> { flip_horizontal: Cell, sprite_standing: RefCell>, @@ -144,7 +137,6 @@ impl<'a> Renderable for PlayerGraphicsComponent<'a> { } } - #[derive(Clone)] enum Tile<'a> { Empty, @@ -153,7 +145,6 @@ enum Tile<'a> { Floor(Rect) } - fn main() { let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); @@ -553,7 +544,5 @@ fn main() { player.render(elapsed, &mut renderer, &player_rect); renderer.present(); - - // sleep(std::time::Duration::from_millis(5)); } } diff --git a/src/player.rs b/src/player.rs deleted file mode 100644 index 91512c5..0000000 --- a/src/player.rs +++ /dev/null @@ -1,42 +0,0 @@ -use sdl2::rect::Rect; - - -pub struct Player { - pub x: f32, - pub y: f32, - pub w: u32, - pub h: u32, - pub dx: f32, - pub dy: f32, - pub gravity: f32, - pub on_ground: bool -} - -impl Player { - pub fn new(x: f32, y: f32) -> Player { - Player { - x: x, - y: y, - w: 32, - h: 32, - dx: 0.0, - dy: 0.0, - gravity: 0.3, - on_ground: false - } - } - - pub fn update(&mut self) { - self.dy += self.gravity; - - if self.dy > 8.0 { - self.dy = 8.0; - } else if self.dy < -8.0 { - self.dy = -8.0; - } - } - - pub fn to_rect(&self) -> Rect { - Rect::new(self.x as i32, self.y as i32, self.w, self.h) - } -} diff --git a/src/sprite.rs b/src/sprite.rs index 6fc4f9a..b764963 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -30,8 +30,8 @@ impl<'a> StaticSprite<'a> { } impl<'a> Sprite for StaticSprite<'a> { - fn render(&self, elapsed: f64, drawer: &mut Renderer, destination: &Rect) { - drawer.copy_ex(self.texture, Some(Rect::new(self.x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical); + fn render(&self, _: f64, drawer: &mut Renderer, destination: &Rect) { + let _ = drawer.copy_ex(self.texture, Some(Rect::new(self.x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical); } } @@ -76,6 +76,6 @@ impl<'a> Sprite for AnimatedSprite<'a> { let x = self.x + (*frame * 16) as i32; - drawer.copy_ex(self.texture, Some(Rect::new(x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical); + let _ = drawer.copy_ex(self.texture, Some(Rect::new(x, self.y, 16, 16)), Some(*destination), 0.0, None, self.flip_horizontal, self.flip_vertical); } } diff --git a/src/tile.rs b/src/tile.rs index 1a71ff6..ff8a617 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -72,7 +72,6 @@ impl Layer where T: Clone { } } - #[cfg(test)] mod tests { use super::Layer; diff --git a/src/timer.rs b/src/timer.rs index 58aa0c8..2959737 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,5 +1,4 @@ -use std::time::{Duration, Instant}; - +use std::time::Instant; pub struct Timer { time: Instant