Fixed various clippy warnings

This commit is contained in:
llogiq 2016-04-03 02:26:31 +02:00 committed by Matthew Collins
parent 6f708d35f2
commit 0b8cc33c17
11 changed files with 87 additions and 99 deletions

View File

@ -159,14 +159,14 @@ fn build_func(id: usize, models: Arc<RwLock<model::Factory>>, work_recv: mpsc::R
_ => {},
}
if !mat.transparent {
solid_count += model::Factory::get_state_model(
&models, block, &mut rng, &snapshot, x, y, z, &mut solid_buffer
);
} else {
if mat.transparent {
trans_count += model::Factory::get_state_model(
&models, block, &mut rng, &snapshot, x, y, z, &mut trans_buffer
);
} else {
solid_count += model::Factory::get_state_model(
&models, block, &mut rng, &snapshot, x, y, z, &mut solid_buffer
);
}
}
}

View File

@ -195,7 +195,7 @@ impl Console {
let reader = BufReader::new(file);
for line in reader.lines() {
let line = line.unwrap();
if line.starts_with("#") || line.is_empty() {
if line.starts_with('#') || line.is_empty() {
continue;
}
let parts = line.splitn(2, ' ').map(|v| v.to_owned()).collect::<Vec<String>>();

View File

@ -520,7 +520,7 @@ impl ComponentMem {
let data = self.data[idx].as_ref().unwrap();
let start = rem * self.component_size;
unsafe {
mem::transmute(data.0.as_ptr().offset(start as isize))
&*(data.0.as_ptr().offset(start as isize) as *const T)
}
}
@ -530,7 +530,7 @@ impl ComponentMem {
let data = self.data[idx].as_mut().unwrap();
let start = rem * self.component_size;
unsafe {
mem::transmute(data.0.as_mut_ptr().offset(start as isize))
&mut *(data.0.as_mut_ptr().offset(start as isize) as *mut T)
}
}
}

View File

@ -210,18 +210,16 @@ impl ecs::System for PlayerRenderer {
* Matrix4::from(Quaternion::from_angle_x(Rad::new(-(i_time.sin() * 0.06) as f32)));
let mut update = true;
if !position.moved {
if player_model.still_time > 5.0 {
if (time - 15.0).abs() <= 1.5 * delta {
time = 15.0;
update = false;
}
dir = (15.0 - time).signum() as i32;
} else {
player_model.still_time += delta;
}
} else {
if position.moved {
player_model.still_time = 0.0;
} else if player_model.still_time > 5.0 {
if (time - 15.0).abs() <= 1.5 * delta {
time = 15.0;
update = false;
}
dir = (15.0 - time).signum() as i32;
} else {
player_model.still_time += delta;
}
if update {

View File

@ -73,7 +73,7 @@ pub fn clear_color(r: f32, g: f32, b: f32, a: f32) {
}
}
/// ClearFlags is a set of flags to mark what should be cleared during
/// `ClearFlags` is a set of flags to mark what should be cleared during
/// a Clear call.
pub enum ClearFlags {
/// Marks the color buffer to be cleared
@ -110,7 +110,7 @@ pub fn depth_mask(f: bool) {
unsafe { gl::DepthMask(f as u8); }
}
/// Func is a function to be preformed on two values.
/// `Func` is a function to be preformed on two values.
pub type Func = u32;
pub const NEVER: Func = gl::NEVER;
@ -157,7 +157,7 @@ pub fn active_texture(id: u32) {
}
}
/// Factor is used in blending
/// `Factor` is used in blending
pub type Factor = u32;
pub const SRC_ALPHA: Factor = gl::SRC_ALPHA;
pub const ONE_MINUS_SRC_ALPHA: Factor = gl::ONE_MINUS_SRC_ALPHA;
@ -201,7 +201,7 @@ pub fn front_face(dir: FaceDirection) {
unsafe { gl::FrontFace(dir) }
}
/// Type is a type of data used by various operations.
/// `Type` is a type of data used by various operations.
pub type Type = u32;
pub const UNSIGNED_BYTE: Type = gl::UNSIGNED_BYTE;
pub const UNSIGNED_SHORT: Type = gl::UNSIGNED_SHORT;
@ -209,7 +209,7 @@ pub const UNSIGNED_INT: Type = gl::UNSIGNED_INT;
pub const SHORT: Type = gl::SHORT;
pub const FLOAT: Type = gl::FLOAT;
/// TextureTarget is a target were a texture can be bound to
/// `TextureTarget` is a target were a texture can be bound to
pub type TextureTarget = u32;
pub const TEXTURE_2D: TextureTarget = gl::TEXTURE_2D;
@ -217,7 +217,7 @@ pub const TEXTURE_2D_MULTISAMPLE: TextureTarget = gl::TEXTURE_2D_MULTISAMPLE;
pub const TEXTURE_2D_ARRAY: TextureTarget = gl::TEXTURE_2D_ARRAY;
pub const TEXTURE_3D: TextureTarget = gl::TEXTURE_3D;
/// TextureFormat is the format of a texture either internally or
/// `TextureFormat` is the format of a texture either internally or
/// to be uploaded.
pub type TextureFormat = u32;
@ -230,7 +230,7 @@ pub const R16F: TextureFormat = gl::R16F;
pub const DEPTH_COMPONENT24: TextureFormat = gl::DEPTH_COMPONENT24;
pub const DEPTH_COMPONENT: TextureFormat = gl::DEPTH_COMPONENT;
/// TextureParameter is a parameter that can be read or set on a texture.
/// `TextureParameter` is a parameter that can be read or set on a texture.
pub type TextureParameter = u32;
pub const TEXTURE_MIN_FILTER: TextureParameter = gl::TEXTURE_MIN_FILTER;
@ -239,7 +239,7 @@ pub const TEXTURE_WRAP_S: TextureParameter = gl::TEXTURE_WRAP_S;
pub const TEXTURE_WRAP_T: TextureParameter = gl::TEXTURE_WRAP_T;
pub const TEXTURE_MAX_LEVEL: TextureParameter = gl::TEXTURE_MAX_LEVEL;
/// TextureValue is a value that be set on a texture's parameter.
/// `TextureValue` is a value that be set on a texture's parameter.
pub type TextureValue = i32;
pub const NEAREST: TextureValue = gl::NEAREST as TextureValue;
@ -250,7 +250,7 @@ pub const NEAREST_MIPMAP_NEAREST: TextureValue = gl::NEAREST_MIPMAP_NEAREST as T
pub const NEAREST_MIPMAP_LINEAR: TextureValue = gl::NEAREST_MIPMAP_LINEAR as TextureValue;
pub const CLAMP_TO_EDGE: TextureValue = gl::CLAMP_TO_EDGE as TextureValue;
/// Texture is a buffer of data used by fragment shaders.
/// `Texture` is a buffer of data used by fragment shaders.
pub struct Texture(u32);
impl Texture {
@ -650,7 +650,7 @@ impl Attribute {
pub struct VertexArray(u32);
impl VertexArray {
/// Allocates a new VertexArray.
/// Allocates a new `VertexArray`.
pub fn new() -> VertexArray {
let mut va = VertexArray(0);
unsafe {
@ -659,9 +659,9 @@ impl VertexArray {
va
}
/// Marks the VertexArray as the currently active one, this
/// Marks the `VertexArray` as the currently active one, this
/// means buffers/the format of the buffers etc will be bound to
/// this VertexArray.
/// this `VertexArray`.
pub fn bind(&self) {
unsafe {
gl::BindVertexArray(self.0);
@ -678,13 +678,13 @@ impl Drop for VertexArray {
}
}
/// BufferTarget is a target for a buffer to be bound to.
/// `BufferTarget` is a target for a buffer to be bound to.
pub type BufferTarget = u32;
pub const ARRAY_BUFFER: BufferTarget = gl::ARRAY_BUFFER;
pub const ELEMENT_ARRAY_BUFFER: BufferTarget = gl::ELEMENT_ARRAY_BUFFER;
/// BufferUsage states how a buffer is going to be used by the program.
/// `BufferUsage` states how a buffer is going to be used by the program.
pub type BufferUsage = u32;
/// Marks the buffer as 'not going to change' after the
@ -706,7 +706,7 @@ pub const READ_ONLY: Access = gl::READ_ONLY;
/// to.
pub const WRITE_ONLY: Access = gl::WRITE_ONLY;
/// Buffer is a storage for vertex data.
/// `Buffer` is a storage for vertex data.
pub struct Buffer(u32);
impl Buffer {

View File

@ -119,7 +119,7 @@ impl Factory {
}
},
};
return Err(true);
Err(true)
});
}
return Err(true);
@ -881,30 +881,27 @@ impl Model {
}
let (mut cr, mut cg, mut cb) = (255, 255, 255);
match face.tint_index {
0 => {
match tint {
TintType::Default => {},
TintType::Color{r, g, b} => {
cr = r;
cg = g;
cb = b;
},
TintType::Grass => {
let (r, g, b) = calculate_biome(snapshot, x, z, &factory.grass_colors);
cr = r;
cg = g;
cb = b;
},
TintType::Foliage => {
let (r, g, b) = calculate_biome(snapshot, x, z, &factory.foliage_colors);
cr = r;
cg = g;
cb = b;
},
}
},
_ => {},
if face.tint_index == 0 {
match tint {
TintType::Default => {},
TintType::Color{r, g, b} => {
cr = r;
cg = g;
cb = b;
},
TintType::Grass => {
let (r, g, b) = calculate_biome(snapshot, x, z, &factory.grass_colors);
cr = r;
cg = g;
cb = b;
},
TintType::Foliage => {
let (r, g, b) = calculate_biome(snapshot, x, z, &factory.foliage_colors);
cr = r;
cg = g;
cb = b;
},
}
}
if face.facing == Direction::West || face.facing == Direction::East {
cr = ((cr as f64) * 0.8) as u8;

View File

@ -492,7 +492,7 @@ impl Lengthable for i32 {
}
}
/// VarInt have a variable size (between 1 and 5 bytes) when encoded based
/// `VarInt` have a variable size (between 1 and 5 bytes) when encoded based
/// on the size of the number
#[derive(Clone, Copy)]
pub struct VarInt(pub i32);
@ -508,7 +508,7 @@ impl Lengthable for VarInt {
}
impl Serializable for VarInt {
/// Decodes a VarInt from the Reader
/// Decodes a `VarInt` from the Reader
fn read_from(buf: &mut io::Read) -> Result<VarInt, io::Error> {
const PART : u32 = 0x7F;
let mut size = 0;
@ -529,7 +529,7 @@ impl Serializable for VarInt {
Result::Ok(VarInt(val as i32))
}
/// Encodes a VarInt into the Writer
/// Encodes a `VarInt` into the Writer
fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> {
const PART : u32 = 0x7F;
let mut val = self.0 as u32;
@ -556,7 +556,7 @@ impl fmt::Debug for VarInt {
}
}
/// VarLong have a variable size (between 1 and 10 bytes) when encoded based
/// `VarLong` have a variable size (between 1 and 10 bytes) when encoded based
/// on the size of the number
#[derive(Clone, Copy)]
pub struct VarLong(pub i64);
@ -572,7 +572,7 @@ impl Lengthable for VarLong {
}
impl Serializable for VarLong {
/// Decodes a VarLong from the Reader
/// Decodes a `VarLong` from the Reader
fn read_from(buf: &mut io::Read) -> Result<VarLong, io::Error> {
const PART : u64 = 0x7F;
let mut size = 0;
@ -593,7 +593,7 @@ impl Serializable for VarLong {
Result::Ok(VarLong(val as i64))
}
/// Encodes a VarLong into the Writer
/// Encodes a `VarLong` into the Writer
fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> {
const PART : u64 = 0x7F;
let mut val = self.0 as u64;
@ -707,7 +707,7 @@ pub struct Conn {
impl Conn {
pub fn new(target: &str) -> Result<Conn, Error> {
// TODO SRV record support
let mut parts = target.split(":").collect::<Vec<&str>>();
let mut parts = target.split(':').collect::<Vec<&str>>();
let address = if parts.len() == 1 {
parts.push("25565");
format!("{}:25565", parts[0])

View File

@ -220,7 +220,7 @@ impl Manager {
collection.shader.light_level.set_float(light_level);
gl::blend_func(collection.blend_s, collection.blend_d);
for (_, model) in &collection.models {
for model in collection.models.values() {
if model.radius > 0.0 && frustum.contains(Sphere {
center: Point3::new(model.x, -model.y, model.z),
radius: model.radius

View File

@ -444,16 +444,13 @@ impl Server {
}
fn on_game_state_change(&mut self, game_state: packet::play::clientbound::ChangeGameState) {
match game_state.reason {
3 => {
if let Some(player) = self.player {
let gamemode = Gamemode::from_int(game_state.value as i32);
*self.entities.get_component_mut(player, self.gamemode).unwrap() = gamemode;
// TODO: Temp
self.entities.get_component_mut(player, self.player_movement).unwrap().flying = gamemode.can_fly();
}
},
_ => {},
if game_state.reason == 3 {
if let Some(player) = self.player {
let gamemode = Gamemode::from_int(game_state.value as i32);
*self.entities.get_component_mut(player, self.gamemode).unwrap() = gamemode;
// TODO: Temp
self.entities.get_component_mut(player, self.player_movement).unwrap().flying = gamemode.can_fly();
}
}
}
@ -521,9 +518,9 @@ enum TeleportFlag {
}
fn calculate_relative_teleport(flag: TeleportFlag, flags: u8, base: f64, val: f64) -> f64 {
if (flags & (flag as u8)) != 0 {
base + val
} else {
if (flags & (flag as u8)) == 0 {
val
} else {
base + val
}
}

View File

@ -5081,7 +5081,7 @@ fn can_connect_redstone(world: &super::World, x: i32, y: i32, z: i32, dir: Direc
if match block { Block::RedstoneWire{..} => true, _ => false,} || match side_down { Block::RedstoneWire{..} => true, _ => false,} {
return RedstoneSide::Side;
}
return RedstoneSide::None;
RedstoneSide::None
}
fn fence_gate_data(facing: Direction, in_wall: bool, open: bool, powered: bool) -> Option<usize> {
@ -5790,7 +5790,9 @@ impl StoneSlabVariant {
fn data(&self) -> usize {
match *self {
StoneSlabVariant::Stone => 0,
StoneSlabVariant::Stone |
StoneSlabVariant::RedSandstone |
StoneSlabVariant::Purpur => 0,
StoneSlabVariant::Sandstone => 1,
StoneSlabVariant::Wood => 2,
StoneSlabVariant::Cobblestone => 3,
@ -5798,8 +5800,6 @@ impl StoneSlabVariant {
StoneSlabVariant::StoneBrick => 5,
StoneSlabVariant::NetherBrick => 6,
StoneSlabVariant::Quartz => 7,
StoneSlabVariant::RedSandstone => 0,
StoneSlabVariant::Purpur => 0,
}
}
}
@ -6079,12 +6079,10 @@ impl TreeVariant {
pub fn data(&self) -> usize {
match *self {
TreeVariant::Oak => 0,
TreeVariant::Spruce => 1,
TreeVariant::Oak | TreeVariant::Acacia => 0,
TreeVariant::Spruce | TreeVariant::DarkOak => 1,
TreeVariant::Birch => 2,
TreeVariant::Jungle => 3,
TreeVariant::Acacia => 0,
TreeVariant::DarkOak => 1,
}
}

View File

@ -375,14 +375,14 @@ impl World {
let mut bit_size = try!(data.read_u8());
let mut block_map = HashMap::with_hasher(BuildHasherDefault::<FNVHash>::default());
if bit_size != 0 {
if bit_size == 0 {
bit_size = 13;
} else {
let count = try!(VarInt::read_from(&mut data)).0;
for i in 0 .. count {
let id = try!(VarInt::read_from(&mut data)).0;
block_map.insert(i as usize, id);
}
} else {
bit_size = 13;
}
let bits = try!(LenPrefixed::<VarInt, u64>::read_from(&mut data)).data;
@ -543,10 +543,9 @@ impl Chunk {
let idx = ((z<<4)|x) as usize;
for yy in 0 .. 256 {
let sy = 255 - yy;
match self.get_block(x, sy, z) {
block::Block::Air{..} => continue,
_ => {},
};
if let block::Block::Air{..} = self.get_block(x, sy, z) {
continue
}
self.heightmap[idx] = sy as u8;
break;
}
@ -578,10 +577,9 @@ impl Chunk {
// Find a new lowest
for yy in 0 .. y {
let sy = y - yy - 1;
match self.get_block(x, sy, z) {
block::Block::Air{..} => continue,
_ => {},
};
if let block::Block::Air{..} = self.get_block(x, sy, z) {
continue
}
self.heightmap[idx] = sy as u8;
break;
}