Update from MR comments

This commit is contained in:
AdamWhitehurst 2020-01-17 08:39:21 -08:00
parent 5959d2a5c7
commit 976eface66
9 changed files with 15 additions and 90 deletions

View File

@ -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<Self, HashMapStorage<Self>>;
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct OverrideState;
impl Component for OverrideState {
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct OverrideAction;
impl Component for OverrideAction {
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct OverrideMove;
impl Component for OverrideMove {
type Storage = FlaggedStorage<Self, NullStorage<Self>>;
}

View File

@ -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,

View File

@ -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;

View File

@ -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<comp::Mass>),
Gravity(PhantomData<comp::Gravity>),
Sticky(PhantomData<comp::Sticky>),
OverrideAction(PhantomData<comp::OverrideAction>),
OverrideMove(PhantomData<comp::OverrideMove>),
OverrideState(PhantomData<comp::OverrideState>),
AbilityAction(PhantomData<comp::AbilityAction>),
AbilityPool(PhantomData<comp::AbilityPool>),
}
@ -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::<comp::Mass>(entity, world),
EcsCompPhantom::Gravity(_) => sync::handle_remove::<comp::Gravity>(entity, world),
EcsCompPhantom::Sticky(_) => sync::handle_remove::<comp::Sticky>(entity, world),
EcsCompPhantom::OverrideAction(_) => {
sync::handle_remove::<comp::OverrideAction>(entity, world)
}
EcsCompPhantom::OverrideMove(_) => {
sync::handle_remove::<comp::OverrideMove>(entity, world)
}
EcsCompPhantom::OverrideState(_) => {
sync::handle_remove::<comp::OverrideState>(entity, world)
}
EcsCompPhantom::AbilityAction(_) => {
sync::handle_remove::<comp::AbilityAction>(entity, world)
}

View File

@ -110,9 +110,6 @@ impl State {
ecs.register::<comp::AbilityPool>();
ecs.register::<comp::AbilityAction>();
ecs.register::<comp::Projectile>();
ecs.register::<comp::OverrideAction>();
ecs.register::<comp::OverrideMove>();
ecs.register::<comp::OverrideState>();
ecs.register::<comp::Body>();
ecs.register::<comp::Player>();
ecs.register::<comp::Stats>();

View File

@ -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<StateHandler Implementor>`s, and will be
/// `None` if state data has not been initialized. So we have to

View File

@ -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;

View File

@ -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,

View File

@ -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};