From f5da167ce59c984c561a0c7f7f03939eea12f1f4 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 1 Jul 2019 22:42:43 +0200 Subject: [PATCH] Fix warnings and clippy recommendations in common --- chat-cli/src/main.rs | 2 +- common/src/assets/mod.rs | 19 ++++++++------ common/src/clock.rs | 9 ++----- common/src/comp/action_state.rs | 2 +- common/src/figure/mod.rs | 2 +- common/src/npc.rs | 4 +-- common/src/state.rs | 7 +++--- common/src/sys/action_state.rs | 18 +++----------- common/src/sys/agent.rs | 12 +++------ common/src/sys/animation.rs | 6 ++--- common/src/sys/combat.rs | 9 ++----- common/src/sys/controller.rs | 34 +++++++++----------------- common/src/sys/phys.rs | 18 ++++++++------ common/src/sys/stats.rs | 2 +- common/src/terrain/block.rs | 4 +-- common/src/terrain/chonk.rs | 10 ++++---- common/src/terrain/structure.rs | 4 +-- common/src/vol.rs | 4 --- common/src/volumes/vol_map_2d.rs | 12 ++++----- common/src/volumes/vol_map_3d.rs | 12 ++++----- server-cli/src/main.rs | 2 +- server/src/lib.rs | 2 +- voxygen/src/menu/char_selection/mod.rs | 2 +- voxygen/src/menu/main/mod.rs | 2 +- voxygen/src/session.rs | 2 +- voxygen/src/singleplayer.rs | 2 +- 26 files changed, 84 insertions(+), 118 deletions(-) diff --git a/chat-cli/src/main.rs b/chat-cli/src/main.rs index f166e91d9c..9f355718fa 100644 --- a/chat-cli/src/main.rs +++ b/chat-cli/src/main.rs @@ -25,7 +25,7 @@ fn main() { info!("Starting chat-cli..."); // Set up an fps clock. - let mut clock = Clock::new(); + let mut clock = Clock::start(); println!("Enter your username"); let username = read_input(); diff --git a/common/src/assets/mod.rs b/common/src/assets/mod.rs index 8cc6d9b703..f8f3b404d4 100644 --- a/common/src/assets/mod.rs +++ b/common/src/assets/mod.rs @@ -51,13 +51,16 @@ pub fn load_map A>( specifier: &str, f: F, ) -> Result, Error> { - Ok(ASSETS - .write() - .unwrap() - .entry(specifier.to_string()) - .or_insert(Arc::new(f(A::load(specifier)?))) - .clone() - .downcast()?) + let mut assets_write = ASSETS.write().unwrap(); + match assets_write.get(specifier) { + Some(asset) => Ok(Arc::clone(asset).downcast()?), + None => { + let asset = Arc::new(f(A::load(specifier)?)); + let clone = Arc::clone(&asset); + assets_write.insert(specifier.to_owned(), clone); + Ok(asset) + } + } } /// Function used to load assets. @@ -84,7 +87,7 @@ pub fn load(specifier: &str) -> Result, Error> { /// let my_image = assets::load_expect::("core.ui.backgrounds.city"); /// ``` pub fn load_expect(specifier: &str) -> Arc { - load(specifier).expect(&format!("Failed loading essential asset: {}", specifier)) + load(specifier).unwrap_or_else(|_| panic!("Failed loading essential asset: {}", specifier)) } /// Asset Trait diff --git a/common/src/clock.rs b/common/src/clock.rs index 4fa250523b..d03a95e815 100644 --- a/common/src/clock.rs +++ b/common/src/clock.rs @@ -13,8 +13,7 @@ pub struct Clock { } impl Clock { - #[allow(dead_code)] - pub fn new() -> Self { + pub fn start() -> Self { Self { last_sys_time: Instant::now(), last_delta: None, @@ -23,22 +22,18 @@ impl Clock { } } - #[allow(dead_code)] pub fn get_tps(&self) -> f64 { 1.0 / self.running_tps_average } - #[allow(dead_code)] pub fn get_last_delta(&self) -> Duration { - self.last_delta.unwrap_or(Duration::new(0, 0)) + self.last_delta.unwrap_or_else(|| Duration::new(0, 0)) } - #[allow(dead_code)] pub fn get_avg_delta(&self) -> Duration { Duration::from_secs_f64(self.running_tps_average) } - #[allow(dead_code)] pub fn tick(&mut self, tgt: Duration) { let delta = Instant::now().duration_since(self.last_sys_time); diff --git a/common/src/comp/action_state.rs b/common/src/comp/action_state.rs index 821fee92b7..546f551ef7 100644 --- a/common/src/comp/action_state.rs +++ b/common/src/comp/action_state.rs @@ -1,4 +1,4 @@ -use specs::{Component, FlaggedStorage, NullStorage, VecStorage}; +use specs::{Component, FlaggedStorage, VecStorage}; #[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct ActionState { diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index 9bdd8a821a..76ab19e8d0 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -32,7 +32,7 @@ impl From<&DotVoxData> for Segment { if let Some(&color) = palette.get(voxel.i as usize) { // TODO: Maybe don't ignore this error? let _ = segment.set( - Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| e as i32), + Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| i32::from(e)), Cell::new(color), ); } diff --git a/common/src/npc.rs b/common/src/npc.rs index 76460b0efa..b896e6f1d3 100644 --- a/common/src/npc.rs +++ b/common/src/npc.rs @@ -13,8 +13,8 @@ pub enum NpcKind { } impl NpcKind { - fn as_str(&self) -> &'static str { - match *self { + fn as_str(self) -> &'static str { + match self { NpcKind::Humanoid => "humanoid", NpcKind::Wolf => "wolf", NpcKind::Pig => "pig", diff --git a/common/src/state.rs b/common/src/state.rs index fae4382b12..5e7d3ef45c 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -82,7 +82,6 @@ impl Default for ChunkChanges { } } } - impl ChunkChanges { pub fn clear(&mut self) { self.new_chunks.clear(); @@ -99,15 +98,17 @@ pub struct State { thread_pool: Arc, } -impl State { +impl Default for State { /// Create a new `State`. - pub fn new() -> Self { + fn default() -> Self { Self { ecs: sphynx::World::new(specs::World::new(), Self::setup_sphynx_world), thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), } } +} +impl State { /// Create a new `State` from an ECS state package. pub fn from_state_package( state_package: sphynx::StatePackage, diff --git a/common/src/sys/action_state.rs b/common/src/sys/action_state.rs index aa2f27e0d0..d5852bf648 100644 --- a/common/src/sys/action_state.rs +++ b/common/src/sys/action_state.rs @@ -1,23 +1,17 @@ use crate::{ - comp::{ - ActionState, Animation, AnimationInfo, Attacking, Controller, ForceUpdate, Gliding, - Jumping, OnGround, Ori, Pos, Rolling, Vel, Wielding, - }, - state::DeltaTime, + comp::{ActionState, Attacking, Controller, Gliding, OnGround, Rolling, Vel, Wielding}, sys::phys::MOVEMENT_THRESHOLD_VEL, }; -use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; +use specs::{Entities, Join, ReadStorage, System, WriteStorage}; /// This system will set the ActionState component as specified by other components pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, - Read<'a, DeltaTime>, ReadStorage<'a, Controller>, ReadStorage<'a, Vel>, ReadStorage<'a, OnGround>, - ReadStorage<'a, Jumping>, ReadStorage<'a, Gliding>, ReadStorage<'a, Attacking>, ReadStorage<'a, Wielding>, @@ -29,11 +23,9 @@ impl<'a> System<'a> for Sys { &mut self, ( entities, - dt, controllers, // To make sure it only runs on the single client and the server velocities, on_grounds, - jumpings, glidings, attackings, wieldings, @@ -42,22 +34,20 @@ impl<'a> System<'a> for Sys { ): Self::SystemData, ) { for ( - entity, + _entity, vel, _controller, on_ground, - jumping, gliding, attacking, wielding, rolling, - mut action_state, + action_state, ) in ( &entities, &velocities, &controllers, on_grounds.maybe(), - jumpings.maybe(), glidings.maybe(), attackings.maybe(), wieldings.maybe(), diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 7ecd5fec42..ba1d97c126 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -1,5 +1,4 @@ -use crate::comp::{Agent, Attacking, Controller, Jumping, Pos}; -use log::warn; +use crate::comp::{Agent, Controller, Pos}; use rand::{seq::SliceRandom, thread_rng}; use specs::{Entities, Join, ReadStorage, System, WriteStorage}; use vek::*; @@ -12,15 +11,10 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Agent>, ReadStorage<'a, Pos>, WriteStorage<'a, Controller>, - WriteStorage<'a, Jumping>, - WriteStorage<'a, Attacking>, ); - fn run( - &mut self, - (entities, mut agents, positions, mut controllers, mut jumps, mut attacks): Self::SystemData, - ) { - for (entity, agent, pos, controller) in + fn run(&mut self, (entities, mut agents, positions, mut controllers): Self::SystemData) { + for (_entity, agent, pos, controller) in (&entities, &mut agents, &positions, &mut controllers).join() { match agent { diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index 00f811a389..d03938668f 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -1,5 +1,5 @@ use crate::{ - comp::{ActionState, Animation, AnimationInfo, ForceUpdate}, + comp::{ActionState, Animation, AnimationInfo}, state::DeltaTime, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; @@ -46,9 +46,9 @@ impl<'a> System<'a> for Sys { let new_time = animation_infos .get(entity) .filter(|i| i.animation == animation) - .map(|i| i.time + dt.0 as f64); + .map(|i| i.time + f64::from(dt.0)); - animation_infos.insert( + let _ = animation_infos.insert( entity, AnimationInfo { animation, diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 46bce443ae..e307d27909 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -1,10 +1,7 @@ use crate::{ - comp::{ - Attacking, HealthSource, Stats, Wielding, {ForceUpdate, Ori, Pos, Vel}, - }, + comp::{Attacking, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel}, state::{DeltaTime, Uid}, }; -use log::warn; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; /// This system is responsible for handling accepted inputs like moving or attacking @@ -18,7 +15,6 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Ori>, WriteStorage<'a, Vel>, WriteStorage<'a, Attacking>, - WriteStorage<'a, Wielding>, WriteStorage<'a, Stats>, WriteStorage<'a, ForceUpdate>, ); @@ -33,7 +29,6 @@ impl<'a> System<'a> for Sys { orientations, mut velocities, mut attackings, - mut wieldings, mut stats, mut force_updates, ): Self::SystemData, @@ -44,7 +39,7 @@ impl<'a> System<'a> for Sys { .filter_map(|(entity, uid, pos, ori, mut attacking)| { if !attacking.applied { // Go through all other entities - for (b, pos_b, mut vel_b, mut stat_b) in + for (b, pos_b, mut vel_b, stat_b) in (&entities, &positions, &mut velocities, &mut stats).join() { // Check if it is a hit diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index 84cd440ef7..a0dfd59858 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -1,23 +1,16 @@ -use crate::{ - comp::{ - ActionState, Animation, AnimationInfo, Attacking, Controller, Gliding, HealthSource, - Jumping, MoveDir, OnGround, Respawning, Rolling, Stats, {ForceUpdate, Ori, Pos, Vel}, - }, - state::DeltaTime, +use crate::comp::{ + ActionState, Attacking, Controller, Gliding, Jumping, MoveDir, Respawning, Rolling, Stats, Vel, }; -use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; +use specs::{Entities, Join, ReadStorage, System, WriteStorage}; /// This system is responsible for validating controller inputs pub struct Sys; impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, - Read<'a, DeltaTime>, ReadStorage<'a, Controller>, ReadStorage<'a, Stats>, - ReadStorage<'a, Pos>, ReadStorage<'a, Vel>, - ReadStorage<'a, Ori>, WriteStorage<'a, ActionState>, WriteStorage<'a, MoveDir>, WriteStorage<'a, Jumping>, @@ -31,12 +24,9 @@ impl<'a> System<'a> for Sys { &mut self, ( entities, - dt, controllers, stats, - positions, velocities, - orientations, mut action_states, mut move_dirs, mut jumpings, @@ -46,13 +36,11 @@ impl<'a> System<'a> for Sys { mut glidings, ): Self::SystemData, ) { - for (entity, controller, stats, pos, vel, ori, mut a) in ( + for (entity, controller, stats, vel, mut a) in ( &entities, &controllers, &stats, - &positions, &velocities, - &orientations, // Although this is changed, it is only kept for this system // as it will be replaced in the action state system &mut action_states, @@ -62,14 +50,14 @@ impl<'a> System<'a> for Sys { if stats.is_dead { // Respawn if controller.respawn { - respawns.insert(entity, Respawning); + let _ = respawns.insert(entity, Respawning); } continue; } // Move dir if !a.rolling { - move_dirs.insert( + let _ = move_dirs.insert( entity, MoveDir(if controller.move_dir.magnitude_squared() > 1.0 { controller.move_dir.normalized() @@ -81,16 +69,16 @@ impl<'a> System<'a> for Sys { // Glide if controller.glide && !a.on_ground && !a.attacking && !a.rolling { - glidings.insert(entity, Gliding); + let _ = glidings.insert(entity, Gliding); a.gliding = true; } else { - glidings.remove(entity); + let _ = glidings.remove(entity); a.gliding = false; } // Attack if controller.attack && !a.attacking && !a.gliding && !a.rolling { - attackings.insert(entity, Attacking::start()); + let _ = attackings.insert(entity, Attacking::start()); a.attacking = true; } @@ -102,13 +90,13 @@ impl<'a> System<'a> for Sys { && !a.attacking && !a.gliding { - rollings.insert(entity, Rolling::start()); + let _ = rollings.insert(entity, Rolling::start()); a.rolling = true; } // Jump if controller.jump && a.on_ground && vel.0.z <= 0.0 { - jumpings.insert(entity, Jumping); + let _ = jumpings.insert(entity, Jumping); a.on_ground = false; } } diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index eed85cd56a..5b54e650ca 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,5 +1,5 @@ use crate::{ - comp::{ActionState, Gliding, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel}, + comp::{ActionState, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel}, state::DeltaTime, terrain::TerrainMap, vol::{ReadVol, Vox}, @@ -45,7 +45,6 @@ impl<'a> System<'a> for Sys { ReadExpect<'a, TerrainMap>, Read<'a, DeltaTime>, ReadStorage<'a, MoveDir>, - ReadStorage<'a, Gliding>, ReadStorage<'a, Stats>, ReadStorage<'a, ActionState>, WriteStorage<'a, Jumping>, @@ -63,7 +62,6 @@ impl<'a> System<'a> for Sys { terrain, dt, move_dirs, - glidings, stats, action_states, mut jumpings, @@ -225,7 +223,7 @@ impl<'a> System<'a> for Sys { }; // Determine the block that we are colliding with most (based on minimum collision axis) - let (block_pos, block_aabb) = near_iter + let (_block_pos, block_aabb) = near_iter .clone() // Calculate the block's position in world space .map(|(i, j, k)| pos.0.map(|e| e.floor() as i32) + Vec3::new(i, j, k)) @@ -262,7 +260,13 @@ impl<'a> System<'a> for Sys { // Determine an appropriate resolution vector (i.e: the minimum distance needed to push out of the block) let max_axis = dir.map(|e| e.abs()).reduce_partial_min(); - let resolve_dir = -dir.map(|e| if e.abs() == max_axis { e } else { 0.0 }); + let resolve_dir = -dir.map(|e| { + if e.abs().to_bits() == max_axis.to_bits() { + e + } else { + 0.0 + } + }); // When the resolution direction is pointing upwards, we must be on the ground if resolve_dir.z > 0.0 && vel.0.z <= 0.0 { @@ -302,7 +306,7 @@ impl<'a> System<'a> for Sys { } if on_ground { - on_grounds.insert(entity, OnGround); + let _ = on_grounds.insert(entity, OnGround); // If we're not on the ground but the space below us is free, then "snap" to the ground } else if collision_with(pos.0 - Vec3::unit_z() * 1.05, near_iter.clone()) && vel.0.z < 0.0 @@ -310,7 +314,7 @@ impl<'a> System<'a> for Sys { && was_on_ground { pos.0.z = (pos.0.z - 0.05).floor(); - on_grounds.insert(entity, OnGround); + let _ = on_grounds.insert(entity, OnGround); } } } diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 86e91111fa..d25480bd45 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -33,7 +33,7 @@ impl<'a> System<'a> for Sys { stat.is_dead = true; } if let Some(change) = &mut stat.health.last_change { - change.1 += dt.0 as f64; + change.1 += f64::from(dt.0); } } } diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index fce23c4a57..f95f2cd9aa 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -16,7 +16,7 @@ impl Block { } } - pub fn get_color(&self) -> Option> { + pub fn get_color(self) -> Option> { if self.is_empty() { None } else { @@ -24,7 +24,7 @@ impl Block { } } - pub fn get_opacity(&self) -> Option { + pub fn get_opacity(self) -> Option { match self.kind { 0 => None, 1 => Some(0.85), diff --git a/common/src/terrain/chonk.rs b/common/src/terrain/chonk.rs index ed8c7a60b1..1d5d637988 100644 --- a/common/src/terrain/chonk.rs +++ b/common/src/terrain/chonk.rs @@ -117,7 +117,7 @@ impl ReadVol for Chonk { - Vec3::unit_z() * (self.z_offset + sub_chunk_idx as i32 * SUB_CHUNK_HEIGHT as i32); - chunk.get(rpos).map_err(|err| ChonkError::ChunkError(err)) + chunk.get(rpos).map_err(ChonkError::ChunkError) } } } @@ -197,7 +197,7 @@ impl WriteVol for Chonk { let mut new_chunk = Chunk::filled(*cblock, ()); for (map_pos, map_block) in map { new_chunk - .set(map_pos.map(|e| e as i32), *map_block) + .set(map_pos.map(|e| i32::from(e)), *map_block) .unwrap(); // Can't fail (I hope!) } @@ -217,9 +217,9 @@ impl WriteVol for Chonk { Ok(()) } */ - SubChunk::Heterogeneous(chunk) => chunk - .set(rpos, block) - .map_err(|err| ChonkError::ChunkError(err)), + SubChunk::Heterogeneous(chunk) => { + chunk.set(rpos, block).map_err(ChonkError::ChunkError) + } //_ => unimplemented!(), } } diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index a218d62a99..9eb4740456 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -86,13 +86,13 @@ impl Asset for Structure { let color = palette .get(index as usize) .copied() - .unwrap_or(Rgb::broadcast(0)); + .unwrap_or_else(|| Rgb::broadcast(0)); StructureBlock::Block(Block::new(1, color)) } }; let _ = vol.set( - Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| e as i32), + Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| i32::from(e)), block, ); } diff --git a/common/src/vol.rs b/common/src/vol.rs index e1f70e48a9..47307344fc 100644 --- a/common/src/vol.rs +++ b/common/src/vol.rs @@ -56,7 +56,6 @@ impl Iterator for VoxPosIter { /// A volume that has a finite size. pub trait SizedVol: BaseVol { /// Get the size of the volume. - #[inline(always)] fn get_size(&self) -> Vec3; /// Iterate through all potential voxel positions in this volume. @@ -71,10 +70,8 @@ pub trait SizedVol: BaseVol { /// A volume that provides read access to its voxel data. pub trait ReadVol: BaseVol { /// Get a reference to the voxel at the provided position in the volume. - #[inline(always)] fn get(&self, pos: Vec3) -> Result<&Self::Vox, Self::Err>; - #[inline(always)] unsafe fn get_unchecked(&self, pos: Vec3) -> &Self::Vox { self.get(pos).unwrap() } @@ -103,7 +100,6 @@ pub trait SampleVol: BaseVol { /// A volume that provides write access to its voxel data. pub trait WriteVol: BaseVol { /// Set the voxel at the provided position in the volume to the provided value. - #[inline(always)] fn set(&mut self, pos: Vec3, vox: Self::Vox) -> Result<(), Self::Err>; } diff --git a/common/src/volumes/vol_map_2d.rs b/common/src/volumes/vol_map_2d.rs index 0f6f53233b..c77b98d0ea 100644 --- a/common/src/volumes/vol_map_2d.rs +++ b/common/src/volumes/vol_map_2d.rs @@ -29,7 +29,7 @@ impl VolMap2d { pos.into().map2(S::SIZE.into(), |e, sz: u32| { // Horrid, but it's faster than a cheetah with a red bull blood transfusion let log2 = (sz - 1).count_ones(); - ((((e as i64 + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32 + ((((i64::from(e) + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32 }) } @@ -37,7 +37,7 @@ impl VolMap2d { pub fn chunk_offs(pos: Vec3) -> Vec3 { let offs = pos.map2(S::SIZE, |e, sz| { // Horrid, but it's even faster than the aforementioned cheetah - (((e as i64 + (1 << 32)) as u64) & (sz - 1) as u64) as i32 + (((i64::from(e) + (1 << 32)) as u64) & u64::from(sz - 1)) as i32 }); Vec3::new(offs.x, offs.y, pos.z) } @@ -57,7 +57,7 @@ impl ReadVol for VolMap2d { .ok_or(VolMap2dErr::NoSuchChunk) .and_then(|chunk| { let co = Self::chunk_offs(pos); - chunk.get(co).map_err(|err| VolMap2dErr::ChunkErr(err)) + chunk.get(co).map_err(VolMap2dErr::ChunkErr) }) } @@ -87,7 +87,7 @@ impl>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for y in chunk_min.y..=chunk_max.y { let chunk_key = Vec2::new(x, y); - let chunk = self.get_key_arc(chunk_key).map(|v| v.clone()); + let chunk = self.get_key_arc(chunk_key).cloned(); if let Some(chunk) = chunk { sample.insert(chunk_key, chunk); @@ -110,7 +110,7 @@ impl WriteVol for Vol let co = Self::chunk_offs(pos); Arc::make_mut(chunk) .set(co, vox) - .map_err(|err| VolMap2dErr::ChunkErr(err)) + .map_err(VolMap2dErr::ChunkErr) }) } } @@ -169,7 +169,7 @@ impl VolMap2d { Self::chunk_key(pos) } - pub fn iter<'a>(&'a self) -> ChunkIter<'a, V> { + pub fn iter(&self) -> ChunkIter { ChunkIter { iter: self.chunks.iter(), } diff --git a/common/src/volumes/vol_map_3d.rs b/common/src/volumes/vol_map_3d.rs index b4b5405ccc..ad3bc42b9c 100644 --- a/common/src/volumes/vol_map_3d.rs +++ b/common/src/volumes/vol_map_3d.rs @@ -28,7 +28,7 @@ impl VolMap3d { pos.map2(S::SIZE, |e, sz| { // Horrid, but it's faster than a cheetah with a red bull blood transfusion let log2 = (sz - 1).count_ones(); - ((((e as i64 + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32 + ((((i64::from(e) + (1 << 32)) as u64) >> log2) - (1 << (32 - log2))) as i32 }) } @@ -36,7 +36,7 @@ impl VolMap3d { pub fn chunk_offs(pos: Vec3) -> Vec3 { pos.map2(S::SIZE, |e, sz| { // Horrid, but it's even faster than the aforementioned cheetah - (((e as i64 + (1 << 32)) as u64) & (sz - 1) as u64) as i32 + (((i64::from(e) + (1 << 32)) as u64) & u64::from(sz - 1)) as i32 }) } } @@ -55,7 +55,7 @@ impl ReadVol for VolMap3d { .ok_or(VolMap3dErr::NoSuchChunk) .and_then(|chunk| { let co = Self::chunk_offs(pos); - chunk.get(co).map_err(|err| VolMap3dErr::ChunkErr(err)) + chunk.get(co).map_err(VolMap3dErr::ChunkErr) }) } } @@ -78,7 +78,7 @@ impl>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol for z in chunk_min.z..=chunk_max.z { let chunk_key = Vec3::new(x, y, z); - let chunk = self.get_key_arc(chunk_key).map(|v| v.clone()); + let chunk = self.get_key_arc(chunk_key).cloned(); if let Some(chunk) = chunk { sample.insert(chunk_key, chunk); @@ -102,7 +102,7 @@ impl WriteVol for Vol let co = Self::chunk_offs(pos); Arc::make_mut(chunk) .set(co, vox) - .map_err(|err| VolMap3dErr::ChunkErr(err)) + .map_err(VolMap3dErr::ChunkErr) }) } } @@ -153,7 +153,7 @@ impl VolMap3d { Self::chunk_key(pos) } - pub fn iter<'a>(&'a self) -> ChunkIter<'a, V> { + pub fn iter(&self) -> ChunkIter { ChunkIter { iter: self.chunks.iter(), } diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index f88c2c545a..d53aca5d91 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -12,7 +12,7 @@ fn main() { info!("Starting server-cli..."); // Set up an fps clock - let mut clock = Clock::new(); + let mut clock = Clock::start(); // Create server let mut server = Server::new().expect("Failed to create server instance!"); diff --git a/server/src/lib.rs b/server/src/lib.rs index c9c6702900..f32530cbf6 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -80,7 +80,7 @@ impl Server { pub fn bind>(addrs: A) -> Result { let (chunk_tx, chunk_rx) = mpsc::channel(); - let mut state = State::new(); + let mut state = State::default(); state .ecs_mut() .add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 305.0))); diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index f3d5bbdd46..3aeee92da1 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -42,7 +42,7 @@ const BG_COLOR: Rgba = Rgba { impl PlayState for CharSelectionState { fn play(&mut self, _: Direction, global_state: &mut GlobalState) -> PlayStateResult { // Set up an fps clock. - let mut clock = Clock::new(); + let mut clock = Clock::start(); let mut current_client_state = self.client.borrow().get_client_state(); while let ClientState::Pending | ClientState::Registered = current_client_state { diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index cbe1033b30..b0f0b609de 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -38,7 +38,7 @@ const BG_COLOR: Rgba = Rgba { impl PlayState for MainMenuState { fn play(&mut self, _: Direction, global_state: &mut GlobalState) -> PlayStateResult { // Set up an fps clock. - let mut clock = Clock::new(); + let mut clock = Clock::start(); // Used for client creation. let mut client_init: Option = None; diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index e26b4cf4c4..60b401158b 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -88,7 +88,7 @@ impl PlayState for SessionState { global_state.window.grab_cursor(true); // Set up an fps clock. - let mut clock = Clock::new(); + let mut clock = Clock::start(); self.client.borrow_mut().clear_terrain(); // Game loop diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index 381fd0cef6..2f8d076529 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -65,7 +65,7 @@ fn run_server(mut server: Server, rec: Receiver) { info!("Starting server-cli..."); // Set up an fps clock - let mut clock = Clock::new(); + let mut clock = Clock::start(); loop { let events = server