From 80e95e2e6c3ee801895b030b86fbe1ceee35a0c6 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Fri, 14 Jun 2019 17:27:05 +0200 Subject: [PATCH] Add `pub use phys::` and remove most `pub mod`s --- client/src/lib.rs | 4 +-- common/src/comp/mod.rs | 36 ++++++++-------------- common/src/comp/phys.rs | 4 --- common/src/msg/client.rs | 6 ++-- common/src/msg/ecs_packet.rs | 12 ++++---- common/src/msg/server.rs | 6 ++-- common/src/state.rs | 8 ++--- common/src/sys/agent.rs | 2 +- common/src/sys/animation.rs | 7 +++-- common/src/sys/combat.rs | 3 +- common/src/sys/controller.rs | 3 +- common/src/sys/phys.rs | 5 +--- server/src/cmd.rs | 34 ++++++--------------- server/src/lib.rs | 58 ++++++++++++++++-------------------- voxygen/src/hud/mod.rs | 6 ++-- voxygen/src/scene/figure.rs | 16 +++++----- voxygen/src/scene/mod.rs | 2 +- voxygen/src/session.rs | 2 +- 18 files changed, 86 insertions(+), 128 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 01e0abe3d3..655e7179be 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -153,7 +153,7 @@ impl Client { pub fn current_chunk(&self) -> Option> { let chunk_pos = Vec2::from( self.state - .read_storage::() + .read_storage::() .get(self.entity) .cloned()? .0, @@ -218,7 +218,7 @@ impl Client { // 5) Terrain let pos = self .state - .read_storage::() + .read_storage::() .get(self.entity) .cloned(); if let (Some(pos), Some(view_distance)) = (pos, self.view_distance) { diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index c876143a22..9f1c20f910 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -1,30 +1,18 @@ pub mod actor; -pub mod agent; -pub mod animation; -pub mod controller; -pub mod inputs; -pub mod phys; -pub mod player; -pub mod stats; +mod agent; +mod animation; +mod controller; +mod inputs; +mod phys; +mod player; +mod stats; // Reexports -pub use actor::Actor; -pub use actor::Body; -pub use actor::HumanoidBody; -pub use actor::QuadrupedBody; -pub use actor::QuadrupedMediumBody; +pub use actor::{Actor, Body, HumanoidBody, QuadrupedBody, QuadrupedMediumBody}; pub use agent::Agent; -pub use animation::Animation; -pub use animation::AnimationInfo; +pub use animation::{Animation, AnimationInfo}; pub use controller::Controller; -pub use inputs::Attacking; -pub use inputs::Gliding; -pub use inputs::Jumping; -pub use inputs::MoveDir; -pub use inputs::OnGround; -pub use inputs::Respawning; -pub use inputs::Rolling; +pub use inputs::{Attacking, Gliding, Jumping, MoveDir, OnGround, Respawning, Rolling}; +pub use phys::{ForceUpdate, Ori, Pos, Vel}; pub use player::Player; -pub use stats::Dying; -pub use stats::HealthSource; -pub use stats::Stats; +pub use stats::{Dying, HealthSource, Stats}; diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index adfc64ffe0..6fe1e603bb 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -2,7 +2,6 @@ use specs::{Component, NullStorage, VecStorage}; use vek::*; // Position - #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Pos(pub Vec3); @@ -11,7 +10,6 @@ impl Component for Pos { } // Velocity - #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Vel(pub Vec3); @@ -20,7 +18,6 @@ impl Component for Vel { } // Orientation - #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct Ori(pub Vec3); @@ -29,7 +26,6 @@ impl Component for Ori { } // ForceUpdate - #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub struct ForceUpdate; diff --git a/common/src/msg/client.rs b/common/src/msg/client.rs index 1187831d2a..47ec6fae5b 100644 --- a/common/src/msg/client.rs +++ b/common/src/msg/client.rs @@ -19,9 +19,9 @@ pub enum ClientMsg { Chat(String), PlayerAnimation(comp::AnimationInfo), PlayerPhysics { - pos: comp::phys::Pos, - vel: comp::phys::Vel, - ori: comp::phys::Ori, + pos: comp::Pos, + vel: comp::Vel, + ori: comp::Ori, }, TerrainChunkRequest { key: Vec2, diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 2e723fbabe..899579b8c3 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -17,9 +17,9 @@ impl sphynx::ResPacket for EcsResPacket {} sphynx::sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPacket { - Pos(comp::phys::Pos), - Vel(comp::phys::Vel), - Ori(comp::phys::Ori), + Pos(comp::Pos), + Vel(comp::Vel), + Ori(comp::Ori), Actor(comp::Actor), Player(comp::Player), Stats(comp::Stats), @@ -33,9 +33,9 @@ sphynx::sum_type! { sphynx::sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPhantom { - Pos(PhantomData), - Vel(PhantomData), - Ori(PhantomData), + Pos(PhantomData), + Vel(PhantomData), + Ori(PhantomData), Actor(PhantomData), Player(PhantomData), Stats(PhantomData), diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index c82f94b2a1..f3604fb839 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -32,9 +32,9 @@ pub enum ServerMsg { EcsSync(sphynx::SyncPackage), EntityPhysics { entity: u64, - pos: comp::phys::Pos, - vel: comp::phys::Vel, - ori: comp::phys::Ori, + pos: comp::Pos, + vel: comp::Vel, + ori: comp::Ori, }, EntityAnimation { entity: u64, diff --git a/common/src/state.rs b/common/src/state.rs index 4dec08d899..6e1f2dde1e 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -104,12 +104,12 @@ impl State { ecs.register_synced::(); ecs.register_synced::(); // TODO: Don't send this to the client? ecs.register_synced::(); // TODO: Don't send this to the client? - ecs.register::(); + ecs.register::(); // Register components synced by other means - ecs.register::(); - ecs.register::(); - ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); ecs.register::(); ecs.register::(); ecs.register::(); diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 0bd445ab1e..3ff07be4ab 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -1,4 +1,4 @@ -use crate::comp::{phys::Pos, Agent, Attacking, Controller, Jumping}; +use crate::comp::{Agent, Attacking, Controller, Jumping, Pos}; use log::warn; use rand::{seq::SliceRandom, thread_rng}; use specs::{Entities, Join, ReadStorage, System, WriteStorage}; diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index 6571547f34..2ccc5cff18 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -1,5 +1,8 @@ use crate::{ - comp::{phys, Animation, AnimationInfo, Attacking, Gliding, Jumping, OnGround, Rolling}, + comp::{ + Animation, AnimationInfo, Attacking, ForceUpdate, Gliding, Jumping, OnGround, Ori, Pos, + Rolling, Vel, + }, state::DeltaTime, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; @@ -10,7 +13,7 @@ impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, Read<'a, DeltaTime>, - ReadStorage<'a, phys::Vel>, + ReadStorage<'a, Vel>, ReadStorage<'a, OnGround>, ReadStorage<'a, Jumping>, ReadStorage<'a, Gliding>, diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index be94838023..a3106bfcda 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -1,7 +1,6 @@ use crate::{ comp::{ - phys::{ForceUpdate, Ori, Pos, Vel}, - Attacking, HealthSource, Stats, + Attacking, HealthSource, Stats, {ForceUpdate, Ori, Pos, Vel}, }, state::{DeltaTime, Uid}, }; diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index 69404fc576..aa3b68c81e 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -1,8 +1,7 @@ use crate::{ comp::{ - phys::{ForceUpdate, Ori, Pos, Vel}, Animation, AnimationInfo, Attacking, Controller, Gliding, HealthSource, Jumping, MoveDir, - OnGround, Respawning, Rolling, Stats, + OnGround, Respawning, Rolling, Stats, {ForceUpdate, Ori, Pos, Vel}, }, state::DeltaTime, }; diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index e98303c035..d756b66ca1 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -1,8 +1,5 @@ use crate::{ - comp::{ - phys::{Ori, Pos, Vel}, - Gliding, Jumping, MoveDir, OnGround, Rolling, Stats, - }, + comp::{Gliding, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Stats, Vel}, state::DeltaTime, terrain::TerrainMap, vol::{ReadVol, Vox}, diff --git a/server/src/cmd.rs b/server/src/cmd.rs index ba8480420d..510a171ff9 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -100,18 +100,12 @@ fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &Ch let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32); match (opt_x, opt_y, opt_z) { (Some(x), Some(y), Some(z)) => { - match server - .state - .read_component_cloned::(entity) - { + match server.state.read_component_cloned::(entity) { Some(current_pos) => { - server.state.write_component( - entity, - comp::phys::Pos(current_pos.0 + Vec3::new(x, y, z)), - ); server .state - .write_component(entity, comp::phys::ForceUpdate); + .write_component(entity, comp::Pos(current_pos.0 + Vec3::new(x, y, z))); + server.state.write_component(entity, comp::ForceUpdate); } None => server.clients.notify( entity, @@ -131,10 +125,8 @@ fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &Ch (Some(x), Some(y), Some(z)) => { server .state - .write_component(entity, comp::phys::Pos(Vec3::new(x, y, z))); - server - .state - .write_component(entity, comp::phys::ForceUpdate); + .write_component(entity, comp::Pos(Vec3::new(x, y, z))); + server.state.write_component(entity, comp::ForceUpdate); } _ => server .clients @@ -173,20 +165,15 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat match opt_alias { Some(alias) => { let ecs = server.state.ecs(); - let opt_player = (&ecs.entities(), &ecs.read_storage::()) + let opt_player = (&ecs.entities(), &ecs.read_storage::()) .join() .find(|(_, player)| player.alias == alias) .map(|(entity, _)| entity); match opt_player { - Some(player) => match server - .state - .read_component_cloned::(player) - { + Some(player) => match server.state.read_component_cloned::(player) { Some(pos) => { server.state.write_component(entity, pos); - server - .state - .write_component(entity, comp::phys::ForceUpdate); + server.state.write_component(entity, comp::ForceUpdate); } None => server.clients.notify( entity, @@ -222,10 +209,7 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C match (opt_agent, opt_id, opt_amount) { (Some(agent), Some(id), Some(amount)) => { - match server - .state - .read_component_cloned::(entity) - { + match server.state.read_component_cloned::(entity) { Some(mut pos) => { pos.0.x += 1.0; // Temp fix TODO: Solve NaN issue with positions of pets let body = kind_to_body(id); diff --git a/server/src/lib.rs b/server/src/lib.rs index 5d5fa38ae6..194fa2b908 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -135,7 +135,7 @@ impl Server { #[allow(dead_code)] pub fn create_npc( &mut self, - pos: comp::phys::Pos, + pos: comp::Pos, name: String, body: comp::Body, ) -> EcsEntityBuilder { @@ -143,13 +143,13 @@ impl Server { .ecs_mut() .create_entity_synced() .with(pos) - .with(comp::phys::Vel(Vec3::zero())) - .with(comp::phys::Ori(Vec3::unit_y())) + .with(comp::Vel(Vec3::zero())) + .with(comp::Ori(Vec3::unit_y())) .with(comp::Controller::default()) .with(comp::AnimationInfo::default()) .with(comp::Actor::Character { name, body }) .with(comp::Stats::default()) - .with(comp::phys::ForceUpdate) + .with(comp::ForceUpdate) } pub fn create_player_character( @@ -165,11 +165,11 @@ impl Server { state.write_component(entity, comp::Stats::default()); state.write_component(entity, comp::AnimationInfo::default()); state.write_component(entity, comp::Controller::default()); - state.write_component(entity, comp::phys::Pos(spawn_point)); - state.write_component(entity, comp::phys::Vel(Vec3::zero())); - state.write_component(entity, comp::phys::Ori(Vec3::unit_y())); + state.write_component(entity, comp::Pos(spawn_point)); + state.write_component(entity, comp::Vel(Vec3::zero())); + state.write_component(entity, comp::Ori(Vec3::unit_y())); // Make sure physics are accepted. - state.write_component(entity, comp::phys::ForceUpdate); + state.write_component(entity, comp::ForceUpdate); // Tell the client its request was successful. client.allow_state(ClientState::Character); @@ -246,9 +246,8 @@ impl Server { // Actually kill them for entity in todo_kill { if let Some(client) = self.clients.get_mut(&entity) { - self.state - .write_component(entity, comp::phys::Vel(Vec3::zero())); - self.state.write_component(entity, comp::phys::ForceUpdate); + self.state.write_component(entity, comp::Vel(Vec3::zero())); + self.state.write_component(entity, comp::ForceUpdate); client.force_state(ClientState::Dead); } else { if let Err(err) = self.state.ecs_mut().delete_entity_synced(entity) { @@ -273,12 +272,11 @@ impl Server { self.state.write_component(entity, comp::Stats::default()); self.state .ecs_mut() - .write_storage::() + .write_storage::() .get_mut(entity) .map(|pos| pos.0.z += 100.0); - self.state - .write_component(entity, comp::phys::Vel(Vec3::zero())); - self.state.write_component(entity, comp::phys::ForceUpdate); + self.state.write_component(entity, comp::Vel(Vec3::zero())); + self.state.write_component(entity, comp::ForceUpdate); } } @@ -289,7 +287,7 @@ impl Server { for (entity, view_distance, pos) in ( &self.state.ecs().entities(), &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), + &self.state.ecs().read_storage::(), ) .join() .filter_map(|(entity, player, pos)| { @@ -324,7 +322,7 @@ impl Server { // For each player with a position, calculate the distance. for (player, pos) in ( &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), + &self.state.ecs().read_storage::(), ) .join() { @@ -632,9 +630,9 @@ impl Server { // Sync physics for (&uid, &pos, &vel, &ori) in ( &state.ecs().read_storage::(), - &state.ecs().read_storage::(), - &state.ecs().read_storage::(), - &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + &state.ecs().read_storage::(), + &state.ecs().read_storage::(), ) .join() { @@ -673,13 +671,10 @@ impl Server { for (entity, &uid, &pos, &vel, &ori, force_update) in ( &self.state.ecs().entities(), &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), - &self.state.ecs().read_storage::(), - self.state - .ecs() - .read_storage::() - .maybe(), + &self.state.ecs().read_storage::(), + &self.state.ecs().read_storage::(), + &self.state.ecs().read_storage::(), + self.state.ecs().read_storage::().maybe(), ) .join() { @@ -695,7 +690,7 @@ impl Server { let in_vd = |entity| { // Get client position. - let client_pos = match state.ecs().read_storage::().get(entity) { + let client_pos = match state.ecs().read_storage::().get(entity) { Some(pos) => pos.0, None => return false, }; @@ -726,10 +721,7 @@ impl Server { &self.state.ecs().entities(), &self.state.ecs().read_storage::(), &self.state.ecs().read_storage::(), - self.state - .ecs() - .read_storage::() - .maybe(), + self.state.ecs().read_storage::().maybe(), ) .join() { @@ -748,7 +740,7 @@ impl Server { // Remove all force flags. self.state .ecs_mut() - .write_storage::() + .write_storage::() .clear(); } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index ccafa92385..34ecf90771 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -103,7 +103,7 @@ font_ids! { pub struct DebugInfo { pub tps: f64, pub ping_ms: f64, - pub coordinates: Option, + pub coordinates: Option, } pub enum Event { @@ -312,7 +312,7 @@ impl Hud { if self.show.ingame { let ecs = client.state().ecs(); let actor = ecs.read_storage::(); - let pos = ecs.read_storage::(); + let pos = ecs.read_storage::(); let stats = ecs.read_storage::(); let player = ecs.read_storage::(); let entities = ecs.entities(); @@ -322,7 +322,7 @@ impl Hud { let player_pos = client .state() .ecs() - .read_storage::() + .read_storage::() .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); let mut name_id_walker = self.ids.name_tags.walk(); diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index a92a16e9d7..547be1e146 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -477,15 +477,15 @@ impl FigureMgr { let player_pos = client .state() .ecs() - .read_storage::() + .read_storage::() .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); for (entity, pos, vel, ori, actor, animation_info, stats) in ( &ecs.entities(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), &ecs.read_storage::(), ecs.read_storage::().maybe(), @@ -676,15 +676,15 @@ impl FigureMgr { let player_pos = client .state() .ecs() - .read_storage::() + .read_storage::() .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); for (entity, _, _, _, actor, _, _) in ( &ecs.entities(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), &ecs.read_storage::(), ecs.read_storage::().maybe(), diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 9d7c09f608..55fe9c7498 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -110,7 +110,7 @@ impl Scene { let player_pos = client .state() .ecs() - .read_storage::() + .read_storage::() .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 11ce68a2d1..3bf9504d51 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -8,7 +8,7 @@ use crate::{ Direction, Error, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{clock::Clock, comp, comp::phys::Pos, msg::ClientState}; +use common::{clock::Clock, comp, comp::Pos, msg::ClientState}; use log::{error, warn}; use std::{cell::RefCell, rc::Rc, time::Duration}; use vek::*;