From 976eface66a67b254ceb284cabd78bb524b691c1 Mon Sep 17 00:00:00 2001 From: AdamWhitehurst Date: Fri, 17 Jan 2020 08:39:21 -0800 Subject: [PATCH] Update from MR comments --- common/src/comp/character_state.rs | 20 +--------------- common/src/comp/mod.rs | 2 +- common/src/event.rs | 1 - common/src/msg/ecs_packet.rs | 21 ----------------- common/src/state.rs | 3 --- common/src/states/mod.rs | 23 ++++--------------- common/src/sys/agent.rs | 4 +--- common/src/sys/character_state.rs | 23 ++++--------------- .../src/audio/sfx/event_mapper/movement.rs | 8 ++----- 9 files changed, 15 insertions(+), 90 deletions(-) diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 2eef455fd4..5fd75a0924 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -9,7 +9,7 @@ use crate::{ use serde::Deserialize; use serde::Serialize; use specs::LazyUpdate; -use specs::{Component, Entity, FlaggedStorage, HashMapStorage, NullStorage}; +use specs::{Component, Entity, FlaggedStorage, HashMapStorage}; use std::time::Duration; pub struct EcsStateData<'a> { @@ -159,21 +159,3 @@ impl Default for CharacterState { impl Component for CharacterState { type Storage = FlaggedStorage>; } - -#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct OverrideState; -impl Component for OverrideState { - type Storage = FlaggedStorage>; -} - -#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct OverrideAction; -impl Component for OverrideAction { - type Storage = FlaggedStorage>; -} - -#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct OverrideMove; -impl Component for OverrideMove { - type Storage = FlaggedStorage>; -} diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index 4dcc7d7172..6457cdee37 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -25,7 +25,7 @@ pub use body::{ }; pub use character_state::{ ActionState, AttackKind, BlockKind, CharacterState, DodgeKind, EcsStateData, MoveState, - OverrideAction, OverrideMove, OverrideState, StateUpdate, + StateUpdate, }; pub use controller::{ ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState, diff --git a/common/src/event.rs b/common/src/event.rs index 803fe06362..04f393d38c 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -1,5 +1,4 @@ use crate::{comp, sync::Uid}; -use comp::item::ToolKind; use parking_lot::Mutex; use serde::Deserialize; use specs::Entity as EcsEntity; diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 9809115c45..f918cbb344 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -21,9 +21,6 @@ sum_type! { Mass(comp::Mass), Gravity(comp::Gravity), Sticky(comp::Sticky), - OverrideAction(comp::OverrideAction), - OverrideMove(comp::OverrideMove), - OverrideState(comp::OverrideState), AbilityAction(comp::AbilityAction), AbilityPool(comp::AbilityPool), } @@ -46,9 +43,6 @@ sum_type! { Mass(PhantomData), Gravity(PhantomData), Sticky(PhantomData), - OverrideAction(PhantomData), - OverrideMove(PhantomData), - OverrideState(PhantomData), AbilityAction(PhantomData), AbilityPool(PhantomData), } @@ -70,9 +64,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::OverrideAction(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::OverrideMove(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::OverrideState(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::AbilityAction(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::AbilityPool(comp) => sync::handle_insert(comp, entity, world), } @@ -92,9 +83,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::OverrideAction(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::OverrideMove(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::OverrideState(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::AbilityAction(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::AbilityPool(comp) => sync::handle_modify(comp, entity, world), } @@ -116,15 +104,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPhantom::Mass(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Gravity(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Sticky(_) => sync::handle_remove::(entity, world), - EcsCompPhantom::OverrideAction(_) => { - sync::handle_remove::(entity, world) - } - EcsCompPhantom::OverrideMove(_) => { - sync::handle_remove::(entity, world) - } - EcsCompPhantom::OverrideState(_) => { - sync::handle_remove::(entity, world) - } EcsCompPhantom::AbilityAction(_) => { sync::handle_remove::(entity, world) } diff --git a/common/src/state.rs b/common/src/state.rs index d5d8e1cf21..430b86bb52 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -110,9 +110,6 @@ impl State { ecs.register::(); ecs.register::(); ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); ecs.register::(); ecs.register::(); ecs.register::(); diff --git a/common/src/states/mod.rs b/common/src/states/mod.rs index 1bed45136f..d95186eaf9 100644 --- a/common/src/states/mod.rs +++ b/common/src/states/mod.rs @@ -32,7 +32,7 @@ use crate::comp::{ /// /// ## Example Implementation: /// ``` -/// use super::utils::*; +/// use crate::states::utils; /// /// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] /// pub struct RunState { @@ -54,27 +54,12 @@ use crate::comp::{ /// ori: *ecs_data.ori, /// }; /// -/// // Update player's Vel -/// update.vel.0 += Vec2::broadcast(ecs_data.dt.0) -/// * ecs_data.inputs.move_dir -/// * if update.vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) { -/// HUMANOID_ACCEL -/// } else { -/// 0.0 -/// }; -/// /// // -- snip -- -/// // Other updates; checks for gliding, climbing, etc. -/// -/// // Try to jump -/// if state_utils::can_jump(ecs_data.physics, ecs_data.inputs) { -/// update.character.move_state = Jump(None); -/// update -/// } +/// // Updates; checks for gliding, climbing, etc. /// /// // Update based on groundedness /// update.character.move_state = -/// state_utils::determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs); +/// utils::determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs); /// /// update /// } @@ -125,6 +110,7 @@ impl ActionState { } } + // TODO: remove when we split up character states into SingleAction and MultiAction enum variants /// Returns whether a given `ActionState` overrides `MoveState` `handle()`ing pub fn overrides_move_state(&self) -> bool { match self { @@ -149,6 +135,7 @@ impl ActionState { // fn's that relate to individual `MoveState`s // or passing data from system to handlers impl MoveState { + // TODO: remove when we split up character states into SingleAction and MultiAction enum variants /// Passes data to variant or subvariant handlers /// States contain `Option`s, and will be /// `None` if state data has not been initialized. So we have to diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index 98460e3248..272462f3f6 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -1,6 +1,4 @@ -use crate::comp::{ - Agent, CharacterState, Controller, ControllerInputs, MountState, MoveState::Glide, Pos, Stats, -}; +use crate::comp::{Agent, CharacterState, Controller, MountState, MoveState::Glide, Pos, Stats}; use crate::hierarchical::ChunkPath; use crate::pathfinding::WorldPath; use crate::terrain::TerrainGrid; diff --git a/common/src/sys/character_state.rs b/common/src/sys/character_state.rs index 258abe8cee..151b0a3791 100644 --- a/common/src/sys/character_state.rs +++ b/common/src/sys/character_state.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ - Body, CharacterState, Controller, EcsStateData, Mounting, MoveState::*, Ori, - OverrideAction, OverrideMove, OverrideState, PhysicsState, Pos, Stats, Vel, + Body, CharacterState, Controller, EcsStateData, Mounting, MoveState::*, Ori, PhysicsState, + Pos, Stats, Vel, }, event::{EventBus, LocalEvent, ServerEvent}, state::DeltaTime, @@ -35,9 +35,6 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, PhysicsState>, ReadStorage<'a, Uid>, ReadStorage<'a, Mounting>, - ReadStorage<'a, OverrideState>, - ReadStorage<'a, OverrideMove>, - ReadStorage<'a, OverrideAction>, ); fn run( &mut self, @@ -58,12 +55,9 @@ impl<'a> System<'a> for Sys { physics_states, uids, mountings, - state_overrides, - move_overrides, - action_overrides, ): Self::SystemData, ) { - for (entity, uid, mut character, pos, vel, ori, controller, stats, body, physics, ()) in ( + for (entity, uid, mut character, pos, vel, ori, controller, stats, body, physics) in ( &entities, &uids, &mut character_states, @@ -74,7 +68,6 @@ impl<'a> System<'a> for Sys { &stats, &bodies, &physics_states, - !&state_overrides, ) .join() { @@ -99,10 +92,7 @@ impl<'a> System<'a> for Sys { } // Determine new action if character can act - if let (None, false) = ( - action_overrides.get(entity), - character.move_state.overrides_action_state(), - ) { + if !character.move_state.overrides_action_state() { let state_update = character.action_state.update(&EcsStateData { entity: &entity, uid, @@ -127,10 +117,7 @@ impl<'a> System<'a> for Sys { } // Determine new move state if character can move - if let (None, false) = ( - move_overrides.get(entity), - character.action_state.overrides_move_state(), - ) { + if !character.action_state.overrides_move_state() { let state_update = character.move_state.update(&EcsStateData { entity: &entity, uid, diff --git a/voxygen/src/audio/sfx/event_mapper/movement.rs b/voxygen/src/audio/sfx/event_mapper/movement.rs index fda1239ba9..eecf6d7752 100644 --- a/voxygen/src/audio/sfx/event_mapper/movement.rs +++ b/voxygen/src/audio/sfx/event_mapper/movement.rs @@ -4,10 +4,7 @@ use crate::audio::sfx::{SfxTriggerItem, SfxTriggers}; use client::Client; use common::{ - comp::{ - ActionState, AttackKind::*, Body, CharacterState, DodgeKind::*, ItemKind, MoveState, Pos, - Stats, SwordKind::*, ToolData, ToolKind::*, - }, + comp::{ActionState, Body, CharacterState, MoveState, Pos}, event::{EventBus, SfxEvent, SfxEventItem}, }; use hashbrown::HashMap; @@ -157,8 +154,7 @@ impl MovementEventMapper { mod tests { use super::*; use common::{ - assets, - comp::{ActionState, MoveState, Stats}, + comp::{ActionState, CharacterState, DodgeKind::*, MoveState}, event::SfxEvent, }; use std::time::{Duration, Instant};