mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Address MR 2612 review comments.
This commit is contained in:
parent
c417e8c5b9
commit
a4d6f0f3c1
@ -45,10 +45,3 @@ impl Component for WaypointArea {
|
||||
impl Default for WaypointArea {
|
||||
fn default() -> Self { Self(5.0) }
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct RepositionOnChunkLoad;
|
||||
|
||||
impl Component for RepositionOnChunkLoad {
|
||||
type Storage = IdvStorage<Self>;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ pub use self::{
|
||||
slot, Inventory, InventoryUpdate, InventoryUpdateEvent,
|
||||
},
|
||||
last::Last,
|
||||
location::{RepositionOnChunkLoad, Waypoint, WaypointArea},
|
||||
location::{Waypoint, WaypointArea},
|
||||
misc::Object,
|
||||
ori::Ori,
|
||||
phys::{
|
||||
|
@ -182,7 +182,6 @@ impl State {
|
||||
ecs.register::<comp::Last<comp::Ori>>();
|
||||
ecs.register::<comp::Alignment>();
|
||||
ecs.register::<comp::Agent>();
|
||||
ecs.register::<comp::RepositionOnChunkLoad>();
|
||||
ecs.register::<comp::WaypointArea>();
|
||||
ecs.register::<comp::ForceUpdate>();
|
||||
ecs.register::<comp::InventoryUpdate>();
|
||||
|
@ -50,7 +50,7 @@ use crate::{
|
||||
connection_handler::ConnectionHandler,
|
||||
data_dir::DataDir,
|
||||
login_provider::LoginProvider,
|
||||
presence::{Presence, RegionSubscription},
|
||||
presence::{Presence, RegionSubscription, RepositionOnChunkLoad},
|
||||
rtsim::RtSim,
|
||||
state_ext::StateExt,
|
||||
sys::sentinel::{DeletedEntities, TrackedComps},
|
||||
@ -250,6 +250,7 @@ impl Server {
|
||||
state.ecs_mut().register::<wiring::Circuit>();
|
||||
state.ecs_mut().register::<comp::HomeChunk>();
|
||||
state.ecs_mut().register::<login_provider::PendingLogin>();
|
||||
state.ecs_mut().register::<RepositionOnChunkLoad>();
|
||||
|
||||
//Alias validator
|
||||
let banned_words_paths = &settings.banned_words_files;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use common_net::msg::PresenceKind;
|
||||
use hashbrown::HashSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specs::{Component, DerefFlaggedStorage};
|
||||
use specs::{Component, DerefFlaggedStorage, NullStorage};
|
||||
use specs_idvs::IdvStorage;
|
||||
use vek::*;
|
||||
|
||||
@ -40,3 +40,10 @@ pub struct RegionSubscription {
|
||||
impl Component for RegionSubscription {
|
||||
type Storage = DerefFlaggedStorage<Self, IdvStorage<Self>>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct RepositionOnChunkLoad;
|
||||
|
||||
impl Component for RepositionOnChunkLoad {
|
||||
type Storage = NullStorage<Self>;
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
use crate::{
|
||||
client::Client, persistence::PersistedComponents, presence::Presence, settings::Settings,
|
||||
sys::sentinel::DeletedEntities, wiring, SpawnPoint,
|
||||
client::Client,
|
||||
persistence::PersistedComponents,
|
||||
presence::{Presence, RepositionOnChunkLoad},
|
||||
settings::Settings,
|
||||
sys::sentinel::DeletedEntities,
|
||||
wiring, SpawnPoint,
|
||||
};
|
||||
use common::{
|
||||
character::CharacterId,
|
||||
@ -525,7 +529,7 @@ impl StateExt for State {
|
||||
);
|
||||
|
||||
if let Some(waypoint) = waypoint {
|
||||
self.write_component_ignore_entity_dead(entity, comp::RepositionOnChunkLoad);
|
||||
self.write_component_ignore_entity_dead(entity, RepositionOnChunkLoad);
|
||||
self.write_component_ignore_entity_dead(entity, waypoint);
|
||||
self.write_component_ignore_entity_dead(entity, comp::Pos(waypoint.get_pos()));
|
||||
self.write_component_ignore_entity_dead(entity, comp::Vel(Vec3::zero()));
|
||||
|
@ -1,9 +1,14 @@
|
||||
use crate::{
|
||||
chunk_generator::ChunkGenerator, client::Client, metrics::NetworkRequestMetrics,
|
||||
presence::Presence, rtsim::RtSim, settings::Settings, SpawnPoint, Tick,
|
||||
chunk_generator::ChunkGenerator,
|
||||
client::Client,
|
||||
metrics::NetworkRequestMetrics,
|
||||
presence::{Presence, RepositionOnChunkLoad},
|
||||
rtsim::RtSim,
|
||||
settings::Settings,
|
||||
SpawnPoint, Tick,
|
||||
};
|
||||
use common::{
|
||||
comp::{self, agent, bird_medium, Alignment, BehaviorCapability, Pos, RepositionOnChunkLoad},
|
||||
comp::{self, agent, bird_medium, Alignment, BehaviorCapability, ForceUpdate, Pos},
|
||||
event::{EventBus, ServerEvent},
|
||||
generation::{get_npc_name, EntityInfo},
|
||||
npc::NPC_NAMES,
|
||||
@ -98,6 +103,7 @@ impl<'a> System<'a> for Sys {
|
||||
ReadStorage<'a, Client>,
|
||||
Entities<'a>,
|
||||
WriteStorage<'a, RepositionOnChunkLoad>,
|
||||
WriteStorage<'a, ForceUpdate>,
|
||||
);
|
||||
|
||||
const NAME: &'static str = "terrain";
|
||||
@ -121,6 +127,7 @@ impl<'a> System<'a> for Sys {
|
||||
clients,
|
||||
entities,
|
||||
mut reposition_on_load,
|
||||
mut force_update,
|
||||
): Self::SystemData,
|
||||
) {
|
||||
let mut server_emitter = server_event_bus.emitter();
|
||||
@ -310,19 +317,23 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
}
|
||||
|
||||
for (entity, pos) in (&entities, &mut positions).join() {
|
||||
if reposition_on_load.get(entity).is_some() {
|
||||
// If the player is in the new chunk and is marked as needing repositioning once
|
||||
// the chunk loads (e.g. from having just logged in), reposition them
|
||||
let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32));
|
||||
if let Some((_, chunk)) = new_chunks.iter().find(|(key, _)| *key == chunk_pos) {
|
||||
pos.0 = chunk
|
||||
.find_accessible_pos(pos.0.xy().as_::<i32>(), false)
|
||||
.as_::<f32>();
|
||||
reposition_on_load.remove(entity);
|
||||
}
|
||||
let mut repositioned = Vec::new();
|
||||
for (entity, pos, _) in (&entities, &mut positions, &reposition_on_load).join() {
|
||||
// If an entity is marked as needing repositioning once the chunk loads (e.g.
|
||||
// from having just logged in), reposition them.
|
||||
|
||||
let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32));
|
||||
if let Some(chunk) = terrain.get_key(chunk_pos) {
|
||||
pos.0 = chunk
|
||||
.find_accessible_pos(pos.0.xy().as_::<i32>(), false)
|
||||
.as_::<f32>();
|
||||
repositioned.push(entity);
|
||||
let _ = force_update.insert(entity, ForceUpdate);
|
||||
}
|
||||
}
|
||||
for entity in repositioned {
|
||||
reposition_on_load.remove(entity);
|
||||
}
|
||||
|
||||
// Send the chunk to all nearby players.
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
Loading…
Reference in New Issue
Block a user