Fix singleplayer feature and rebase related stuff

This commit is contained in:
Imbris 2020-03-07 17:16:00 -05:00
parent 7dfb24d4a5
commit 28e00a0f6e
4 changed files with 40 additions and 28 deletions

View File

@ -465,17 +465,18 @@ impl Show {
self.want_grab = true;
// Unpause the game if we are on singleplayer
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
global_state.unpause();
} else {
self.esc_menu = true;
self.want_grab = false;
// Pause the game if we are on singleplayer
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(true);
};
#[cfg(feature = "singleplayer")]
{
// Pause the game if we are on singleplayer
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(true);
}
}
}
}
@ -1720,10 +1721,13 @@ impl Hud {
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
settings_window::Event::ChangeTab(tab) => self.show.open_setting_tab(tab),
settings_window::Event::Close => {
// Unpause the game if we are on singleplayer so that we can logout
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
#[cfg(feature = "singleplayer")]
{
// Unpause the game if we are on singleplayer so that we can logout
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
}
self.show.settings(false)
},
@ -1908,24 +1912,18 @@ impl Hud {
self.force_ungrab = false;
// Unpause the game if we are on singleplayer
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
global_state.unpause();
},
Some(esc_menu::Event::Logout) => {
// Unpause the game if we are on singleplayer so that we can logout
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
global_state.unpause();
events.push(Event::Logout);
},
Some(esc_menu::Event::Quit) => events.push(Event::Quit),
Some(esc_menu::Event::CharacterSelection) => {
// Unpause the game if we are on singleplayer so that we can logout
if let Some(singleplayer) = global_state.singleplayer.as_ref() {
singleplayer.pause(false);
};
global_state.unpause();
events.push(Event::CharacterSelection)
},

View File

@ -28,12 +28,13 @@ pub mod window;
// Reexports
pub use crate::error::Error;
#[cfg(feature = "singleplayer")]
use crate::singleplayer::Singleplayer;
use crate::{
audio::AudioFrontend,
profile::Profile,
render::Renderer,
settings::Settings,
singleplayer::Singleplayer,
window::{Event, Window},
};
use common::{assets::watch, clock::Clock};
@ -61,6 +62,23 @@ impl GlobalState {
}
pub fn maintain(&mut self, dt: f32) { self.audio.maintain(dt); }
#[cfg(feature = "singleplayer")]
pub fn paused(&self) -> bool {
self.singleplayer
.as_ref()
.map_or(false, Singleplayer::is_paused)
}
#[cfg(not(feature = "singleplayer"))]
pub fn paused(&self) -> bool { false }
pub fn unpause(&self) {
#[cfg(feature = "singleplayer")]
{
self.singleplayer.as_ref().map(|s| s.pause(false));
}
}
}
// TODO: appears to be currently unused by playstates

View File

@ -15,7 +15,7 @@ use veloren_voxygen::{
};
use common::{
assets::{load, load_expect, load_watched, watch},
assets::{load_watched, watch},
clock::Clock,
};
use std::panic;

View File

@ -636,9 +636,7 @@ impl PlayState for SessionState {
self.inputs.climb = self.key_state.climb();
// Runs if either in a multiplayer server or the singleplayer server is unpaused
if global_state.singleplayer.is_none()
|| !global_state.singleplayer.as_ref().unwrap().is_paused()
{
if !global_state.paused() {
// Perform an in-game tick.
match self.tick(global_state.clock.get_avg_delta(), global_state) {
Ok(TickAction::Continue) => {}, // Do nothing
@ -986,9 +984,7 @@ impl PlayState for SessionState {
};
// Runs if either in a multiplayer server or the singleplayer server is unpaused
if global_state.singleplayer.is_none()
|| !global_state.singleplayer.as_ref().unwrap().is_paused()
{
if !global_state.paused() {
self.scene.maintain(
global_state.window.renderer_mut(),
&mut global_state.audio,