Merge branch 'imbris/small-fixes' into 'master'

Fix a couple things

See merge request veloren/veloren!1328
This commit is contained in:
Imbris 2020-08-27 01:54:11 +00:00
commit 2dfde32b45
11 changed files with 65 additions and 60 deletions

View File

@ -556,7 +556,7 @@ impl Client {
} }
pub fn pick_up(&mut self, entity: EcsEntity) { pub fn pick_up(&mut self, entity: EcsEntity) {
if let Some(uid) = self.state.read_component_cloned(entity) { if let Some(uid) = self.state.read_component_copied(entity) {
self.singleton_stream self.singleton_stream
.send(ClientMsg::ControlEvent(ControlEvent::InventoryManip( .send(ClientMsg::ControlEvent(ControlEvent::InventoryManip(
InventoryManip::Pickup(uid), InventoryManip::Pickup(uid),
@ -680,7 +680,7 @@ impl Client {
} }
pub fn mount(&mut self, entity: EcsEntity) { pub fn mount(&mut self, entity: EcsEntity) {
if let Some(uid) = self.state.read_component_cloned(entity) { if let Some(uid) = self.state.read_component_copied(entity) {
self.singleton_stream self.singleton_stream
.send(ClientMsg::ControlEvent(ControlEvent::Mount(uid))) .send(ClientMsg::ControlEvent(ControlEvent::Mount(uid)))
.unwrap(); .unwrap();
@ -1456,7 +1456,7 @@ impl Client {
pub fn entity(&self) -> EcsEntity { self.entity } pub fn entity(&self) -> EcsEntity { self.entity }
/// Get the player's Uid. /// Get the player's Uid.
pub fn uid(&self) -> Option<Uid> { self.state.read_component_cloned(self.entity) } pub fn uid(&self) -> Option<Uid> { self.state.read_component_copied(self.entity) }
/// Get the client state /// Get the client state
pub fn get_client_state(&self) -> ClientState { self.client_state } pub fn get_client_state(&self) -> ClientState { self.client_state }
@ -1509,7 +1509,7 @@ impl Client {
pub fn is_admin(&self) -> bool { pub fn is_admin(&self) -> bool {
let client_uid = self let client_uid = self
.state .state
.read_component_cloned::<Uid>(self.entity) .read_component_copied::<Uid>(self.entity)
.expect("Client doesn't have a Uid!!!"); .expect("Client doesn't have a Uid!!!");
self.player_list self.player_list

View File

@ -199,10 +199,15 @@ impl State {
} }
/// Read a component attributed to a particular entity. /// Read a component attributed to a particular entity.
pub fn read_component_cloned<C: Component + Copy>(&self, entity: EcsEntity) -> Option<C> { pub fn read_component_cloned<C: Component + Clone>(&self, entity: EcsEntity) -> Option<C> {
self.ecs.read_storage().get(entity).cloned() self.ecs.read_storage().get(entity).cloned()
} }
/// Read a component attributed to a particular entity.
pub fn read_component_copied<C: Component + Copy>(&self, entity: EcsEntity) -> Option<C> {
self.ecs.read_storage().get(entity).copied()
}
/// Get a read-only reference to the storage of a particular component type. /// Get a read-only reference to the storage of a particular component type.
pub fn read_storage<C: Component>(&self) -> EcsStorage<C, Fetch<EcsMaskedStorage<C>>> { pub fn read_storage<C: Component>(&self) -> EcsStorage<C, Fetch<EcsMaskedStorage<C>>> {
self.ecs.read_storage::<C>() self.ecs.read_storage::<C>()

View File

@ -614,6 +614,7 @@ impl BParticipant {
trace!("Start participant_shutdown_mgr"); trace!("Start participant_shutdown_mgr");
let sender = s2b_shutdown_bparticipant_r.await.unwrap(); let sender = s2b_shutdown_bparticipant_r.await.unwrap();
#[cfg(feature = "metrics")]
let mut send_cache = MultiCidFrameCache::new(self.metrics.frames_out_total.clone()); let mut send_cache = MultiCidFrameCache::new(self.metrics.frames_out_total.clone());
self.close_api(None).await; self.close_api(None).await;

View File

@ -190,7 +190,7 @@ fn handle_make_block(
) { ) {
if let Some(block_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) { if let Some(block_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
if let Ok(bk) = BlockKind::try_from(block_name.as_str()) { if let Ok(bk) = BlockKind::try_from(block_name.as_str()) {
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => server.state.set_block( Some(pos) => server.state.set_block(
pos.0.map(|e| e.floor() as i32), pos.0.map(|e| e.floor() as i32),
Block::new(bk, Rgb::broadcast(255)), Block::new(bk, Rgb::broadcast(255)),
@ -262,7 +262,7 @@ fn handle_jump(
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) { if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) {
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(current_pos) => { Some(current_pos) => {
server server
.state .state
@ -287,7 +287,7 @@ fn handle_goto(
if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) { if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) {
if server if server
.state .state
.read_component_cloned::<comp::Pos>(target) .read_component_copied::<comp::Pos>(target)
.is_some() .is_some()
{ {
server server
@ -498,9 +498,9 @@ fn handle_tp(
); );
return; return;
}; };
if let Some(_pos) = server.state.read_component_cloned::<comp::Pos>(target) { if let Some(_pos) = server.state.read_component_copied::<comp::Pos>(target) {
if let Some(player) = opt_player { if let Some(player) = opt_player {
if let Some(pos) = server.state.read_component_cloned::<comp::Pos>(player) { if let Some(pos) = server.state.read_component_copied::<comp::Pos>(player) {
server.state.write_component(target, pos); server.state.write_component(target, pos);
server.state.write_component(target, comp::ForceUpdate); server.state.write_component(target, comp::ForceUpdate);
} else { } else {
@ -545,7 +545,7 @@ fn handle_spawn(
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => { (Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => {
let uid = server let uid = server
.state .state
.read_component_cloned(target) .read_component_copied(target)
.expect("Expected player to have a UID"); .expect("Expected player to have a UID");
if let Some(alignment) = parse_alignment(uid, &opt_align) { if let Some(alignment) = parse_alignment(uid, &opt_align) {
let amount = opt_amount let amount = opt_amount
@ -556,7 +556,7 @@ fn handle_spawn(
let ai = opt_ai.unwrap_or_else(|| "true".to_string()); let ai = opt_ai.unwrap_or_else(|| "true".to_string());
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => { Some(pos) => {
let agent = let agent =
if let comp::Alignment::Owned(_) | comp::Alignment::Npc = alignment { if let comp::Alignment::Owned(_) | comp::Alignment::Npc = alignment {
@ -667,7 +667,7 @@ fn handle_spawn_training_dummy(
_args: String, _args: String,
_action: &ChatCommand, _action: &ChatCommand,
) { ) {
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => { Some(pos) => {
let vel = Vec3::new( let vel = Vec3::new(
rand::thread_rng().gen_range(-2.0, 3.0), rand::thread_rng().gen_range(-2.0, 3.0),
@ -708,7 +708,7 @@ fn handle_spawn_campfire(
_args: String, _args: String,
_action: &ChatCommand, _action: &ChatCommand,
) { ) {
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => { Some(pos) => {
server server
.state .state
@ -1067,7 +1067,7 @@ fn handle_explosion(
let ecs = server.state.ecs(); let ecs = server.state.ecs();
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => { Some(pos) => {
ecs.read_resource::<EventBus<ServerEvent>>() ecs.read_resource::<EventBus<ServerEvent>>()
.emit_now(ServerEvent::Explosion { .emit_now(ServerEvent::Explosion {
@ -1092,7 +1092,7 @@ fn handle_waypoint(
_args: String, _args: String,
_action: &ChatCommand, _action: &ChatCommand,
) { ) {
match server.state.read_component_cloned::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => { Some(pos) => {
let time = server.state.ecs().read_resource(); let time = server.state.ecs().read_resource();
let _ = server let _ = server
@ -1128,7 +1128,7 @@ fn handle_adminify(
Some(player) => { Some(player) => {
let is_admin = if server let is_admin = if server
.state .state
.read_component_cloned::<comp::Admin>(player) .read_component_copied::<comp::Admin>(player)
.is_some() .is_some()
{ {
ecs.write_storage::<comp::Admin>().remove(player); ecs.write_storage::<comp::Admin>().remove(player);
@ -1672,7 +1672,7 @@ fn handle_remove_lights(
action: &ChatCommand, action: &ChatCommand,
) { ) {
let opt_radius = scan_fmt_some!(&args, &action.arg_fmt(), f32); let opt_radius = scan_fmt_some!(&args, &action.arg_fmt(), f32);
let opt_player_pos = server.state.read_component_cloned::<comp::Pos>(target); let opt_player_pos = server.state.read_component_copied::<comp::Pos>(target);
let mut to_delete = vec![]; let mut to_delete = vec![];
match opt_player_pos { match opt_player_pos {

View File

@ -386,7 +386,7 @@ pub fn handle_respawn(server: &Server, entity: EcsEntity) {
.is_some() .is_some()
{ {
let respawn_point = state let respawn_point = state
.read_component_cloned::<comp::Waypoint>(entity) .read_component_copied::<comp::Waypoint>(entity)
.map(|wp| wp.get_pos()) .map(|wp| wp.get_pos())
.unwrap_or(state.ecs().read_resource::<SpawnPoint>().0); .unwrap_or(state.ecs().read_resource::<SpawnPoint>().0);

View File

@ -169,10 +169,10 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
thrown_items.push(( thrown_items.push((
*pos, *pos,
state state
.read_component_cloned::<comp::Vel>(entity) .read_component_copied::<comp::Vel>(entity)
.unwrap_or_default(), .unwrap_or_default(),
state state
.read_component_cloned::<comp::Ori>(entity) .read_component_copied::<comp::Ori>(entity)
.unwrap_or_default(), .unwrap_or_default(),
*kind, *kind,
)); ));
@ -187,7 +187,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
state.read_storage::<comp::Pos>().get(entity) state.read_storage::<comp::Pos>().get(entity)
{ {
let uid = state let uid = state
.read_component_cloned(entity) .read_component_copied(entity)
.expect("Expected player to have a UID"); .expect("Expected player to have a UID");
if ( if (
&state.read_storage::<comp::Alignment>(), &state.read_storage::<comp::Alignment>(),
@ -344,7 +344,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
dropped_items.push(( dropped_items.push((
*pos, *pos,
state state
.read_component_cloned::<comp::Ori>(entity) .read_component_copied::<comp::Ori>(entity)
.unwrap_or_default(), .unwrap_or_default(),
item, item,
)); ));
@ -377,10 +377,10 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
for _ in 0..amount { for _ in 0..amount {
dropped_items.push(( dropped_items.push((
state state
.read_component_cloned::<comp::Pos>(entity) .read_component_copied::<comp::Pos>(entity)
.unwrap_or_default(), .unwrap_or_default(),
state state
.read_component_cloned::<comp::Ori>(entity) .read_component_copied::<comp::Ori>(entity)
.unwrap_or_default(), .unwrap_or_default(),
item.clone(), item.clone(),
)); ));
@ -422,7 +422,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
}, },
}; };
let uid = state.read_component_cloned::<Uid>(entity); let uid = state.read_component_copied::<Uid>(entity);
let mut new_entity = state let mut new_entity = state
.create_object(Default::default(), match kind { .create_object(Default::default(), match kind {

View File

@ -20,7 +20,7 @@ pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
// Note: If other `ServerEvent`s are referring to this entity they will be // Note: If other `ServerEvent`s are referring to this entity they will be
// disrupted // disrupted
let maybe_client = state.ecs().write_storage::<Client>().remove(entity); let maybe_client = state.ecs().write_storage::<Client>().remove(entity);
let maybe_uid = state.read_component_cloned::<Uid>(entity); let maybe_uid = state.read_component_copied::<Uid>(entity);
let maybe_player = state.ecs().write_storage::<comp::Player>().remove(entity); let maybe_player = state.ecs().write_storage::<comp::Player>().remove(entity);
let maybe_group = state let maybe_group = state
.ecs() .ecs()

View File

@ -1,6 +1,7 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn)] #![allow(clippy::option_map_unit_fn)]
#![feature(bool_to_option, drain_filter, option_zip)] #![feature(bool_to_option, drain_filter, option_zip)]
#![cfg_attr(not(feature = "worldgen"), feature(const_panic))]
pub mod alias_validator; pub mod alias_validator;
pub mod chunk_generator; pub mod chunk_generator;
@ -191,10 +192,12 @@ impl Server {
let (world, index) = World::generate(settings.world_seed); let (world, index) = World::generate(settings.world_seed);
#[cfg(not(feature = "worldgen"))] #[cfg(not(feature = "worldgen"))]
let map = WorldMapMsg { let map = WorldMapMsg {
dimensions: Vec2::new(1, 1), dimensions_lg: Vec2::zero(),
max_height: 1.0, max_height: 1.0,
rgba: vec![0], rgba: vec![0],
horizons: [(vec![0], vec![0]), (vec![0], vec![0])], horizons: [(vec![0], vec![0]), (vec![0], vec![0])],
sea_level: 0.0,
alt: vec![30],
}; };
#[cfg(feature = "worldgen")] #[cfg(feature = "worldgen")]

View File

@ -168,9 +168,12 @@ impl StateExt for State {
self.write_component(entity, comp::CharacterState::default()); self.write_component(entity, comp::CharacterState::default());
self.write_component( self.write_component(
entity, entity,
comp::Alignment::Owned(self.read_component_cloned(entity).unwrap()), comp::Alignment::Owned(self.read_component_copied(entity).unwrap()),
); );
// Make sure physics components are updated
self.write_component(entity, comp::ForceUpdate);
// Set the character id for the player // Set the character id for the player
// TODO this results in a warning in the console: "Error modifying synced // TODO this results in a warning in the console: "Error modifying synced
// component, it doesn't seem to exist" // component, it doesn't seem to exist"
@ -203,38 +206,31 @@ impl StateExt for State {
fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents) { fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents) {
let (body, stats, inventory, loadout) = components; let (body, stats, inventory, loadout) = components;
// Make sure physics are accepted.
self.write_component(entity, comp::ForceUpdate);
// Notify clients of a player list update if let Some(player_uid) = self.read_component_copied::<Uid>(entity) {
let client_uid = self // Notify clients of a player list update
.read_component_cloned::<Uid>(entity) self.notify_registered_clients(ServerMsg::PlayerListUpdate(
.expect("Client doesn't have a Uid!!!"); PlayerListUpdate::SelectedCharacter(player_uid, CharacterInfo {
name: String::from(&stats.name),
level: stats.level.level(),
}),
));
self.notify_registered_clients(ServerMsg::PlayerListUpdate( self.write_component(entity, comp::Collider::Box {
PlayerListUpdate::SelectedCharacter(client_uid, CharacterInfo { radius: body.radius(),
name: String::from(&stats.name), z_min: 0.0,
level: stats.level.level(), z_max: body.height(),
}), });
)); self.write_component(entity, body);
self.write_component(entity, stats);
self.write_component(entity, inventory);
self.write_component(entity, loadout);
self.write_component(entity, comp::Collider::Box { self.write_component(
radius: body.radius(), entity,
z_min: 0.0, comp::InventoryUpdate::new(comp::InventoryUpdateEvent::default()),
z_max: body.height(), );
}); }
self.write_component(entity, body);
self.write_component(entity, stats);
self.write_component(entity, inventory);
self.write_component(entity, loadout);
self.write_component(
entity,
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::default()),
);
// Make sure physics are accepted.
self.write_component(entity, comp::ForceUpdate);
} }
/// Send the chat message to the proper players. Say and region are limited /// Send the chat message to the proper players. Say and region are limited

View File

@ -515,7 +515,7 @@ impl<'a> Widget for Social<'a> {
}) })
.or_else(|| { .or_else(|| {
self.selected_entity self.selected_entity
.and_then(|s| self.client.state().read_component_cloned(s.0)) .and_then(|s| self.client.state().read_component_copied(s.0))
}) })
.filter(|selected| { .filter(|selected| {
// Prevent inviting entities already in the same group // Prevent inviting entities already in the same group

View File

@ -265,7 +265,7 @@ impl ParticleMgr {
let time = scene_data.state.get_time(); let time = scene_data.state.get_time();
let player_pos = scene_data let player_pos = scene_data
.state .state
.read_component_cloned::<Pos>(scene_data.player_entity) .read_component_copied::<Pos>(scene_data.player_entity)
.unwrap_or_default(); .unwrap_or_default();
let player_chunk = player_pos.0.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| { let player_chunk = player_pos.0.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| {
(e.floor() as i32).div_euclid(sz as i32) (e.floor() as i32).div_euclid(sz as i32)