From 4bdbb3ff6b090f1e9d517e0da5b8b083e810ca51 Mon Sep 17 00:00:00 2001 From: TelepathicWalrus Date: Sun, 21 May 2023 10:42:44 +0100 Subject: [PATCH] Move stay position to agent --- assets/voxygen/i18n/en/hud/misc.ftl | 3 +-- common/net/src/synced_components.rs | 7 ------- common/src/comp/agent.rs | 2 ++ common/src/comp/pet.rs | 14 ++------------ common/state/src/state.rs | 1 - server/agent/src/data.rs | 3 --- server/src/events/interaction.rs | 15 +++++++-------- server/src/sys/agent.rs | 6 +----- server/src/sys/agent/behavior_tree.rs | 9 +++++---- server/src/sys/pets.rs | 11 ++++------- voxygen/src/hud/mod.rs | 17 ++++------------- 11 files changed, 26 insertions(+), 62 deletions(-) diff --git a/assets/voxygen/i18n/en/hud/misc.ftl b/assets/voxygen/i18n/en/hud/misc.ftl index 4148083bb9..85ff7d30c1 100644 --- a/assets/voxygen/i18n/en/hud/misc.ftl +++ b/assets/voxygen/i18n/en/hud/misc.ftl @@ -54,7 +54,6 @@ hud-mine-needs_unhandled_case = Needs ??? hud-talk = Talk hud-trade = Trade hud-mount = Mount -hud-stay = Stay -hud-follow = Follow +hud-stay-follow = Stay/Follow hud-sit = Sit hud-steer = Steer diff --git a/common/net/src/synced_components.rs b/common/net/src/synced_components.rs index e9a50d92f0..d8d5bf858b 100755 --- a/common/net/src/synced_components.rs +++ b/common/net/src/synced_components.rs @@ -46,7 +46,6 @@ macro_rules! synced_components { beam_segment: BeamSegment, alignment: Alignment, stance: Stance, - pet_state: PetState, // TODO: change this to `SyncFrom::ClientEntity` and sync the bare minimum // from other entities (e.g. just keys needed to show appearance // based on their loadout). Also, it looks like this actually has @@ -74,7 +73,6 @@ macro_rules! reexport_comps { ($($name:ident: $type:ident,)*) => { mod inner { pub use common::comp::*; - pub use common::comp::pet::PetState; use common::link::Is; use common::mounting::{Mount, Rider, VolumeRider}; // We alias these because the identifier used for the @@ -106,11 +104,6 @@ synced_components!(reexport_comps); use crate::sync::{NetSync, SyncFrom}; -// These are synced from any entity within range. -impl NetSync for PetState { - const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity; -} - impl NetSync for Body { const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity; } diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 5643ba06fd..945fc7c53e 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -594,6 +594,7 @@ pub struct Agent { /// required and reset each time the flee timer is reset. pub flee_from_pos: Option, pub awareness: Awareness, + pub stay_pos: Option, /// Inputs sent up to rtsim pub rtsim_outbox: Option>, } @@ -699,6 +700,7 @@ impl Agent { sounds_heard: Vec::new(), position_pid_controller: None, flee_from_pos: None, + stay_pos: None, awareness: Awareness::new(0.0), rtsim_outbox: None, } diff --git a/common/src/comp/pet.rs b/common/src/comp/pet.rs index 0b8f8f40e6..e954eff273 100755 --- a/common/src/comp/pet.rs +++ b/common/src/comp/pet.rs @@ -1,7 +1,6 @@ -use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small, Pos}; +use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small}; use crossbeam_utils::atomic::AtomicCell; -use serde::{Deserialize, Serialize}; -use specs::{Component, DerefFlaggedStorage}; +use specs::Component; use std::{num::NonZeroU64, sync::Arc}; pub type PetId = AtomicCell>; @@ -108,12 +107,3 @@ impl Component for Pet { // isn't worth using `DenseVecStorage` here. type Storage = specs::VecStorage; } - -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Default)] -pub struct PetState { - pub stay_pos: Option, -} - -impl Component for PetState { - type Storage = DerefFlaggedStorage; -} diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 39668f0b71..7771d54f00 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -203,7 +203,6 @@ impl State { ecs.register::>(); ecs.register::>(); ecs.register::>(); - ecs.register::(); ecs.register::(); ecs.register::(); ecs.register::(); diff --git a/server/agent/src/data.rs b/server/agent/src/data.rs index 64000bdb08..a5537684e9 100755 --- a/server/agent/src/data.rs +++ b/server/agent/src/data.rs @@ -12,7 +12,6 @@ use common::{ }, slot::EquipSlot, }, - pet::PetState, ActiveAbilities, Alignment, Body, CharacterState, Combo, Energy, Health, Inventory, LightEmitter, LootOwner, Ori, PhysicsState, Poise, Pos, Presence, Scale, SkillSet, Stance, Stats, Vel, @@ -53,7 +52,6 @@ pub struct AgentData<'a> { pub light_emitter: Option<&'a LightEmitter>, pub glider_equipped: bool, pub is_gliding: bool, - pub stay_pos: Option, pub health: Option<&'a Health>, pub char_state: &'a CharacterState, pub active_abilities: &'a ActiveAbilities, @@ -349,7 +347,6 @@ pub struct ReadData<'a> { pub is_mounts: ReadStorage<'a, Is>, pub is_riders: ReadStorage<'a, Is>, pub is_volume_riders: ReadStorage<'a, Is>, - pub pet_states: ReadStorage<'a, PetState>, pub time_of_day: Read<'a, TimeOfDay>, pub light_emitter: ReadStorage<'a, LightEmitter>, #[cfg(feature = "worldgen")] diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index 502759e474..80410cf2ec 100755 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -10,7 +10,7 @@ use common::{ inventory::slot::EquipSlot, item::{flatten_counted_items, MaterialStatManifest}, loot_owner::LootOwnerKind, - pet::{is_mountable, PetState}, + pet::is_mountable, tool::{AbilityMap, ToolKind}, Inventory, LootOwner, Pos, SkillGroupKind, }, @@ -134,7 +134,7 @@ pub fn handle_mount(server: &mut Server, rider: EcsEntity, mount: EcsEntity) { let is_stay = state .ecs() - .read_storage::() + .read_storage::() .get(mount) .and_then(|x| x.stay_pos) .is_some(); @@ -225,7 +225,7 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec } let prev_pet_pos = state .ecs() - .read_storage::() + .read_storage::() .get(pet) .and_then(|s| s.stay_pos); let mut new_pet_pos = None; @@ -236,12 +236,11 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec && within_mounting_range(positions.get(command_giver), positions.get(pet)) && state.ecs().read_storage::>().get(pet).is_none() { - let _ = state + state .ecs() - .write_storage::() - .insert(pet, PetState { - stay_pos: new_pet_pos, - }); + .write_storage::() + .get_mut(pet) + .map(|s| s.stay_pos = new_pet_pos); } } diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 9208e518f9..8747f9ba9f 100755 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -72,7 +72,6 @@ impl<'a> System<'a> for Sys { !&read_data.is_mounts, read_data.is_riders.maybe(), read_data.is_volume_riders.maybe(), - read_data.pet_states.maybe(), ), ) .par_join() @@ -96,7 +95,7 @@ impl<'a> System<'a> for Sys { light_emitter, group, rtsim_entity, - (_, is_rider, is_volume_rider, pet_state), + (_, is_rider, is_volume_rider), )| { let mut event_emitter = event_bus.emitter(); let mut rng = thread_rng(); @@ -160,8 +159,6 @@ impl<'a> System<'a> for Sys { matches!(&*item.kind(), comp::item::ItemKind::Glider) }); - let stay_pos = pet_state.and_then(|s| s.stay_pos); - let is_gliding = matches!( read_data.char_states.get(entity), Some(CharacterState::GlideWield(_) | CharacterState::Glide(_)) @@ -232,7 +229,6 @@ impl<'a> System<'a> for Sys { light_emitter, glider_equipped, is_gliding, - stay_pos, health: read_data.healths.get(entity), char_state, active_abilities, diff --git a/server/src/sys/agent/behavior_tree.rs b/server/src/sys/agent/behavior_tree.rs index 0ab52c3ccd..fb547e9dd0 100755 --- a/server/src/sys/agent/behavior_tree.rs +++ b/server/src/sys/agent/behavior_tree.rs @@ -406,11 +406,11 @@ fn do_pickup_loot(bdata: &mut BehaviorData) -> bool { fn follow_if_far_away(bdata: &mut BehaviorData) -> bool { if let Some(Target { target, .. }) = bdata.agent.target { if let Some(tgt_pos) = bdata.read_data.positions.get(target) { - let stay = bdata.agent_data.stay_pos.is_some(); + let stay = bdata.agent.stay_pos.is_some(); if stay { - let stay_pos = bdata.agent_data.stay_pos.map_or(Pos(Vec3::zero()), |v| v); + let stay_pos = bdata.agent.stay_pos.map_or(Pos(Vec3::zero()), |v| v); let distance_from_stay = stay_pos.0.distance_squared(bdata.agent_data.pos.0); - + bdata.controller.push_action(ControlAction::Sit); if distance_from_stay > (MAX_STAY_DISTANCE).powi(2) { bdata.agent_data.follow( bdata.agent, @@ -421,6 +421,7 @@ fn follow_if_far_away(bdata: &mut BehaviorData) -> bool { return true; } } else { + bdata.controller.push_action(ControlAction::Stand); let dist_sqrd = bdata.agent_data.pos.0.distance_squared(tgt_pos.0); if dist_sqrd > (MAX_PATROL_DIST * bdata.agent.psyche.idle_wander_factor).powi(2) { bdata.agent_data.follow( @@ -449,7 +450,7 @@ fn attack_if_owner_hurt(bdata: &mut BehaviorData) -> bool { } else { false }; - let stay = bdata.agent_data.stay_pos.is_some(); + let stay = bdata.agent.stay_pos.is_some(); if owner_recently_attacked && !stay { bdata.agent_data.attack_target_attacker( bdata.agent, diff --git a/server/src/sys/pets.rs b/server/src/sys/pets.rs index 7789f0d27c..c7c49fa2fa 100755 --- a/server/src/sys/pets.rs +++ b/server/src/sys/pets.rs @@ -1,5 +1,5 @@ use common::{ - comp::{pet::PetState, Alignment, Pet, PhysicsState, Pos}, + comp::{Agent, Alignment, Pet, PhysicsState, Pos}, terrain::TerrainGrid, uid::IdMaps, }; @@ -16,7 +16,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Pos>, ReadStorage<'a, Alignment>, ReadStorage<'a, Pet>, - ReadStorage<'a, PetState>, + ReadStorage<'a, Agent>, ReadStorage<'a, PhysicsState>, Read<'a, IdMaps>, ); @@ -27,7 +27,7 @@ impl<'a> System<'a> for Sys { fn run( _job: &mut Job, - (entities, terrain, mut positions, alignments, pets, pet_state, physics, id_maps): Self::SystemData, + (entities, terrain, mut positions, alignments, pets, agn, physics, id_maps): Self::SystemData, ) { const LOST_PET_DISTANCE_THRESHOLD: f32 = 200.0; @@ -58,10 +58,7 @@ impl<'a> System<'a> for Sys { .collect(); for (pet_entity, owner_pos) in lost_pets.iter() { - let stay = pet_state - .get(*pet_entity) - .and_then(|f| f.stay_pos) - .is_some(); + let stay = agn.get(*pet_entity).and_then(|x| x.stay_pos).is_some(); if let Some(mut pet_pos) = positions.get_mut(*pet_entity) && !stay{ // Move the pets to their owner's position // TODO: Create a teleportation event to handle this instead of diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index b44a3d266d..b753bec038 100755 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1504,7 +1504,6 @@ impl Hud { let alignments = ecs.read_storage::(); let is_mounts = ecs.read_storage::>(); let is_riders = ecs.read_storage::>(); - let pet_state = ecs.read_storage::(); let stances = ecs.read_storage::(); let time = ecs.read_resource::