diff --git a/Cargo.lock b/Cargo.lock index 795aa5d..c662aa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,8 +5,8 @@ dependencies = [ "byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "glfw 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "image 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", + "image 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -50,7 +50,7 @@ name = "bzip2-sys" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -97,7 +97,7 @@ dependencies = [ [[package]] name = "gcc" -version = "0.3.14" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -170,7 +170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -191,7 +191,7 @@ dependencies = [ [[package]] name = "image" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -270,7 +270,7 @@ name = "miniz-sys" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -317,7 +317,7 @@ name = "openssl-sys" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libressl-pnacl-sys 2.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/console/mod.rs b/src/console/mod.rs index ab67120..3ec2281 100644 --- a/src/console/mod.rs +++ b/src/console/mod.rs @@ -13,8 +13,10 @@ // limitations under the License. use std::marker::PhantomData; +use std::collections::HashMap; +use std::any::Any; -pub struct CVar { +pub struct CVar { pub name: &'static str, pub ty: PhantomData, pub description: &'static str, @@ -23,10 +25,6 @@ pub struct CVar { pub default: &'static Fn() -> T, } -impl CVar { - -} - impl Var for CVar {} pub trait Var { @@ -34,17 +32,32 @@ pub trait Var { } pub struct Console { - vars: Vec>, + vars: HashMap<&'static str, Box>, + var_values: HashMap<&'static str, Box>, } impl Console { pub fn new() -> Console { Console { - vars: Vec::new(), + vars: HashMap::new(), + var_values: HashMap::new(), } } - pub fn register(&mut self, var: CVar) where CVar : Var { - self.vars.push(Box::new(var)); + pub fn register(&mut self, var: CVar) where CVar : Var { + if self.vars.contains_key(var.name) { + panic!("Key registered twice {}", var.name); + } + self.var_values.insert(var.name, Box::new((var.default)())); + self.vars.insert(var.name, Box::new(var)); + } + + pub fn get(&self, var: CVar) -> &T where CVar : Var { + // Should never fail + self.var_values.get(var.name).unwrap().downcast_ref::().unwrap() + } + + pub fn set(&mut self, var: CVar, val: T) where CVar : Var { + self.var_values.insert(var.name, Box::new(val)); } } \ No newline at end of file diff --git a/src/format.rs b/src/format.rs index f0c9cba..50dc3f9 100644 --- a/src/format.rs +++ b/src/format.rs @@ -277,8 +277,8 @@ fn test_color_from() { const LEGACY_CHAR: char = '§'; pub fn convert_legacy(c: &mut Component) { - match c { - &mut Component::Text(ref mut txt) => { + match *c { + Component::Text(ref mut txt) => { if let Some(ref mut extra) = txt.modifier.extra.as_mut() { for e in extra.iter_mut() { convert_legacy(e); diff --git a/src/gl/mod.rs b/src/gl/mod.rs index e28090b..9653816 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -312,7 +312,7 @@ impl Shader { pub fn get_parameter(&self, param: ShaderParameter) -> i32 { let mut ret : i32 = 0; unsafe { gl::GetShaderiv(self.0, param, &mut ret); } - return ret; + ret } pub fn get_info_log(&self) -> String { @@ -505,13 +505,13 @@ pub struct MappedBuffer { impl Deref for MappedBuffer { type Target = Vec; - fn deref<'a>(&'a self) -> &'a Self::Target { + fn deref(&self) -> &Self::Target { &self.inner } } impl DerefMut for MappedBuffer { - fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } } diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 1bc06d2..25734cf 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -353,7 +353,7 @@ pub struct LenPrefixed { impl LenPrefixed { fn new(data: Vec) -> LenPrefixed { - return LenPrefixed { + LenPrefixed { len: Default::default(), data: data, } @@ -374,7 +374,7 @@ impl Serializable for LenPrefixed { fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> { let len_data : L = L::from(self.data.len()); try!(len_data.write_to(buf)); - let ref data = self.data; + let data = &self.data; for val in data { try!(val.write_to(buf)); } @@ -406,7 +406,7 @@ pub struct LenPrefixedBytes { impl LenPrefixedBytes { fn new(data: Vec) -> LenPrefixedBytes { - return LenPrefixedBytes { + LenPrefixedBytes { len: Default::default(), data: data, } @@ -621,18 +621,18 @@ impl convert::From for Error { impl ::std::error::Error for Error { fn description(&self) -> &str { - match self { - &Error::Err(ref val) => &val[..], - &Error::IOError(ref e) => e.description(), + match *self { + Error::Err(ref val) => &val[..], + Error::IOError(ref e) => e.description(), } } } impl ::std::fmt::Display for Error { fn fmt(&self, f : &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - match self { - &Error::Err(ref val) => write!(f, "protocol error: {}", val), - &Error::IOError(ref e) => e.fmt(f) + match *self { + Error::Err(ref val) => write!(f, "protocol error: {}", val), + Error::IOError(ref e) => e.fmt(f) } } } diff --git a/src/render/atlas.rs b/src/render/atlas.rs index 8e05bfe..d88bde7 100644 --- a/src/render/atlas.rs +++ b/src/render/atlas.rs @@ -39,10 +39,9 @@ impl Atlas { pub fn add(&mut self, width: usize, height: usize) -> Option { let mut priority = usize::max_value(); let mut target: Option = None; - let mut index = 0; let mut target_index = 0; // Search through and find the best fit for this texture - for free in &self.free_space { + for (index, free) in self.free_space.iter().enumerate() { if free.width >= width && free.height >= height { let current_priority = (free.width - width) * (free.height - height); if target.is_none() || current_priority < priority { @@ -55,7 +54,6 @@ impl Atlas { break; } } - index += 1; } if target.is_none() { return None; diff --git a/src/render/mod.rs b/src/render/mod.rs index a6d7bef..8be919e 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -46,7 +46,7 @@ impl Renderer { let version = { res.read().unwrap().version() }; let tex = gl::Texture::new(); tex.bind(gl::TEXTURE_2D_ARRAY); - tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, ATLAS_SIZE as u32, 1, gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE*ATLAS_SIZE*1*4]); + tex.image_3d(gl::TEXTURE_2D_ARRAY, 0, ATLAS_SIZE as u32, ATLAS_SIZE as u32, 1, gl::RGBA, gl::UNSIGNED_BYTE, &[0; ATLAS_SIZE*ATLAS_SIZE*4]); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MAG_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_MIN_FILTER, gl::NEAREST); tex.set_parameter(gl::TEXTURE_2D_ARRAY, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); @@ -122,7 +122,7 @@ impl Renderer { tex.pending_uploads.clear(); } - for ani in self.textures.write().unwrap().animated_textures.iter_mut() { + for ani in &mut self.textures.write().unwrap().animated_textures { if ani.remaining_time <= 0.0 { ani.current_frame = (ani.current_frame + 1) % ani.frames.len(); ani.remaining_time += ani.frames[ani.current_frame].time as f64; @@ -358,7 +358,7 @@ impl TextureManager { fn find_free(&mut self, width: usize, height: usize) -> (i32, atlas::Rect) { let mut index = 0; - for atlas in self.atlases.iter_mut() { + for atlas in &mut self.atlases { if let Some(rect) = atlas.add(width, height) { return (index, rect); } @@ -568,7 +568,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { panic!("Shader error: {}", v.get_info_log()); } else { let log = v.get_info_log(); - if log.len() > 0 { + if !log.is_empty() { println!("{}", log); } } @@ -582,7 +582,7 @@ pub fn create_program(vertex: &str, fragment: &str) -> gl::Program { panic!("Shader error: {}", f.get_info_log()); } else { let log = f.get_info_log(); - if log.len() > 0 { + if !log.is_empty() { println!("{}", log); } } @@ -599,11 +599,9 @@ pub fn generate_element_buffer(size: usize) -> (Vec, gl::Type) { let mut ty = gl::UNSIGNED_SHORT; let mut data = if (size/6)*4*3 >= u16::max_value() as usize { ty = gl::UNSIGNED_INT; - let data = Vec::with_capacity(size*4); - data + Vec::with_capacity(size*4) } else { - let data = Vec::with_capacity(size*2); - data + Vec::with_capacity(size*2) }; for i in 0 .. size/6 { for val in &[0, 1, 2, 2, 1, 3] { diff --git a/src/render/ui.rs b/src/render/ui.rs index 7a6aef8..da2e20d 100644 --- a/src/render/ui.rs +++ b/src/render/ui.rs @@ -87,10 +87,8 @@ impl UIState { let mut char_map = HashMap::new(); let ascii_chars = "ÀÁÂÈÊËÍÓÔÕÚßãõğİıŒœŞşŴŵžȇ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αβΓπΣσμτΦΘΩδ∞∅∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■"; - let mut pos = 0u32; - for c in ascii_chars.chars() { - char_map.insert(c, ::std::char::from_u32(pos).unwrap()); - pos += 1; + for (pos, c) in ascii_chars.chars().enumerate() { + char_map.insert(c, ::std::char::from_u32(pos as u32).unwrap()); } let mut state = UIState { @@ -206,7 +204,7 @@ impl UIState { (sh as f32) / (self.page_height as f32) ) } - return p.relative( + p.relative( (cx * 16 + info.0 as u32) as f32 / 256.0, (cy * 16) as f32 / 256.0, (info.1 - info.0) as f32 / 256.0, @@ -234,7 +232,7 @@ impl UIState { return (((info.1 - info.0) as f64) / sw) * 16.0; } let info = self.font_character_info[c as usize]; - return (info.1 - info.0) as f64; + (info.1 - info.0) as f64 } fn load_font(&mut self) { @@ -242,11 +240,11 @@ impl UIState { if let Some(mut info) = res.open("minecraft", "font/glyph_sizes.bin") { let mut data = Vec::with_capacity(0x10000); info.read_to_end(&mut data).unwrap(); - for i in 0 .. self.font_character_info.len() { + for (i, info) in self.font_character_info.iter_mut().enumerate() { // Top nibble - start position // Bottom nibble - end position - self.font_character_info[i].0 = (data[i] >> 4) as i32; - self.font_character_info[i].1 = (data[i] & 0xF) as i32 + 1; + info.0 = (data[i] >> 4) as i32; + info.1 = (data[i] & 0xF) as i32 + 1; } } if let Some(mut val) = res.open("minecraft", "textures/font/ascii.png") { diff --git a/src/types/bit/set.rs b/src/types/bit/set.rs index 995ce69..e74f6c5 100644 --- a/src/types/bit/set.rs +++ b/src/types/bit/set.rs @@ -51,6 +51,6 @@ impl Set { } pub fn get(&mut self, i: usize) -> bool { - return (self.data[i>>6] & (1 << (i & 0x3F))) != 0 + (self.data[i>>6] & (1 << (i & 0x3F))) != 0 } } diff --git a/src/ui/logo.rs b/src/ui/logo.rs index 83f3cdb..695f198 100644 --- a/src/ui/logo.rs +++ b/src/ui/logo.rs @@ -58,13 +58,11 @@ impl Logo { if line.is_empty() { continue; } - let mut i = 0; - for c in line.chars() { - i += 1; + for (i, c) in line.chars().enumerate() { if c == ' ' { continue; } - let x = (i - 1) * 4; + let x = i * 4; let y = row * 8; let (r, g, b) = if c == ':' { (255, 255, 255) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 97eeab7..27709a4 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -39,27 +39,27 @@ macro_rules! element_impl { ($($name:ident),+) => ( impl Element { fn get_click_funcs(&self) -> Vec { - match self { + match *self { $( - &Element::$name(ref val) => val.click_funcs.clone(), + Element::$name(ref val) => val.click_funcs.clone(), )+ _ => unimplemented!(), } } fn get_hover_funcs(&self) -> Vec { - match self { + match *self { $( - &Element::$name(ref val) => val.hover_funcs.clone(), + Element::$name(ref val) => val.hover_funcs.clone(), )+ _ => unimplemented!(), } } fn should_call_hover(&mut self, new: bool) -> bool{ - match self { + match *self { $( - &mut Element::$name(ref mut val) => { + Element::$name(ref mut val) => { let ret = val.hovered != new; val.hovered = new; ret @@ -70,81 +70,81 @@ impl Element { } fn should_draw(&self) -> bool { - match self { + match *self { $( - &Element::$name(ref val) => val.should_draw, + Element::$name(ref val) => val.should_draw, )+ _ => unimplemented!(), } } fn get_parent(&self) -> Option { - match self { + match *self { $( - &Element::$name(ref val) => val.parent, + Element::$name(ref val) => val.parent, )+ _ => unimplemented!(), } } fn get_attachment(&self) -> (VAttach, HAttach) { - match self { + match *self { $( - &Element::$name(ref val) => (val.v_attach, val.h_attach), + Element::$name(ref val) => (val.v_attach, val.h_attach), )+ _ => unimplemented!(), } } fn get_offset(&self) -> (f64, f64) { - match self { + match *self { $( - &Element::$name(ref val) => (val.x, val.y), + Element::$name(ref val) => (val.x, val.y), )+ _ => unimplemented!(), } } fn get_size(&self) -> (f64, f64) { - match self { + match *self { $( - &Element::$name(ref val) => val.get_size(), + Element::$name(ref val) => val.get_size(), )+ _ => unimplemented!(), } } fn is_dirty(&self) -> bool { - match self { + match *self { $( - &Element::$name(ref val) => val.dirty, + Element::$name(ref val) => val.dirty, )+ _ => unimplemented!(), } } fn set_dirty(&mut self, dirty: bool) { - match self { + match *self { $( - &mut Element::$name(ref mut val) => val.dirty = dirty, + Element::$name(ref mut val) => val.dirty = dirty, )+ _ => unimplemented!(), } } fn update(&mut self, renderer: &mut render::Renderer) { - match self { + match *self { $( - &mut Element::$name(ref mut val) => val.update(renderer), + Element::$name(ref mut val) => val.update(renderer), )+ _ => unimplemented!(), } } fn draw(&mut self, renderer: &mut render::Renderer, r: &Region, width: f64, height: f64, delta: f64) -> &Vec{ - match self { + match *self { $( - &mut Element::$name(ref mut val) => val.draw(renderer, r, width, height, delta), + Element::$name(ref mut val) => val.draw(renderer, r, width, height, delta), )+ _ => unimplemented!(), } @@ -459,8 +459,8 @@ impl Container { pub trait UIElement { fn wrap(self) -> Element; - fn unwrap_ref<'a>(&'a Element) -> &'a Self; - fn unwrap_ref_mut<'a>(&'a mut Element) -> &'a mut Self; + fn unwrap_ref(&Element) -> &Self; + fn unwrap_ref_mut(&mut Element) -> &mut Self; } macro_rules! lazy_field {