From 6b09fd7c530465029f4585def673b45a4110f173 Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 17 May 2019 05:22:32 -0400 Subject: [PATCH] Pedantic comment and language fixes. Former-commit-id: eb49765c911aaa97a9c8ed351216a7a6f8411213 --- .gitlab-ci.yml | 4 +- chat-cli/src/main.rs | 10 +- client/src/lib.rs | 36 +++--- common/src/assets/mod.rs | 20 ++-- common/src/clock.rs | 2 +- common/src/comp/actor.rs | 33 +++--- common/src/comp/phys.rs | 8 +- common/src/figure/cell.rs | 2 +- common/src/lib.rs | 2 +- common/src/msg/ecs_packet.rs | 9 +- common/src/net/data.rs | 10 +- common/src/net/post.rs | 14 +-- common/src/net/post2.rs | 14 +-- common/src/ray.rs | 2 +- common/src/state.rs | 58 +++++----- common/src/sys/agent.rs | 6 +- common/src/sys/control.rs | 10 +- common/src/sys/phys.rs | 4 +- common/src/vol.rs | 6 +- common/src/volumes/chunk.rs | 4 +- common/src/volumes/dyna.rs | 4 +- common/src/volumes/vol_map.rs | 0 server-cli/src/main.rs | 6 +- server/src/cmd.rs | 35 +++--- server/src/input.rs | 2 +- server/src/lib.rs | 103 +++++++++-------- voxygen/src/anim/character/gliding.rs | 63 ++++++----- voxygen/src/anim/character/idle.rs | 28 ++--- voxygen/src/anim/character/jump.rs | 25 ++-- voxygen/src/anim/character/run.rs | 26 ++--- voxygen/src/anim/mod.rs | 8 +- voxygen/src/anim/quadruped/idle.rs | 52 ++++----- voxygen/src/anim/quadruped/jump.rs | 44 ++++---- voxygen/src/anim/quadruped/mod.rs | 48 ++++---- voxygen/src/anim/quadruped/run.rs | 58 +++++----- voxygen/src/error.rs | 10 +- voxygen/src/hud/buttons.rs | 6 +- voxygen/src/hud/character_window.rs | 17 ++- voxygen/src/hud/chat.rs | 23 ++-- voxygen/src/hud/esc_menu.rs | 4 +- voxygen/src/hud/minimap.rs | 2 +- voxygen/src/hud/mod.rs | 50 ++++---- voxygen/src/hud/settings_window.rs | 10 +- voxygen/src/hud/skillbar.rs | 9 +- voxygen/src/main.rs | 40 +++---- voxygen/src/menu/char_selection/mod.rs | 26 ++--- voxygen/src/menu/char_selection/ui.rs | 119 ++++++++++---------- voxygen/src/menu/main/client_init.rs | 32 +++--- voxygen/src/menu/main/mod.rs | 28 ++--- voxygen/src/menu/main/start_singleplayer.rs | 11 +- voxygen/src/menu/main/ui.rs | 4 +- voxygen/src/mesh/vol.rs | 4 +- voxygen/src/render/consts.rs | 2 +- voxygen/src/render/mesh.rs | 8 +- voxygen/src/render/mod.rs | 2 +- voxygen/src/render/model.rs | 4 +- voxygen/src/render/pipelines/mod.rs | 4 +- voxygen/src/render/renderer.rs | 19 ++-- voxygen/src/render/texture.rs | 4 +- voxygen/src/render/util.rs | 2 +- voxygen/src/scene/camera.rs | 8 +- voxygen/src/scene/figure.rs | 84 +++++++------- voxygen/src/scene/figure/figure.rs | 18 +-- voxygen/src/scene/figure/figurequad.rs | 18 +-- voxygen/src/scene/mod.rs | 28 ++--- voxygen/src/scene/terrain.rs | 34 +++--- voxygen/src/session.rs | 45 ++++---- voxygen/src/settings.rs | 16 +-- voxygen/src/singleplayer.rs | 10 +- voxygen/src/ui/event.rs | 8 +- voxygen/src/ui/font_ids.rs | 2 +- voxygen/src/ui/graphic/graphic.rs | 21 ++-- voxygen/src/ui/graphic/renderer.rs | 8 +- voxygen/src/ui/img_ids.rs | 2 +- voxygen/src/ui/mod.rs | 88 +++++++-------- voxygen/src/ui/scale.rs | 23 ++-- voxygen/src/ui/widgets/image_slider.rs | 14 +-- voxygen/src/ui/widgets/toggle_button.rs | 6 +- voxygen/src/window.rs | 20 ++-- world/src/lib.rs | 2 +- 80 files changed, 835 insertions(+), 816 deletions(-) create mode 100644 common/src/volumes/vol_map.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 398e93b29b..61317e2790 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,8 +4,8 @@ stages: - post-build - executable -# our own git fetch command like https://gitlab.com/gitlab-org/gitlab-runner/blob/master/shells/abstract.go -# speeds up building because we skip the git clean and dont need any gitlab caches +# Our own git fetch command like https://gitlab.com/gitlab-org/gitlab-runner/blob/master/shells/abstract.go +# speeds up building because we skip the git clean and don't need any gitlab caches. variables: GIT_STRATEGY: none before_script: diff --git a/chat-cli/src/main.rs b/chat-cli/src/main.rs index 411e4367f9..7fa1022b3a 100644 --- a/chat-cli/src/main.rs +++ b/chat-cli/src/main.rs @@ -6,15 +6,15 @@ use std::time::Duration; const FPS: u64 = 60; fn main() { - // Init logging + // Initialize logging. pretty_env_logger::init(); info!("Starting chat-cli..."); - // Set up an fps clock + // Set up an fps clock. let mut clock = Clock::new(); - // Create client + // Create a client. let mut client = Client::new(([127, 0, 0, 1], 59003), 300).expect("Failed to create client instance"); @@ -38,10 +38,10 @@ fn main() { } } - // Clean up the server after a tick + // Clean up the server after a tick. client.cleanup(); - // Wait for the next tick + // Wait for the next tick. clock.tick(Duration::from_millis(1000 / FPS)); } } diff --git a/client/src/lib.rs b/client/src/lib.rs index 514c6448ae..d1e4d1508a 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -95,7 +95,7 @@ impl Client { } /// Get a reference to the client's worker thread pool. This pool should be used for any - /// computationally expensive operations that run outside of the main thread (i.e: threads that + /// computationally expensive operations that run outside of the main thread (i.e., threads that /// block on I/O operations are exempt). #[allow(dead_code)] pub fn thread_pool(&self) -> &threadpool::ThreadPool { @@ -114,7 +114,7 @@ impl Client { &mut self.state } - /// Get the player's entity + /// Get the player's entity. #[allow(dead_code)] pub fn entity(&self) -> EcsEntity { self.entity @@ -126,13 +126,13 @@ impl Client { self.tick } - /// Send a chat message to the server + /// Send a chat message to the server. #[allow(dead_code)] pub fn send_chat(&mut self, msg: String) { self.postbox.send_message(ClientMsg::Chat(msg)) } - /// Execute a single client tick, handle input and update the game state by the given duration + /// Execute a single client tick, handle input and update the game state by the given duration. #[allow(dead_code)] pub fn tick(&mut self, input: Input, dt: Duration) -> Result, Error> { // This tick function is the centre of the Veloren universe. Most client-side things are @@ -147,13 +147,13 @@ impl Client { // 4) Go through the terrain update queue and apply all changes to the terrain // 5) Finish the tick, passing control of the main thread back to the frontend - // Build up a list of events for this frame, to be passed to the frontend + // Build up a list of events for this frame, to be passed to the frontend. let mut frontend_events = Vec::new(); - // Handle new messages from the server + // Handle new messages from the server. frontend_events.append(&mut self.handle_new_messages()?); - // Pass character control from frontend input to the player's entity + // Pass character control from frontend input to the player's entity. // TODO: Only do this if the entity already has a Control component! self.state.write_component( self.entity, @@ -164,10 +164,10 @@ impl Client { }, ); - // Tick the client's LocalState (step 3) + // Tick the client's LocalState (step 3). self.state.tick(dt); - // Update the server about the player's physics attributes + // Update the server about the player's physics attributes. match ( self.state.read_storage().get(self.entity).cloned(), self.state.read_storage().get(self.entity).cloned(), @@ -180,7 +180,7 @@ impl Client { _ => {} } - // Update the server about the player's currently playing animation and the previous one + // Update the server about the player's currently playing animation and the previous one. if let Some(animation_history) = self .state .read_storage::() @@ -201,7 +201,7 @@ impl Client { if let Some(pos) = pos { let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32)); - // Remove chunks that are too far from the player + // Remove chunks that are too far from the player. let mut chunks_to_remove = Vec::new(); self.state.terrain().iter().for_each(|(key, _)| { if (Vec2::from(chunk_pos) - Vec2::from(key)) @@ -216,8 +216,8 @@ impl Client { self.state.remove_chunk(key); } - // Request chunks from the server - // TODO: This is really not very efficient + // Request chunks from the server. + // TODO: This is really inefficient. 'outer: for dist in 0..10 { for i in chunk_pos.x - dist..chunk_pos.x + dist + 1 { for j in chunk_pos.y - dist..chunk_pos.y + dist + 1 { @@ -237,25 +237,25 @@ impl Client { } } - // If chunks are taking too long, assume they're no longer pending + // If chunks are taking too long, assume they're no longer pending. let now = Instant::now(); self.pending_chunks .retain(|_, created| now.duration_since(*created) < Duration::from_secs(10)); } - // Finish the tick, pass control back to the frontend (step 6) + // Finish the tick, pass control back to the frontend (step 6). self.tick += 1; Ok(frontend_events) } - /// Clean up the client after a tick + /// Clean up the client after a tick. #[allow(dead_code)] pub fn cleanup(&mut self) { // Cleanup the local state self.state.cleanup(); } - /// Handle new server messages + /// Handle new server messages. fn handle_new_messages(&mut self) -> Result, Error> { let mut frontend_events = Vec::new(); @@ -324,7 +324,7 @@ impl Client { } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT { return Err(Error::ServerTimeout); } else if self.state.get_time() - self.last_ping > SERVER_TIMEOUT * 0.5 { - // Try pinging the server if the timeout is nearing + // Try pinging the server if the timeout is nearing. self.postbox.send_message(ClientMsg::Ping); } diff --git a/common/src/assets/mod.rs b/common/src/assets/mod.rs index 5a98f4e57a..84774db8d7 100644 --- a/common/src/assets/mod.rs +++ b/common/src/assets/mod.rs @@ -12,9 +12,9 @@ use std::{ #[derive(Debug, Clone)] pub enum Error { - /// An asset of a different type has already been loaded with this specifier + /// An asset of a different type has already been loaded with this specifier. InvalidType, - /// Asset does not exist + /// Asset does not exist. NotFound(String), } @@ -35,8 +35,8 @@ lazy_static! { RwLock::new(HashMap::new()); } -/// Function used to load assets -/// loaded assets are cached in a global singleton hashmap +/// Function used to load assets. +/// Loaded assets are cached in a global singleton hashmap. /// Example usage: /// ```no_run /// use image::DynamicImage; @@ -54,9 +54,9 @@ pub fn load(specifier: &str) -> Result, Error> { .downcast()?) } -/// Function used to load assets that will panic if the asset is not found -/// Use this to load essential assets -/// loaded assets are cached in a global singleton hashmap +/// Function used to load assets that will panic if the asset is not found. +/// Use this to load essential assets. +/// Loaded assets are cached in a global singleton hashmap. /// Example usage: /// ```no_run /// use image::DynamicImage; @@ -89,11 +89,11 @@ impl Asset for DotVoxData { } } -// TODO: System to load file from specifiers (eg "core.ui.backgrounds.city") +// TODO: System to load file from specifiers (e.g.: "core.ui.backgrounds.city"). fn try_open_with_path(name: &str) -> Option { debug!("Trying to access \"{}\"", name); - // TODO: don't do this? - // if it's stupid and it works.., + // TODO: Don't do this? + // If it's stupid but it works... [ "assets".to_string(), "../assets".to_string(), /* optimizations */ diff --git a/common/src/clock.rs b/common/src/clock.rs index 09f2d2716c..5538b4c636 100644 --- a/common/src/clock.rs +++ b/common/src/clock.rs @@ -43,7 +43,7 @@ impl Clock { .duration_since(self.last_sys_time) .expect("Time went backwards!"); - // Attempt to sleep to fill the gap + // Attempt to sleep to fill the gap. if let Some(sleep_dur) = tgt.checked_sub(delta) { let adjustment = if self.running_tps_average == 0.0 { 1.0 diff --git a/common/src/comp/actor.rs b/common/src/comp/actor.rs index 885f53381e..5cb24a6a39 100644 --- a/common/src/comp/actor.rs +++ b/common/src/comp/actor.rs @@ -71,24 +71,23 @@ pub enum Draw { } //// #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Pighead { +pub enum PigHead { Default, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Pigchest { +pub enum PigChest { Default, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Pigleg_l { +pub enum PigLegL { Default, } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Pigleg_r { +pub enum PigLegR { Default, } -//// const ALL_RACES: [Race; 6] = [ Race::Danari, @@ -158,19 +157,19 @@ const ALL_QRACES: [Race; 6] = [ Race::Undead, ]; const ALL_QBODY_TYPES: [BodyType; 3] = [BodyType::Female, BodyType::Male, BodyType::Unspecified]; -const ALL_QHEADS: [Pighead; 1] = [Pighead::Default]; -const ALL_QCHESTS: [Pigchest; 1] = [Pigchest::Default]; -const ALL_QPIGLEG_LS: [Pigleg_l; 1] = [Pigleg_l::Default]; -const ALL_QPIGLEG_RS: [Pigleg_r; 1] = [Pigleg_r::Default]; +const ALL_QPIG_HEADS: [PigHead; 1] = [PigHead::Default]; +const ALL_QPIG_CHESTS: [PigChest; 1] = [PigChest::Default]; +const ALL_QPIG_LEG_LS: [PigLegL; 1] = [PigLegL::Default]; +const ALL_QPIG_LEG_RS: [PigLegR; 1] = [PigLegR::Default]; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct QuadrupedBody { pub race: Race, pub body_type: BodyType, - pub pighead: Pighead, - pub pigchest: Pigchest, - pub pigleg_l: Pigleg_l, - pub pigleg_r: Pigleg_r, + pub pig_head: PigHead, + pub pig_chest: PigChest, + pub pig_leg_l: PigLegL, + pub pig_leg_r: PigLegR, } impl QuadrupedBody { @@ -178,10 +177,10 @@ impl QuadrupedBody { Self { race: *thread_rng().choose(&ALL_QRACES).unwrap(), body_type: *thread_rng().choose(&ALL_QBODY_TYPES).unwrap(), - pighead: *thread_rng().choose(&ALL_QHEADS).unwrap(), - pigchest: *thread_rng().choose(&ALL_QCHESTS).unwrap(), - pigleg_l: *thread_rng().choose(&ALL_QPIGLEG_LS).unwrap(), - pigleg_r: *thread_rng().choose(&ALL_QPIGLEG_RS).unwrap(), + pig_head: *thread_rng().choose(&ALL_QPIG_HEADS).unwrap(), + pig_chest: *thread_rng().choose(&ALL_QPIG_CHESTS).unwrap(), + pig_leg_l: *thread_rng().choose(&ALL_QPIG_LEG_LS).unwrap(), + pig_leg_r: *thread_rng().choose(&ALL_QPIG_LEG_RS).unwrap(), } } } diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index 67df6ac1ba..cb9765b6c1 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -1,7 +1,7 @@ use specs::{Component, FlaggedStorage, NullStorage, VecStorage}; use vek::*; -// Pos +// Position #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Pos(pub Vec3); @@ -10,7 +10,7 @@ impl Component for Pos { type Storage = VecStorage; } -// Vel +// Velocity #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Vel(pub Vec3); @@ -19,7 +19,7 @@ impl Component for Vel { type Storage = VecStorage; } -// Dir +// Direction #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Dir(pub Vec3); @@ -28,7 +28,7 @@ impl Component for Dir { type Storage = VecStorage; } -// Dir +// Update #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct ForceUpdate; diff --git a/common/src/figure/cell.rs b/common/src/figure/cell.rs index 2d445dcf3d..a76e19d867 100644 --- a/common/src/figure/cell.rs +++ b/common/src/figure/cell.rs @@ -4,7 +4,7 @@ use vek::*; // Crate use crate::vol::Vox; -/// A type representing a single voxel in a figure +/// A type representing a single voxel in a figure. #[derive(Copy, Clone, Debug)] pub enum Cell { Filled([u8; 3]), diff --git a/common/src/lib.rs b/common/src/lib.rs index a783a78366..d52324a41b 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -23,7 +23,7 @@ pub mod util; pub mod vol; pub mod volumes; -/// The networking module containing high-level wrappers of `TcpListener` and `TcpStream` (`PostOffice` and `PostBox` respectively) and data types used by both the server and client +/// The networking module containing high-level wrappers of `TcpListener` and `TcpStream` (`PostOffice` and `PostBox` respectively) and data types used by both the server and client. /// # Examples /// ``` /// use std::net::SocketAddr; diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index ffb5898e86..32af121dc4 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -2,7 +2,8 @@ use crate::{comp, state}; use serde_derive::{Deserialize, Serialize}; use std::marker::PhantomData; -// Automatically derive From for EcsResPacket for each variant EcsResPacket::T(T) +// Automatically derive From for EcsResPacket +// for each variant EcsResPacket::T(T). sphynx::sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsResPacket { @@ -11,7 +12,8 @@ sphynx::sum_type! { } } impl sphynx::ResPacket for EcsResPacket {} -// Automatically derive From for EcsCompPacket for each variant EcsCompPacket::T(T) +// Automatically derive From for EcsCompPacket +// for each variant EcsCompPacket::T(T.) sphynx::sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPacket { @@ -23,7 +25,8 @@ sphynx::sum_type! { Stats(comp::Stats), } } -// Automatically derive From for EcsCompPhantom for each variant EcsCompPhantom::T(PhantomData) +// Automatically derive From for EcsCompPhantom +// for each variant EcsCompPhantom::T(PhantomData). sphynx::sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPhantom { diff --git a/common/src/net/data.rs b/common/src/net/data.rs index ee0b19090a..3239321f56 100644 --- a/common/src/net/data.rs +++ b/common/src/net/data.rs @@ -1,18 +1,18 @@ -/// Messages server sends to client +/// Messages server sends to client. #[derive(Deserialize, Serialize, Debug)] pub enum ServerMsg { - // VersionInfo MUST always stay first in this struct + // VersionInfo MUST always stay first in this struct. VersionInfo {}, } -/// Messages client sends to server +/// Messages client sends to server. #[derive(Deserialize, Serialize, Debug)] pub enum ClientMsg { - // VersionInfo MUST always stay first in this struct + // VersionInfo MUST always stay first in this struct. VersionInfo {}, } -/// Control message type, used in [PostBox](super::PostBox) and [PostOffice](super::PostOffice) to control threads +/// Control message type, used in [PostBox](super::PostBox) and [PostOffice](super::PostOffice) to control threads. pub enum ControlMsg { Shutdown, } diff --git a/common/src/net/post.rs b/common/src/net/post.rs index 38a8533186..3feab15866 100644 --- a/common/src/net/post.rs +++ b/common/src/net/post.rs @@ -253,7 +253,7 @@ impl PostBox { let _ = self.send_tx.send(data); } - // TODO: This method is super messy + // TODO: This method is super messy. pub fn next_message(&mut self) -> Option { if self.err.is_some() { return None; @@ -528,14 +528,14 @@ fn connect() { let mut postoffice = PostOffice::, TestMsg>::bind(srv_addr).unwrap(); - // We should start off with 0 incoming connections + // We should start off with 0 incoming connections. thread::sleep(Duration::from_millis(250)); assert_eq!(postoffice.new_connections().len(), 0); assert_eq!(postoffice.error(), None); let postbox = PostBox::, TestMsg>::to_server(srv_addr).unwrap(); - // Now a postbox has been created, we should have 1 new + // Now a postbox has been created, we should have 1 new. thread::sleep(Duration::from_millis(250)); let incoming = postoffice.new_connections(); assert_eq!(incoming.len(), 1); @@ -549,7 +549,7 @@ fn connect_fail() { let mut postoffice = PostOffice::, TestMsg>::bind(listen_addr).unwrap(); - // We should start off with 0 incoming connections + // We should start off with 0 incoming connections. thread::sleep(Duration::from_millis(250)); assert_eq!(postoffice.new_connections().len(), 0); assert_eq!(postoffice.error(), None); @@ -564,7 +564,7 @@ fn connection_count() { let mut postoffice = PostOffice::, TestMsg>::bind(srv_addr).unwrap(); let mut postboxes = Vec::new(); - // We should start off with 0 incoming connections + // We should start off with 0 incoming connections. thread::sleep(Duration::from_millis(250)); assert_eq!(postoffice.new_connections().len(), 0); assert_eq!(postoffice.error(), None); @@ -573,7 +573,7 @@ fn connection_count() { postboxes.push(PostBox::, TestMsg>::to_server(srv_addr).unwrap()); } - // 5 postboxes created, we should have 5 + // 5 postboxes created, we should have 5. thread::sleep(Duration::from_millis(3500)); let incoming = postoffice.new_connections(); assert_eq!(incoming.len(), 5); @@ -597,7 +597,7 @@ fn disconnect() { incoming.next().unwrap() }; - // The client postbox has since been disconnected + // The client postbox has since been disconnected. thread::sleep(Duration::from_millis(2050)); let incoming_msgs = server_postbox.new_messages(); assert_eq!(incoming_msgs.len(), 0); diff --git a/common/src/net/post2.rs b/common/src/net/post2.rs index 3c720f67d9..ac6b94f622 100644 --- a/common/src/net/post2.rs +++ b/common/src/net/post2.rs @@ -188,7 +188,7 @@ impl PostBox { Ok(None) => {} } - // Try getting messages from the send channel + // Try getting messages from the send channel. for _ in 0..100 { match send_rx.try_recv() { Ok(send_msg) => { @@ -202,12 +202,12 @@ impl PostBox { } */ - // Assemble into packet + // Assemble into packet. let mut packet_bytes = msg_bytes.len().to_le_bytes().as_ref().to_vec(); packet_bytes.push(msg_bytes.iter().fold(0, |a, x| a ^ *x)); packet_bytes.append(&mut msg_bytes); - // Split packet into chunks + // Split packet into chunks. packet_bytes .chunks(4096) .map(|chunk| chunk.to_vec()) @@ -222,7 +222,7 @@ impl PostBox { } } - // Try sending bytes through the TCP stream + // Try sending bytes through the TCP stream. for _ in 0..100 { match outgoing_chunks.pop_front() { Some(mut chunk) => match stream.write(&chunk) { @@ -232,7 +232,7 @@ impl PostBox { break; } Err(e) if e.kind() == io::ErrorKind::WouldBlock => { - // Return chunk to the queue to try again later + // Return chunk to the queue to try again later. outgoing_chunks.push_front(chunk); break; } @@ -246,7 +246,7 @@ impl PostBox { } } - // Try receiving bytes from the TCP stream + // Try receiving bytes from the TCP stream. for _ in 0..100 { let mut buf = [0; 4096]; @@ -262,7 +262,7 @@ impl PostBox { } } - // Try turning bytes into messages + // Try turning bytes into messages. for _ in 0..100 { match incoming_buf.get(0..9) { Some(len_bytes) => { diff --git a/common/src/ray.rs b/common/src/ray.rs index 568dedc4c4..9f7900b3e7 100644 --- a/common/src/ray.rs +++ b/common/src/ray.rs @@ -54,7 +54,7 @@ impl<'a, V: ReadVol, F: RayUntil> Ray<'a, V, F> { pos = self.from + dir * dist; ipos = pos.map(|e| e.floor() as i32); - // Allow one iteration above max + // Allow one iteration above max. if dist > max { break; } diff --git a/common/src/state.rs b/common/src/state.rs index 07f9676f88..150bd8462d 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -20,25 +20,25 @@ use std::{collections::HashSet, sync::Arc, time::Duration}; use vek::*; /// How much faster should an in-game day be compared to a real day? -// TODO: Don't hard-code this +// TODO: Don't hard-code this. const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0; -/// A resource to store the time of day +/// A resource that stores the time of day. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TimeOfDay(f64); -/// A resource to store the tick (i.e: physics) time +/// A resource that stores the tick (i.e: physics) time. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Time(f64); -/// A resource used to store the time since the last tick +/// A resource that stores the time since the previous tick. #[derive(Default)] pub struct DeltaTime(pub f32); /// At what point should we stop speeding up physics to compensate for lag? If we speed physics up -/// too fast, we'd skip important physics events like collisions. This constant determines what -/// the upper limit is. If delta time exceeds this value, the game's physics will begin to produce -/// time lag. Ideally, we'd avoid such a situation. +/// too fast, we'd skip important physics events like collisions. This constant determines the +/// upper limit. If delta time exceeds this value, the game's physics will begin to produce time +/// lag. Ideally, we'd avoid such a situation. const MAX_DELTA_TIME: f32 = 0.15; pub struct Changes { @@ -64,7 +64,7 @@ impl Changes { } /// A type used to represent game state stored on both the client and the server. This includes -/// things like entity components, terrain data, and global state like weather, time of day, etc. +/// things like entity components, terrain data, and global states like weather, time of day, etc. pub struct State { ecs: sphynx::World, // Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher @@ -82,7 +82,7 @@ impl State { } } - /// Create a new `State` from an ECS state package + /// Create a new `State` from an ECS state package. pub fn from_state_package( state_package: sphynx::StatePackage, ) -> Self { @@ -97,14 +97,14 @@ impl State { } } - // Create a new Sphynx ECS world + // Create a new Sphynx ECS world. fn setup_sphynx_world(ecs: &mut sphynx::World) { - // Register synced components + // Register synced components. ecs.register_synced::(); ecs.register_synced::(); ecs.register_synced::(); - // Register unsynched (or synced by other means) components + // Register unsynced (or synced by other means) components. ecs.register::(); ecs.register::(); ecs.register::(); @@ -112,16 +112,16 @@ impl State { ecs.register::(); ecs.register::(); - // Register synced resources used by the ECS + // Register synced resources used by the ECS. ecs.add_resource_synced(TimeOfDay(0.0)); - // Register unsynced resources used by the ECS + // Register unsynced resources used by the ECS. ecs.add_resource(Time(0.0)); ecs.add_resource(DeltaTime(0.0)); ecs.add_resource(TerrainMap::new().unwrap()); } - /// Register a component with the state's ECS + /// Register a component with the state's ECS. pub fn with_component(mut self) -> Self where ::Storage: Default, @@ -130,27 +130,27 @@ impl State { self } - /// Write a component attributed to a particular entity + /// Write a component attributed to a particular entity. pub fn write_component(&mut self, entity: EcsEntity, comp: C) { let _ = self.ecs.write_storage().insert(entity, comp); } - /// Read a component attributed to a particular entity + /// Read a component attributed to a particular entity. pub fn read_component_cloned(&self, entity: EcsEntity) -> Option { self.ecs.read_storage().get(entity).cloned() } - /// Get a read-only reference to the storage of a particular component type + /// Get a read-only reference to the storage of a particular component type. pub fn read_storage(&self) -> EcsStorage>> { self.ecs.read_storage::() } - /// Get a reference to the internal ECS world + /// Get a reference to the internal ECS world. pub fn ecs(&self) -> &sphynx::World { &self.ecs } - /// Get a mutable reference to the internal ECS world + /// Get a mutable reference to the internal ECS world. pub fn ecs_mut(&mut self) -> &mut sphynx::World { &mut self.ecs } @@ -194,7 +194,7 @@ impl State { } } - /// Remove the chunk with the given key from this state's terrain, if it exists + /// Remove the chunk with the given key from this state's terrain, if it exists. pub fn remove_chunk(&mut self, key: Vec2) { if self .ecs @@ -208,27 +208,27 @@ impl State { /// Execute a single tick, simulating the game state by the given duration. pub fn tick(&mut self, dt: Duration) { - // Change the time accordingly + // Change the time accordingly. self.ecs.write_resource::().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR; self.ecs.write_resource::