From 75ca605f5d1e607a149ee50075d936d8735375ec Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 31 May 2019 14:45:16 -0400 Subject: [PATCH] Changes the physics misnomer Direction to Orientation and adjusts some ECS read_storage names. --- client/src/lib.rs | 8 +++--- common/src/comp/phys.rs | 6 ++--- common/src/msg/client.rs | 2 +- common/src/msg/ecs_packet.rs | 4 +-- common/src/msg/server.rs | 2 +- common/src/state.rs | 2 +- common/src/sys/actions.rs | 14 +++++------ common/src/sys/agent.rs | 8 +++--- common/src/sys/inputs.rs | 34 +++++++++++++------------- server/src/lib.rs | 20 +++++++-------- voxygen/src/anim/character/attack.rs | 2 +- voxygen/src/scene/figure.rs | 16 ++++++------ voxygen/src/scene/figure/figure.rs | 10 ++++---- voxygen/src/scene/figure/figurequad.rs | 10 ++++---- 14 files changed, 69 insertions(+), 69 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index dd43d40628..e8b4c791f0 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -271,9 +271,9 @@ impl Client { self.state.read_storage().get(self.entity).cloned(), self.state.read_storage().get(self.entity).cloned(), ) { - (Some(pos), Some(vel), Some(dir)) => { + (Some(pos), Some(vel), Some(ori)) => { self.postbox - .send_message(ClientMsg::PlayerPhysics { pos, vel, dir }); + .send_message(ClientMsg::PlayerPhysics { pos, vel, ori }); } _ => {} } @@ -341,12 +341,12 @@ impl Client { entity, pos, vel, - dir, + ori, } => match self.state.ecs().entity_from_uid(entity) { Some(entity) => { self.state.write_component(entity, pos); self.state.write_component(entity, vel); - self.state.write_component(entity, dir); + self.state.write_component(entity, ori); } None => {} }, diff --git a/common/src/comp/phys.rs b/common/src/comp/phys.rs index 8bfd9150bc..15604e636f 100644 --- a/common/src/comp/phys.rs +++ b/common/src/comp/phys.rs @@ -19,12 +19,12 @@ impl Component for Vel { type Storage = VecStorage; } -// Direction +// Orientation #[derive(Copy, Clone, Debug, Serialize, Deserialize)] -pub struct Dir(pub Vec3); +pub struct Ori(pub Vec3); -impl Component for Dir { +impl Component for Ori { type Storage = VecStorage; } diff --git a/common/src/msg/client.rs b/common/src/msg/client.rs index b340b1797b..aa765d0a52 100644 --- a/common/src/msg/client.rs +++ b/common/src/msg/client.rs @@ -22,7 +22,7 @@ pub enum ClientMsg { PlayerPhysics { pos: comp::phys::Pos, vel: comp::phys::Vel, - dir: comp::phys::Dir, + ori: comp::phys::Ori, }, TerrainChunkRequest { key: Vec2, diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index c4e3163d62..5d860ae85c 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -19,7 +19,7 @@ sphynx::sum_type! { pub enum EcsCompPacket { Pos(comp::phys::Pos), Vel(comp::phys::Vel), - Dir(comp::phys::Dir), + Ori(comp::phys::Ori), Actor(comp::Actor), Player(comp::Player), Stats(comp::Stats), @@ -33,7 +33,7 @@ sphynx::sum_type! { pub enum EcsCompPhantom { Pos(PhantomData), Vel(PhantomData), - Dir(PhantomData), + Ori(PhantomData), Actor(PhantomData), Player(PhantomData), Stats(PhantomData), diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index 379f65cddf..fc02a6d93a 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -27,7 +27,7 @@ pub enum ServerMsg { entity: u64, pos: comp::phys::Pos, vel: comp::phys::Vel, - dir: comp::phys::Dir, + ori: comp::phys::Ori, }, EntityAnimation { entity: u64, diff --git a/common/src/state.rs b/common/src/state.rs index 66984551f5..fe0f8c06ac 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -109,7 +109,7 @@ impl State { // Register components synced by other means ecs.register::(); ecs.register::(); - ecs.register::(); + ecs.register::(); ecs.register::(); // Register client-local components diff --git a/common/src/sys/actions.rs b/common/src/sys/actions.rs index cf81096320..0e006fb1a6 100644 --- a/common/src/sys/actions.rs +++ b/common/src/sys/actions.rs @@ -5,7 +5,7 @@ use vek::*; // Crate use crate::{ comp::{ - phys::{Dir, Pos, Vel}, + phys::{Ori, Pos, Vel}, Animation, AnimationInfo, Attacking, }, state::DeltaTime, @@ -23,12 +23,12 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Attacking>, ); - fn run(&mut self, (entities, dt, mut attackings): Self::SystemData) { - for (entity, attacking) in (&entities, &mut attackings).join() { - attacking.time += dt.0; + fn run(&mut self, (entities, dt, mut attacks): Self::SystemData) { + for (entity, attack) in (&entities, &mut attacks).join() { + attack.time += dt.0; } - let finished_attack = (&entities, &mut attackings) + let finished_attacks = (&entities, &mut attacks) .join() .filter(|(e, a)| { a.time > 0.25 // TODO: constant @@ -36,8 +36,8 @@ impl<'a> System<'a> for Sys { .map(|(e, a)| e) .collect::>(); - for entity in finished_attack { - attackings.remove(entity); + for entity in finished_attacks { + attacks.remove(entity); } } } diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 1b8e359d31..d7a10dc364 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -25,7 +25,7 @@ impl<'a> System<'a> for Sys { fn run( &mut self, - (time, entities, mut agents, positions, mut controls, mut jumpings, mut attackings): Self::SystemData, + (time, entities, mut agents, positions, mut controls, mut jumps, mut attacks): Self::SystemData, ) { for (entity, agent, pos, control) in (&entities, &mut agents, &positions, &mut controls).join() @@ -42,13 +42,13 @@ impl<'a> System<'a> for Sys { } } Agent::Pet { target, offset } => { - // Run towards target + // Run towards target. match positions.get(*target) { Some(tgt_pos) => { let tgt_pos = tgt_pos.0 + *offset; if tgt_pos.z > pos.0.z + 1.0 { - jumpings.insert(entity, Jumping); + jumps.insert(entity, Jumping); } // Move towards the target. @@ -79,7 +79,7 @@ impl<'a> System<'a> for Sys { control.move_dir = Vec2::zero(); if rand::random::() < 0.2 { - attackings.insert(entity, Attacking::start()); + attacks.insert(entity, Attacking::start()); } false diff --git a/common/src/sys/inputs.rs b/common/src/sys/inputs.rs index 0a32422607..861611a308 100644 --- a/common/src/sys/inputs.rs +++ b/common/src/sys/inputs.rs @@ -5,7 +5,7 @@ use vek::*; // Crate use crate::{ comp::{ - phys::{Dir, ForceUpdate, Pos, Vel}, + phys::{Ori, ForceUpdate, Pos, Vel}, Animation, AnimationInfo, Attacking, Control, Gliding, HealthSource, Jumping, Respawning, Stats, }, @@ -26,7 +26,7 @@ impl<'a> System<'a> for Sys { ReadExpect<'a, TerrainMap>, ReadStorage<'a, Pos>, WriteStorage<'a, Vel>, - WriteStorage<'a, Dir>, + WriteStorage<'a, Ori>, WriteStorage<'a, AnimationInfo>, WriteStorage<'a, Stats>, ReadStorage<'a, Control>, @@ -47,23 +47,23 @@ impl<'a> System<'a> for Sys { terrain, positions, mut velocities, - mut directions, + mut orientations, mut animation_infos, mut stats, mut controls, - mut jumpings, - mut respawnings, - mut glidings, - mut attackings, + mut jumps, + mut respawns, + mut glides, + mut attacks, mut force_updates, ): Self::SystemData, ) { - for (entity, pos, control, stats, mut dir, mut vel) in ( + for (entity, pos, control, stats, mut ori, mut vel) in ( &entities, &positions, &controls, &stats, - &mut directions, + &mut orientations, &mut velocities, ) .join() @@ -85,7 +85,7 @@ impl<'a> System<'a> for Sys { // Apply physics to the player: acceleration and non-linear deceleration. vel.0 += Vec2::broadcast(dt.0) * control.move_dir * 200.0; - if jumpings.get(entity).is_some() { + if jumps.get(entity).is_some() { vel.0.z += 16.0; } @@ -95,7 +95,7 @@ impl<'a> System<'a> for Sys { // Apply physics to the player: acceleration and non-linear deceleration. vel.0 += Vec2::broadcast(dt.0) * control.move_dir * 10.0; - if glidings.get(entity).is_some() && vel.0.z < 0.0 { + if glides.get(entity).is_some() && vel.0.z < 0.0 { // TODO: Don't hard-code this. let anti_grav = 9.81 * 3.95 + vel.0.z.powf(2.0) * 0.2; vel.0.z += @@ -118,18 +118,18 @@ impl<'a> System<'a> for Sys { * Vec3::new(1.0, 1.0, 0.0); if vel.0.magnitude_squared() != 0.0 { - dir.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0); + ori.0 = vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0); } let animation = if on_ground { if control.move_dir.magnitude() > 0.01 { Animation::Run - } else if attackings.get(entity).is_some() { + } else if attacks.get(entity).is_some() { Animation::Attack } else { Animation::Idle } - } else if glidings.get(entity).is_some() { + } else if glides.get(entity).is_some() { Animation::Gliding } else { Animation::Jump @@ -151,8 +151,8 @@ impl<'a> System<'a> for Sys { ); } - for (entity, &uid, pos, dir, attacking) in - (&entities, &uids, &positions, &directions, &mut attackings).join() + for (entity, &uid, pos, ori, attacking) in + (&entities, &uids, &positions, &orientations, &mut attacks).join() { if !attacking.applied { for (b, pos_b, mut stat_b, mut vel_b) in @@ -162,7 +162,7 @@ impl<'a> System<'a> for Sys { if entity != b && !stat_b.is_dead && pos.0.distance_squared(pos_b.0) < 50.0 - && dir.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0 + && ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 70.0 { // Deal damage stat_b.hp.change_by(-10, HealthSource::Attack { by: uid }); // TODO: variable damage and weapon diff --git a/server/src/lib.rs b/server/src/lib.rs index c6f8d96d88..e24146be71 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -145,7 +145,7 @@ impl Server { .create_entity_synced() .with(pos) .with(comp::phys::Vel(Vec3::zero())) - .with(comp::phys::Dir(Vec3::unit_y())) + .with(comp::phys::Ori(Vec3::unit_y())) .with(comp::Control::default()) .with(comp::AnimationInfo::default()) .with(comp::Actor::Character { name, body }) @@ -167,7 +167,7 @@ impl Server { state.write_component(entity, comp::AnimationInfo::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::Dir(Vec3::unit_y())); + state.write_component(entity, comp::phys::Ori(Vec3::unit_y())); // Make sure physics are accepted. state.write_component(entity, comp::phys::ForceUpdate); @@ -524,11 +524,11 @@ impl Server { _ => client.error_state(RequestStateError::Impossible), } } - ClientMsg::PlayerPhysics { pos, vel, dir } => match client.client_state { + ClientMsg::PlayerPhysics { pos, vel, ori } => match client.client_state { ClientState::Character => { state.write_component(entity, pos); state.write_component(entity, vel); - state.write_component(entity, dir); + state.write_component(entity, ori); } // Only characters can send positions. _ => client.error_state(RequestStateError::Impossible), @@ -629,12 +629,12 @@ impl Server { state.write_component(entity, player); // Sync physics - for (entity, &uid, &pos, &vel, &dir) in ( + for (entity, &uid, &pos, &vel, &ori) in ( &state.ecs().entities(), &state.ecs().read_storage::(), &state.ecs().read_storage::(), &state.ecs().read_storage::(), - &state.ecs().read_storage::(), + &state.ecs().read_storage::(), ) .join() { @@ -642,7 +642,7 @@ impl Server { entity: uid.into(), pos, vel, - dir, + ori, }); } @@ -671,12 +671,12 @@ impl Server { .notify_registered(ServerMsg::EcsSync(self.state.ecs_mut().next_sync_package())); // Sync physics - for (entity, &uid, &pos, &vel, &dir, force_update) in ( + 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::(), self.state .ecs() .read_storage::() @@ -688,7 +688,7 @@ impl Server { entity: uid.into(), pos, vel, - dir, + ori, }; let state = &self.state; diff --git a/voxygen/src/anim/character/attack.rs b/voxygen/src/anim/character/attack.rs index 9c9e8039bc..a39f6ae531 100644 --- a/voxygen/src/anim/character/attack.rs +++ b/voxygen/src/anim/character/attack.rs @@ -36,7 +36,7 @@ impl Animation for AttackAnimation { let wave_stop = (anim_time as f32 * 6.0).min(PI / 2.0).sin(); let wave_stop_alt = (anim_time as f32 * 28.0).min(PI / 2.0).sin(); let wave_stop_quick = (anim_time as f32 * 16.0).min(PI / 2.0).sin(); - let peakwave = 1.0 - (anim_time as f32 * 1.0).cos(); + let peak_wave = 1.0 - (anim_time as f32 * 1.0).cos(); let head_look = Vec2::new( ((global_time + anim_time) as f32 / 8.0) diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 8d9c2893c7..0c17815f6b 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -483,11 +483,11 @@ impl FigureMgr { .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); - for (entity, pos, vel, dir, actor, animation_info, stats) in ( + 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::().maybe(), @@ -568,7 +568,7 @@ impl FigureMgr { }; state.skeleton.interpolate(&target_skeleton); - state.update(renderer, pos.0, dir.0, col); + state.update(renderer, pos.0, ori.0, col); } Body::Quadruped(body) => { let state = self.quadruped_states.entry(entity).or_insert_with(|| { @@ -597,7 +597,7 @@ impl FigureMgr { }; state.skeleton.interpolate(&target_skeleton); - state.update(renderer, pos.0, dir.0, col); + state.update(renderer, pos.0, ori.0, col); } Body::QuadrupedMedium(body) => { let state = @@ -633,7 +633,7 @@ impl FigureMgr { }; state.skeleton.interpolate(&target_skeleton); - state.update(renderer, pos.0, dir.0, col); + state.update(renderer, pos.0, ori.0, col); } }, // TODO: Non-character actors @@ -671,7 +671,7 @@ impl FigureMgr { &ecs.entities(), &ecs.read_storage::(), &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), &ecs.read_storage::(), ecs.read_storage::().maybe(), @@ -737,12 +737,12 @@ impl FigureState { &mut self, renderer: &mut Renderer, pos: Vec3, - dir: Vec3, + ori: Vec3, col: Rgba, ) { let mat = Mat4::::identity() * Mat4::translation_3d(pos) - * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0); + * Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0); let locals = FigureLocals::new(mat, col); renderer.update_consts(&mut self.locals, &[locals]).unwrap(); diff --git a/voxygen/src/scene/figure/figure.rs b/voxygen/src/scene/figure/figure.rs index c045510664..95b2cb1bb8 100644 --- a/voxygen/src/scene/figure/figure.rs +++ b/voxygen/src/scene/figure/figure.rs @@ -238,11 +238,11 @@ impl FigureMgr { pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client) { let time = client.state().get_time(); let ecs = client.state().ecs(); - for (entity, pos, vel, dir, actor, animation_history) in ( + for (entity, pos, vel, ori, actor, animation_history) in ( &ecs.entities(), &ecs.read_storage::(), &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), &ecs.read_storage::(), ) @@ -275,7 +275,7 @@ impl FigureMgr { state.skeleton.interpolate(&target_skeleton); - state.update(renderer, pos.0, dir.0); + state.update(renderer, pos.0, ori.0); } // TODO: Non-humanoid bodies. }, // TODO: Non-character actors. @@ -333,10 +333,10 @@ impl FigureState { } } - pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3, dir: Vec3) { + pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3, ori: Vec3) { let mat = Mat4::::identity() * Mat4::translation_3d(pos) - * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0); + * Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0); let locals = FigureLocals::new(mat); renderer.update_consts(&mut self.locals, &[locals]).unwrap(); diff --git a/voxygen/src/scene/figure/figurequad.rs b/voxygen/src/scene/figure/figurequad.rs index d53056823f..ead4ce1ade 100644 --- a/voxygen/src/scene/figure/figurequad.rs +++ b/voxygen/src/scene/figure/figurequad.rs @@ -180,11 +180,11 @@ impl FigureMgr { pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client) { let time = client.state().get_time(); let ecs = client.state().ecs(); - for (entity, pos, vel, dir, actor, animation_history) in ( + for (entity, pos, vel, ori, actor, animation_history) in ( &ecs.entities(), &ecs.read_storage::(), &ecs.read_storage::(), - &ecs.read_storage::(), + &ecs.read_storage::(), &ecs.read_storage::(), &ecs.read_storage::(), ) @@ -205,7 +205,7 @@ impl FigureMgr { state.skeleton.interpolate(&target_skeleton); - state.update(renderer, pos.0, dir.0); + state.update(renderer, pos.0, ori.0); } // TODO: Non-humanoid bodies }, // TODO: Non-character actors @@ -263,10 +263,10 @@ impl FigureState { } } - pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3, dir: Vec3) { + pub fn update(&mut self, renderer: &mut Renderer, pos: Vec3, ori: Vec3) { let mat = Mat4::::identity() * Mat4::translation_3d(pos) - * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0); + * Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0); let locals = FigureLocals::new(mat); renderer.update_consts(&mut self.locals, &[locals]).unwrap();