2019-08-19 12:39:23 +00:00
|
|
|
#![deny(unsafe_code)]
|
2020-06-14 16:48:07 +00:00
|
|
|
#![allow(clippy::option_map_unit_fn)]
|
2020-03-31 17:02:26 +00:00
|
|
|
#![feature(bool_to_option)]
|
2019-04-29 20:37:19 +00:00
|
|
|
#![recursion_limit = "2048"]
|
2019-01-23 20:01:58 +00:00
|
|
|
|
2020-02-29 03:59:11 +00:00
|
|
|
use veloren_voxygen::{
|
|
|
|
audio::{self, AudioFrontend},
|
|
|
|
i18n::{self, i18n_asset_key, VoxygenLocalization},
|
|
|
|
logging,
|
2020-06-16 13:55:37 +00:00
|
|
|
profile::Profile,
|
2020-02-08 03:26:17 +00:00
|
|
|
run,
|
2020-03-31 18:12:49 +00:00
|
|
|
settings::{AudioOutput, Settings},
|
2020-01-17 23:43:18 +00:00
|
|
|
window::Window,
|
2020-02-08 03:26:17 +00:00
|
|
|
GlobalState,
|
2020-01-20 13:37:29 +00:00
|
|
|
};
|
2020-02-29 03:59:11 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
use common::{
|
2020-08-28 01:02:17 +00:00
|
|
|
assets::{watch, Asset},
|
2019-10-27 07:11:18 +00:00
|
|
|
clock::Clock,
|
|
|
|
};
|
2020-02-08 03:26:17 +00:00
|
|
|
use std::panic;
|
2020-10-25 20:19:39 +00:00
|
|
|
use tracing::{error, info, warn};
|
2019-04-17 13:23:34 +00:00
|
|
|
|
2019-01-02 21:25:01 +00:00
|
|
|
fn main() {
|
2019-08-18 19:21:16 +00:00
|
|
|
// Load the settings
|
2020-02-01 20:39:39 +00:00
|
|
|
// Note: This won't log anything due to it being called before
|
2020-06-21 10:22:26 +00:00
|
|
|
// `logging::init`. The issue is we need to read a setting to decide
|
2020-02-01 20:39:39 +00:00
|
|
|
// whether we create a log file or not.
|
2019-10-27 07:11:18 +00:00
|
|
|
let mut settings = Settings::load();
|
|
|
|
// Save settings to add new fields or create the file if it is not already there
|
2019-08-18 19:21:16 +00:00
|
|
|
if let Err(err) = settings.save_to_file() {
|
|
|
|
panic!("Failed to save settings: {:?}", err);
|
|
|
|
}
|
2019-12-10 14:02:51 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Init logging and hold the guards.
|
|
|
|
let _guards = logging::init(&settings);
|
2020-01-17 23:43:18 +00:00
|
|
|
|
2020-10-25 20:19:39 +00:00
|
|
|
if let Some(path) = veloren_voxygen::settings::voxygen_data_dir().parent() {
|
|
|
|
info!("Using userdata dir at: {}", path.display());
|
|
|
|
} else {
|
|
|
|
error!("Can't log userdata dir, voxygen data dir has no parent!");
|
|
|
|
}
|
|
|
|
|
2019-05-11 20:39:46 +00:00
|
|
|
// Set up panic handler to relay swish panic messages to the user
|
2019-05-05 18:42:44 +00:00
|
|
|
let default_hook = panic::take_hook();
|
2019-04-25 11:49:36 +00:00
|
|
|
panic::set_hook(Box::new(move |panic_info| {
|
2019-05-08 20:01:02 +00:00
|
|
|
let panic_info_payload = panic_info.payload();
|
|
|
|
let payload_string = panic_info_payload.downcast_ref::<String>();
|
|
|
|
let reason = match payload_string {
|
2019-05-09 17:27:07 +00:00
|
|
|
Some(s) => &s,
|
|
|
|
None => {
|
|
|
|
let payload_str = panic_info_payload.downcast_ref::<&str>();
|
|
|
|
match payload_str {
|
|
|
|
Some(st) => st,
|
|
|
|
None => "Payload is not a string",
|
2019-05-08 20:01:02 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-05-08 20:01:02 +00:00
|
|
|
};
|
2019-05-17 07:55:51 +00:00
|
|
|
let msg = format!(
|
2019-05-31 03:01:52 +00:00
|
|
|
"A critical error has occurred and Voxygen has been forced to \
|
2019-05-17 07:55:51 +00:00
|
|
|
terminate in an unusual manner. Details about the error can be \
|
|
|
|
found below.\n\
|
|
|
|
\n\
|
|
|
|
> What should I do?\n\
|
|
|
|
\n\
|
|
|
|
We need your help to fix this! You can help by contacting us and \
|
|
|
|
reporting this problem. To do this, open an issue on the Veloren \
|
|
|
|
issue tracker:\n\
|
|
|
|
\n\
|
|
|
|
https://www.gitlab.com/veloren/veloren/issues/new\n\
|
|
|
|
\n\
|
|
|
|
If you're on the Veloren community Discord server, we'd be \
|
|
|
|
grateful if you could also post a message in the #support channel.
|
|
|
|
\n\
|
|
|
|
> What should I include?\n\
|
|
|
|
\n\
|
|
|
|
The error information below will be useful in finding and fixing \
|
|
|
|
the problem. Please include as much information about your setup \
|
|
|
|
and the events that led up to the panic as possible.
|
|
|
|
\n\
|
|
|
|
Voxygen has logged information about the problem (including this \
|
2020-03-20 08:47:00 +00:00
|
|
|
message) to the file {}. Please include the contents of this \
|
2019-05-17 07:55:51 +00:00
|
|
|
file in your bug report.
|
|
|
|
\n\
|
|
|
|
> Error information\n\
|
|
|
|
\n\
|
|
|
|
The information below is intended for developers and testers.\n\
|
|
|
|
\n\
|
|
|
|
Panic Payload: {:?}\n\
|
2020-03-20 08:47:00 +00:00
|
|
|
PanicInfo: {}\n\
|
|
|
|
Game version: {} [{}]",
|
2020-03-22 22:06:05 +00:00
|
|
|
Settings::load()
|
|
|
|
.log
|
|
|
|
.logs_path
|
2019-12-18 19:35:17 +00:00
|
|
|
.join("voxygen-<date>.log")
|
|
|
|
.display(),
|
|
|
|
reason,
|
|
|
|
panic_info,
|
2020-03-20 08:47:00 +00:00
|
|
|
common::util::GIT_HASH.to_string(),
|
|
|
|
common::util::GIT_DATE.to_string()
|
2019-05-17 07:55:51 +00:00
|
|
|
);
|
2019-04-25 11:49:36 +00:00
|
|
|
|
2019-06-06 14:48:41 +00:00
|
|
|
error!(
|
2019-05-14 07:41:27 +00:00
|
|
|
"VOXYGEN HAS PANICKED\n\n{}\n\nBacktrace:\n{:?}",
|
|
|
|
msg,
|
2019-05-17 07:55:51 +00:00
|
|
|
backtrace::Backtrace::new(),
|
2019-05-14 07:41:27 +00:00
|
|
|
);
|
2019-04-25 11:49:36 +00:00
|
|
|
|
2020-09-08 14:33:06 +00:00
|
|
|
#[cfg(feature = "native-dialog")]
|
2020-01-07 05:45:43 +00:00
|
|
|
{
|
2020-09-08 14:33:06 +00:00
|
|
|
use native_dialog::{Dialog, MessageAlert, MessageType};
|
|
|
|
|
|
|
|
let mbox = move || {
|
|
|
|
MessageAlert {
|
|
|
|
title: "Voxygen has panicked",
|
|
|
|
//somehow `<` and `>` are invalid characters and cause the msg to get replaced
|
|
|
|
// by some generic text thus i replace them
|
|
|
|
text: &msg.replace('<', "[").replace('>', "]"),
|
|
|
|
typ: MessageType::Error,
|
|
|
|
}
|
|
|
|
.show()
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
// On windows we need to spawn a thread as the msg doesn't work otherwise
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
mbox();
|
|
|
|
})
|
2020-09-11 14:24:15 +00:00
|
|
|
.join()
|
|
|
|
.unwrap();
|
2020-09-08 14:33:06 +00:00
|
|
|
|
2020-09-09 10:11:56 +00:00
|
|
|
#[cfg(not(target_os = "windows"))]
|
2020-09-08 14:33:06 +00:00
|
|
|
mbox();
|
2020-01-07 05:45:43 +00:00
|
|
|
}
|
2019-05-05 18:42:44 +00:00
|
|
|
|
|
|
|
default_hook(panic_info);
|
2019-04-25 11:49:36 +00:00
|
|
|
}));
|
|
|
|
|
2020-06-17 07:49:14 +00:00
|
|
|
// Initialise watcher for animation hotreloading
|
|
|
|
#[cfg(feature = "hot-anim")]
|
|
|
|
anim::init();
|
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Setup audio
|
|
|
|
let mut audio = match settings.audio.output {
|
|
|
|
AudioOutput::Off => None,
|
|
|
|
AudioOutput::Automatic => audio::get_default_device(),
|
|
|
|
AudioOutput::Device(ref dev) => Some(dev.clone()),
|
|
|
|
}
|
|
|
|
.map(|dev| AudioFrontend::new(dev, settings.audio.max_sfx_channels))
|
|
|
|
.unwrap_or_else(AudioFrontend::no_audio);
|
|
|
|
|
|
|
|
audio.set_music_volume(settings.audio.music_volume);
|
|
|
|
audio.set_sfx_volume(settings.audio.sfx_volume);
|
|
|
|
|
|
|
|
// Load the profile.
|
|
|
|
let profile = Profile::load();
|
|
|
|
|
|
|
|
let mut localization_watcher = watch::ReloadIndicator::new();
|
2020-08-28 01:02:17 +00:00
|
|
|
let localized_strings = VoxygenLocalization::load_watched(
|
2019-10-27 07:11:18 +00:00
|
|
|
&i18n_asset_key(&settings.language.selected_language),
|
|
|
|
&mut localization_watcher,
|
|
|
|
)
|
|
|
|
.unwrap_or_else(|error| {
|
2020-02-08 03:26:17 +00:00
|
|
|
let selected_language = &settings.language.selected_language;
|
2019-10-27 07:11:18 +00:00
|
|
|
warn!(
|
2020-02-08 03:26:17 +00:00
|
|
|
?error,
|
|
|
|
?selected_language,
|
2019-10-27 07:11:18 +00:00
|
|
|
"Impossible to load language: change to the default language (English) instead.",
|
|
|
|
);
|
|
|
|
settings.language.selected_language = i18n::REFERENCE_LANG.to_owned();
|
2020-08-28 01:02:17 +00:00
|
|
|
VoxygenLocalization::load_watched(
|
2019-10-27 07:11:18 +00:00
|
|
|
&i18n_asset_key(&settings.language.selected_language),
|
|
|
|
&mut localization_watcher,
|
|
|
|
)
|
|
|
|
.unwrap()
|
2020-06-21 21:47:49 +00:00
|
|
|
});
|
2019-10-27 07:11:18 +00:00
|
|
|
localized_strings.log_missing_entries();
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Create window
|
|
|
|
let (window, event_loop) = Window::new(&settings).expect("Failed to create window!");
|
|
|
|
|
|
|
|
let global_state = GlobalState {
|
|
|
|
audio,
|
|
|
|
profile,
|
|
|
|
window,
|
|
|
|
settings,
|
2020-11-10 12:30:01 +00:00
|
|
|
clock: Clock::new(std::time::Duration::from_millis(30)),
|
2019-10-27 07:11:18 +00:00
|
|
|
info_message: None,
|
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
singleplayer: None,
|
|
|
|
localization_watcher,
|
|
|
|
};
|
2019-06-19 19:25:08 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
run::run(global_state, event_loop);
|
2019-01-02 21:25:01 +00:00
|
|
|
}
|