This commit is contained in:
Thinkofdeath 2015-09-29 20:09:36 +01:00
parent bdfc002e99
commit 302af6393d
11 changed files with 88 additions and 83 deletions

16
Cargo.lock generated
View File

@ -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)",

View File

@ -13,8 +13,10 @@
// limitations under the License.
use std::marker::PhantomData;
use std::collections::HashMap;
use std::any::Any;
pub struct CVar<T: Sized + 'static> {
pub struct CVar<T: Sized + Any + 'static> {
pub name: &'static str,
pub ty: PhantomData<T>,
pub description: &'static str,
@ -23,10 +25,6 @@ pub struct CVar<T: Sized + 'static> {
pub default: &'static Fn() -> T,
}
impl <T> CVar<T> {
}
impl Var for CVar<String> {}
pub trait Var {
@ -34,17 +32,32 @@ pub trait Var {
}
pub struct Console {
vars: Vec<Box<Var>>,
vars: HashMap<&'static str, Box<Var>>,
var_values: HashMap<&'static str, Box<Any>>,
}
impl Console {
pub fn new() -> Console {
Console {
vars: Vec::new(),
vars: HashMap::new(),
var_values: HashMap::new(),
}
}
pub fn register<T>(&mut self, var: CVar<T>) where CVar<T> : Var {
self.vars.push(Box::new(var));
pub fn register<T: Sized + Any>(&mut self, var: CVar<T>) where CVar<T> : 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<T: Sized + Any>(&self, var: CVar<T>) -> &T where CVar<T> : Var {
// Should never fail
self.var_values.get(var.name).unwrap().downcast_ref::<T>().unwrap()
}
pub fn set<T: Sized + Any>(&mut self, var: CVar<T>, val: T) where CVar<T> : Var {
self.var_values.insert(var.name, Box::new(val));
}
}

View File

@ -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);

View File

@ -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<u8>;
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
}
}

View File

@ -353,7 +353,7 @@ pub struct LenPrefixed<L: Lengthable, V> {
impl <L: Lengthable, V: Default> LenPrefixed<L, V> {
fn new(data: Vec<V>) -> LenPrefixed<L, V> {
return LenPrefixed {
LenPrefixed {
len: Default::default(),
data: data,
}
@ -374,7 +374,7 @@ impl <L: Lengthable, V: Serializable> Serializable for LenPrefixed<L, V> {
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<L: Lengthable> {
impl <L: Lengthable> LenPrefixedBytes<L> {
fn new(data: Vec<u8>) -> LenPrefixedBytes<L> {
return LenPrefixedBytes {
LenPrefixedBytes {
len: Default::default(),
data: data,
}
@ -621,18 +621,18 @@ impl convert::From<io::Error> 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)
}
}
}

View File

@ -39,10 +39,9 @@ impl Atlas {
pub fn add(&mut self, width: usize, height: usize) -> Option<Rect> {
let mut priority = usize::max_value();
let mut target: Option<Rect> = 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;

View File

@ -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<u8>, 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] {

View File

@ -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") {

View File

@ -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
}
}

View File

@ -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)

View File

@ -39,27 +39,27 @@ macro_rules! element_impl {
($($name:ident),+) => (
impl Element {
fn get_click_funcs(&self) -> Vec<ClickFunc> {
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<HoverFunc> {
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<ElementRefInner> {
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<u8>{
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 {