mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Update from MR comments
This commit is contained in:
parent
5959d2a5c7
commit
976eface66
@ -9,7 +9,7 @@ use crate::{
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use specs::LazyUpdate;
|
use specs::LazyUpdate;
|
||||||
use specs::{Component, Entity, FlaggedStorage, HashMapStorage, NullStorage};
|
use specs::{Component, Entity, FlaggedStorage, HashMapStorage};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub struct EcsStateData<'a> {
|
pub struct EcsStateData<'a> {
|
||||||
@ -159,21 +159,3 @@ impl Default for CharacterState {
|
|||||||
impl Component for CharacterState {
|
impl Component for CharacterState {
|
||||||
type Storage = FlaggedStorage<Self, HashMapStorage<Self>>;
|
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>>;
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,7 @@ pub use body::{
|
|||||||
};
|
};
|
||||||
pub use character_state::{
|
pub use character_state::{
|
||||||
ActionState, AttackKind, BlockKind, CharacterState, DodgeKind, EcsStateData, MoveState,
|
ActionState, AttackKind, BlockKind, CharacterState, DodgeKind, EcsStateData, MoveState,
|
||||||
OverrideAction, OverrideMove, OverrideState, StateUpdate,
|
StateUpdate,
|
||||||
};
|
};
|
||||||
pub use controller::{
|
pub use controller::{
|
||||||
ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState,
|
ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::{comp, sync::Uid};
|
use crate::{comp, sync::Uid};
|
||||||
use comp::item::ToolKind;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use specs::Entity as EcsEntity;
|
use specs::Entity as EcsEntity;
|
||||||
|
@ -21,9 +21,6 @@ sum_type! {
|
|||||||
Mass(comp::Mass),
|
Mass(comp::Mass),
|
||||||
Gravity(comp::Gravity),
|
Gravity(comp::Gravity),
|
||||||
Sticky(comp::Sticky),
|
Sticky(comp::Sticky),
|
||||||
OverrideAction(comp::OverrideAction),
|
|
||||||
OverrideMove(comp::OverrideMove),
|
|
||||||
OverrideState(comp::OverrideState),
|
|
||||||
AbilityAction(comp::AbilityAction),
|
AbilityAction(comp::AbilityAction),
|
||||||
AbilityPool(comp::AbilityPool),
|
AbilityPool(comp::AbilityPool),
|
||||||
}
|
}
|
||||||
@ -46,9 +43,6 @@ sum_type! {
|
|||||||
Mass(PhantomData<comp::Mass>),
|
Mass(PhantomData<comp::Mass>),
|
||||||
Gravity(PhantomData<comp::Gravity>),
|
Gravity(PhantomData<comp::Gravity>),
|
||||||
Sticky(PhantomData<comp::Sticky>),
|
Sticky(PhantomData<comp::Sticky>),
|
||||||
OverrideAction(PhantomData<comp::OverrideAction>),
|
|
||||||
OverrideMove(PhantomData<comp::OverrideMove>),
|
|
||||||
OverrideState(PhantomData<comp::OverrideState>),
|
|
||||||
AbilityAction(PhantomData<comp::AbilityAction>),
|
AbilityAction(PhantomData<comp::AbilityAction>),
|
||||||
AbilityPool(PhantomData<comp::AbilityPool>),
|
AbilityPool(PhantomData<comp::AbilityPool>),
|
||||||
}
|
}
|
||||||
@ -70,9 +64,6 @@ impl sync::CompPacket for EcsCompPacket {
|
|||||||
EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world),
|
EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world),
|
||||||
EcsCompPacket::Gravity(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::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::AbilityAction(comp) => sync::handle_insert(comp, entity, world),
|
||||||
EcsCompPacket::AbilityPool(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::Mass(comp) => sync::handle_modify(comp, entity, world),
|
||||||
EcsCompPacket::Gravity(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::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::AbilityAction(comp) => sync::handle_modify(comp, entity, world),
|
||||||
EcsCompPacket::AbilityPool(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::Mass(_) => sync::handle_remove::<comp::Mass>(entity, world),
|
||||||
EcsCompPhantom::Gravity(_) => sync::handle_remove::<comp::Gravity>(entity, world),
|
EcsCompPhantom::Gravity(_) => sync::handle_remove::<comp::Gravity>(entity, world),
|
||||||
EcsCompPhantom::Sticky(_) => sync::handle_remove::<comp::Sticky>(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(_) => {
|
EcsCompPhantom::AbilityAction(_) => {
|
||||||
sync::handle_remove::<comp::AbilityAction>(entity, world)
|
sync::handle_remove::<comp::AbilityAction>(entity, world)
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,6 @@ impl State {
|
|||||||
ecs.register::<comp::AbilityPool>();
|
ecs.register::<comp::AbilityPool>();
|
||||||
ecs.register::<comp::AbilityAction>();
|
ecs.register::<comp::AbilityAction>();
|
||||||
ecs.register::<comp::Projectile>();
|
ecs.register::<comp::Projectile>();
|
||||||
ecs.register::<comp::OverrideAction>();
|
|
||||||
ecs.register::<comp::OverrideMove>();
|
|
||||||
ecs.register::<comp::OverrideState>();
|
|
||||||
ecs.register::<comp::Body>();
|
ecs.register::<comp::Body>();
|
||||||
ecs.register::<comp::Player>();
|
ecs.register::<comp::Player>();
|
||||||
ecs.register::<comp::Stats>();
|
ecs.register::<comp::Stats>();
|
||||||
|
@ -32,7 +32,7 @@ use crate::comp::{
|
|||||||
///
|
///
|
||||||
/// ## Example Implementation:
|
/// ## Example Implementation:
|
||||||
/// ```
|
/// ```
|
||||||
/// use super::utils::*;
|
/// use crate::states::utils;
|
||||||
///
|
///
|
||||||
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||||
/// pub struct RunState {
|
/// pub struct RunState {
|
||||||
@ -54,27 +54,12 @@ use crate::comp::{
|
|||||||
/// ori: *ecs_data.ori,
|
/// 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 --
|
/// // -- snip --
|
||||||
/// // Other updates; checks for gliding, climbing, etc.
|
/// // 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
|
|
||||||
/// }
|
|
||||||
///
|
///
|
||||||
/// // Update based on groundedness
|
/// // Update based on groundedness
|
||||||
/// update.character.move_state =
|
/// 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
|
/// 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
|
/// Returns whether a given `ActionState` overrides `MoveState` `handle()`ing
|
||||||
pub fn overrides_move_state(&self) -> bool {
|
pub fn overrides_move_state(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -149,6 +135,7 @@ impl ActionState {
|
|||||||
// fn's that relate to individual `MoveState`s
|
// fn's that relate to individual `MoveState`s
|
||||||
// or passing data from system to handlers
|
// or passing data from system to handlers
|
||||||
impl MoveState {
|
impl MoveState {
|
||||||
|
// TODO: remove when we split up character states into SingleAction and MultiAction enum variants
|
||||||
/// Passes data to variant or subvariant handlers
|
/// Passes data to variant or subvariant handlers
|
||||||
/// States contain `Option<StateHandler Implementor>`s, and will be
|
/// States contain `Option<StateHandler Implementor>`s, and will be
|
||||||
/// `None` if state data has not been initialized. So we have to
|
/// `None` if state data has not been initialized. So we have to
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use crate::comp::{
|
use crate::comp::{Agent, CharacterState, Controller, MountState, MoveState::Glide, Pos, Stats};
|
||||||
Agent, CharacterState, Controller, ControllerInputs, MountState, MoveState::Glide, Pos, Stats,
|
|
||||||
};
|
|
||||||
use crate::hierarchical::ChunkPath;
|
use crate::hierarchical::ChunkPath;
|
||||||
use crate::pathfinding::WorldPath;
|
use crate::pathfinding::WorldPath;
|
||||||
use crate::terrain::TerrainGrid;
|
use crate::terrain::TerrainGrid;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
Body, CharacterState, Controller, EcsStateData, Mounting, MoveState::*, Ori,
|
Body, CharacterState, Controller, EcsStateData, Mounting, MoveState::*, Ori, PhysicsState,
|
||||||
OverrideAction, OverrideMove, OverrideState, PhysicsState, Pos, Stats, Vel,
|
Pos, Stats, Vel,
|
||||||
},
|
},
|
||||||
event::{EventBus, LocalEvent, ServerEvent},
|
event::{EventBus, LocalEvent, ServerEvent},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
@ -35,9 +35,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
ReadStorage<'a, PhysicsState>,
|
ReadStorage<'a, PhysicsState>,
|
||||||
ReadStorage<'a, Uid>,
|
ReadStorage<'a, Uid>,
|
||||||
ReadStorage<'a, Mounting>,
|
ReadStorage<'a, Mounting>,
|
||||||
ReadStorage<'a, OverrideState>,
|
|
||||||
ReadStorage<'a, OverrideMove>,
|
|
||||||
ReadStorage<'a, OverrideAction>,
|
|
||||||
);
|
);
|
||||||
fn run(
|
fn run(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -58,12 +55,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
physics_states,
|
physics_states,
|
||||||
uids,
|
uids,
|
||||||
mountings,
|
mountings,
|
||||||
state_overrides,
|
|
||||||
move_overrides,
|
|
||||||
action_overrides,
|
|
||||||
): Self::SystemData,
|
): 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,
|
&entities,
|
||||||
&uids,
|
&uids,
|
||||||
&mut character_states,
|
&mut character_states,
|
||||||
@ -74,7 +68,6 @@ impl<'a> System<'a> for Sys {
|
|||||||
&stats,
|
&stats,
|
||||||
&bodies,
|
&bodies,
|
||||||
&physics_states,
|
&physics_states,
|
||||||
!&state_overrides,
|
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
@ -99,10 +92,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine new action if character can act
|
// Determine new action if character can act
|
||||||
if let (None, false) = (
|
if !character.move_state.overrides_action_state() {
|
||||||
action_overrides.get(entity),
|
|
||||||
character.move_state.overrides_action_state(),
|
|
||||||
) {
|
|
||||||
let state_update = character.action_state.update(&EcsStateData {
|
let state_update = character.action_state.update(&EcsStateData {
|
||||||
entity: &entity,
|
entity: &entity,
|
||||||
uid,
|
uid,
|
||||||
@ -127,10 +117,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine new move state if character can move
|
// Determine new move state if character can move
|
||||||
if let (None, false) = (
|
if !character.action_state.overrides_move_state() {
|
||||||
move_overrides.get(entity),
|
|
||||||
character.action_state.overrides_move_state(),
|
|
||||||
) {
|
|
||||||
let state_update = character.move_state.update(&EcsStateData {
|
let state_update = character.move_state.update(&EcsStateData {
|
||||||
entity: &entity,
|
entity: &entity,
|
||||||
uid,
|
uid,
|
||||||
|
@ -4,10 +4,7 @@ use crate::audio::sfx::{SfxTriggerItem, SfxTriggers};
|
|||||||
|
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{ActionState, Body, CharacterState, MoveState, Pos},
|
||||||
ActionState, AttackKind::*, Body, CharacterState, DodgeKind::*, ItemKind, MoveState, Pos,
|
|
||||||
Stats, SwordKind::*, ToolData, ToolKind::*,
|
|
||||||
},
|
|
||||||
event::{EventBus, SfxEvent, SfxEventItem},
|
event::{EventBus, SfxEvent, SfxEventItem},
|
||||||
};
|
};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
@ -157,8 +154,7 @@ impl MovementEventMapper {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use common::{
|
use common::{
|
||||||
assets,
|
comp::{ActionState, CharacterState, DodgeKind::*, MoveState},
|
||||||
comp::{ActionState, MoveState, Stats},
|
|
||||||
event::SfxEvent,
|
event::SfxEvent,
|
||||||
};
|
};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
Loading…
Reference in New Issue
Block a user