Merge branch 'master' of gitlab.com:veloren/veloren into sharp/small-fixes

This commit is contained in:
Joshua Yanovski 2020-08-19 05:15:56 +02:00
commit 5b1625f99d
3 changed files with 41 additions and 12 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
### Changed ### Changed
- Fixed a bug where leaving the Settings menu by pressing "N" in single player kept the game paused
### Removed ### Removed

View File

@ -10,7 +10,7 @@ use common::{
}; };
use futures_executor::block_on; use futures_executor::block_on;
use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt};
use tracing::{debug, error, trace}; use tracing::{debug, error, trace, warn};
pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) { pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
let state = server.state_mut(); let state = server.state_mut();
@ -80,13 +80,31 @@ pub fn handle_exit_ingame(server: &mut Server, entity: EcsEntity) {
pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event { pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event {
if let Some(client) = server.state().read_storage::<Client>().get(entity) { if let Some(client) = server.state().read_storage::<Client>().get(entity) {
trace!("Closing participant of client"); trace!("Closing participant of client");
let participant = client.participant.lock().unwrap().take().unwrap(); let participant = match client.participant.try_lock() {
if let Err(e) = block_on(participant.disconnect()) { Ok(mut p) => p.take().unwrap(),
debug!( Err(e) => {
?e, error!(?e, "coudln't lock participant for removal");
"Error when disconnecting client, maybe the pipe already broke" return Event::ClientDisconnected { entity };
); },
}; };
std::thread::spawn(|| {
let pid = participant.remote_pid();
let now = std::time::Instant::now();
trace!(?pid, "start disconnect");
if let Err(e) = block_on(participant.disconnect()) {
debug!(
?e,
"Error when disconnecting client, maybe the pipe already broke"
);
};
trace!(?pid, "finished disconnect");
let elapsed = now.elapsed();
if elapsed.as_millis() > 100 {
warn!(?elapsed, "disconecting took quite long");
} else {
debug!(?elapsed, "disconecting took");
}
});
} }
let state = server.state_mut(); let state = server.state_mut();

View File

@ -462,10 +462,20 @@ impl Show {
} }
} }
fn toggle_settings(&mut self) { fn toggle_settings(&mut self, global_state: &GlobalState) {
match self.open_windows { match self.open_windows {
Windows::Settings => self.settings(false), Windows::Settings => {
_ => self.settings(true), #[cfg(feature = "singleplayer")]
global_state.unpause();
self.settings(false);
},
_ => {
#[cfg(feature = "singleplayer")]
global_state.pause();
self.settings(true)
},
}; };
} }
@ -1635,7 +1645,7 @@ impl Hud {
.set(self.ids.buttons, ui_widgets) .set(self.ids.buttons, ui_widgets)
{ {
Some(buttons::Event::ToggleBag) => self.show.toggle_bag(), Some(buttons::Event::ToggleBag) => self.show.toggle_bag(),
Some(buttons::Event::ToggleSettings) => self.show.toggle_settings(), Some(buttons::Event::ToggleSettings) => self.show.toggle_settings(global_state),
Some(buttons::Event::ToggleSocial) => self.show.toggle_social(), Some(buttons::Event::ToggleSocial) => self.show.toggle_social(),
Some(buttons::Event::ToggleSpell) => self.show.toggle_spell(), Some(buttons::Event::ToggleSpell) => self.show.toggle_spell(),
Some(buttons::Event::ToggleMap) => self.show.toggle_map(), Some(buttons::Event::ToggleMap) => self.show.toggle_map(),
@ -2311,7 +2321,7 @@ impl Hud {
true true
}, },
GameInput::Settings if state => { GameInput::Settings if state => {
self.show.toggle_settings(); self.show.toggle_settings(global_state);
true true
}, },
GameInput::Help if state => { GameInput::Help if state => {