From 28e00a0f6eb96c1512d293c42921b4f0f779bfb4 Mon Sep 17 00:00:00 2001 From: Imbris <imbrisf@gmail.com> Date: Sat, 7 Mar 2020 17:16:00 -0500 Subject: [PATCH] Fix singleplayer feature and rebase related stuff --- voxygen/src/hud/mod.rs | 38 ++++++++++++++++++-------------------- voxygen/src/lib.rs | 20 +++++++++++++++++++- voxygen/src/main.rs | 2 +- voxygen/src/session.rs | 8 ++------ 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 7a4c2a75f6..d776b04d84 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -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) }, diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index 058d61c901..202b7b55d3 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -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 diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 6cc09a3406..1820be77fd 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -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; diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 456ce050a1..bac1dbdf7a 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -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,