2019-08-19 12:39:23 +00:00
|
|
|
#![deny(unsafe_code)]
|
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
|
|
|
|
2021-07-30 05:01:17 +00:00
|
|
|
// Allow profiling allocations with Tracy
|
|
|
|
#[cfg_attr(feature = "tracy-memory", global_allocator)]
|
|
|
|
#[cfg(feature = "tracy-memory")]
|
|
|
|
static GLOBAL: common_base::tracy_client::ProfiledAllocator<std::alloc::System> =
|
|
|
|
common_base::tracy_client::ProfiledAllocator::new(std::alloc::System, 128);
|
|
|
|
|
2021-07-29 18:47:45 +00:00
|
|
|
use i18n::{self, LocalizationHandle};
|
2020-02-29 03:59:11 +00:00
|
|
|
use veloren_voxygen::{
|
2020-11-12 03:55:40 +00:00
|
|
|
audio::AudioFrontend,
|
2020-06-16 13:55:37 +00:00
|
|
|
profile::Profile,
|
2020-02-08 03:26:17 +00:00
|
|
|
run,
|
2021-04-10 14:53:34 +00:00
|
|
|
scene::terrain::SpriteRenderContext,
|
2021-01-23 08:34:38 +00:00
|
|
|
settings::{get_fps, 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
|
|
|
|
2021-09-30 06:09:30 +00:00
|
|
|
use chrono::Utc;
|
2021-06-27 18:34:32 +00:00
|
|
|
#[cfg(feature = "hot-reloading")]
|
|
|
|
use common::assets;
|
|
|
|
use common::clock::Clock;
|
2021-07-19 02:57:14 +00:00
|
|
|
use std::{panic, path::PathBuf};
|
2020-10-25 20:19:39 +00:00
|
|
|
use tracing::{error, info, warn};
|
2021-07-04 09:47:18 +00:00
|
|
|
#[cfg(feature = "egui-ui")]
|
|
|
|
use veloren_voxygen::ui::egui::EguiState;
|
2019-04-17 13:23:34 +00:00
|
|
|
|
2019-01-02 21:25:01 +00:00
|
|
|
fn main() {
|
2022-05-10 07:28:13 +00:00
|
|
|
#[cfg(feature = "tracy")]
|
|
|
|
common_base::tracy_client::Client::start();
|
|
|
|
|
2021-07-19 02:57:14 +00:00
|
|
|
let userdata_dir = common_base::userdata_dir_workspace!();
|
|
|
|
|
|
|
|
// Determine where Voxygen's logs should go
|
|
|
|
// Choose a path to store the logs by the following order:
|
|
|
|
// - The VOXYGEN_LOGS environment variable
|
|
|
|
// - The <userdata>/voxygen/logs
|
|
|
|
let logs_dir = std::env::var_os("VOXYGEN_LOGS")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.unwrap_or_else(|| userdata_dir.join("voxygen").join("logs"));
|
|
|
|
|
|
|
|
// Init logging and hold the guards.
|
2021-09-30 06:09:30 +00:00
|
|
|
let now = Utc::now();
|
|
|
|
let log_filename = format!("{}_voxygen.log", now.format("%Y-%m-%d"));
|
|
|
|
let _guards = common_frontend::init_stdout(Some((&logs_dir, &log_filename)));
|
2021-07-19 02:57:14 +00:00
|
|
|
|
2021-10-04 15:46:25 +00:00
|
|
|
// Re-run userdata selection so any warnings will be logged
|
|
|
|
common_base::userdata_dir_workspace!();
|
|
|
|
|
2021-07-19 02:57:14 +00:00
|
|
|
info!("Using userdata dir at: {}", userdata_dir.display());
|
|
|
|
|
|
|
|
// Determine Voxygen's config directory either by env var or placed in veloren's
|
|
|
|
// userdata folder
|
|
|
|
let config_dir = std::env::var_os("VOXYGEN_CONFIG")
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.and_then(|path| {
|
|
|
|
if path.exists() {
|
|
|
|
Some(path)
|
|
|
|
} else {
|
|
|
|
warn!(?path, "VOXYGEN_CONFIG points to invalid path.");
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| userdata_dir.join("voxygen"));
|
|
|
|
info!("Using config dir at: {}", config_dir.display());
|
|
|
|
|
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.
|
2021-07-19 02:57:14 +00:00
|
|
|
let mut settings = Settings::load(&config_dir);
|
2022-01-17 22:20:33 +00:00
|
|
|
settings.display_warnings();
|
2019-10-27 07:11:18 +00:00
|
|
|
// Save settings to add new fields or create the file if it is not already there
|
2021-07-19 02:57:14 +00:00
|
|
|
if let Err(err) = settings.save_to_file(&config_dir) {
|
2019-08-18 19:21:16 +00:00
|
|
|
panic!("Failed to save settings: {:?}", err);
|
|
|
|
}
|
2019-12-10 14:02:51 +00:00
|
|
|
|
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 {
|
2021-07-11 18:41:52 +00:00
|
|
|
Some(s) => s,
|
2019-05-09 17:27:07 +00:00
|
|
|
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 \
|
2022-01-11 19:42:05 +00:00
|
|
|
grateful if you could also post a message in the #support channel.
|
2019-05-17 07:55:51 +00:00
|
|
|
\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: {} [{}]",
|
2021-09-30 06:09:30 +00:00
|
|
|
logs_dir.join(&log_filename).display(),
|
2019-12-18 19:35:17 +00:00
|
|
|
reason,
|
|
|
|
panic_info,
|
2021-11-24 09:09:22 +00:00
|
|
|
*common::util::GIT_HASH,
|
|
|
|
*common::util::GIT_DATE
|
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
|
|
|
{
|
2021-02-07 05:48:57 +00:00
|
|
|
use native_dialog::{MessageDialog, MessageType};
|
2020-09-08 14:33:06 +00:00
|
|
|
|
|
|
|
let mbox = move || {
|
2021-02-07 05:48:57 +00:00
|
|
|
MessageDialog::new()
|
|
|
|
.set_title("Voxygen has panicked")
|
2020-09-08 14:33:06 +00:00
|
|
|
//somehow `<` and `>` are invalid characters and cause the msg to get replaced
|
|
|
|
// by some generic text thus i replace them
|
2021-02-07 05:48:57 +00:00
|
|
|
.set_text(&msg.replace('<', "[").replace('>', "]"))
|
|
|
|
.set_type(MessageType::Error)
|
|
|
|
.show_alert()
|
|
|
|
.unwrap()
|
2020-09-08 14:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On windows we need to spawn a thread as the msg doesn't work otherwise
|
|
|
|
#[cfg(target_os = "windows")]
|
2021-02-18 00:01:57 +00:00
|
|
|
{
|
|
|
|
let builder = std::thread::Builder::new().name("shutdown".into());
|
|
|
|
builder
|
|
|
|
.spawn(move || {
|
|
|
|
mbox();
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
.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
|
|
|
}));
|
|
|
|
|
2021-08-11 07:42:29 +00:00
|
|
|
// Setup tokio runtime
|
2021-08-10 13:55:58 +00:00
|
|
|
use common::consts::MIN_RECOMMENDED_TOKIO_THREADS;
|
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicUsize, Ordering},
|
|
|
|
Arc,
|
|
|
|
};
|
|
|
|
use tokio::runtime::Builder;
|
|
|
|
|
2021-08-11 07:42:29 +00:00
|
|
|
// TODO: evaluate std::thread::available_concurrency as a num_cpus replacement
|
2021-08-10 13:55:58 +00:00
|
|
|
let cores = num_cpus::get();
|
|
|
|
let tokio_runtime = Arc::new(
|
|
|
|
Builder::new_multi_thread()
|
|
|
|
.enable_all()
|
|
|
|
.worker_threads((cores / 4).max(MIN_RECOMMENDED_TOKIO_THREADS))
|
|
|
|
.thread_name_fn(|| {
|
|
|
|
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
|
|
|
|
format!("tokio-voxygen-{}", id)
|
|
|
|
})
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
|
2021-06-27 18:34:32 +00:00
|
|
|
#[cfg(feature = "hot-reloading")]
|
2020-12-12 22:14:24 +00:00
|
|
|
assets::start_hot_reloading();
|
|
|
|
|
2021-07-04 09:47:18 +00:00
|
|
|
// Initialise watcher for animation hot-reloading
|
2020-06-17 07:49:14 +00:00
|
|
|
#[cfg(feature = "hot-anim")]
|
2021-07-04 09:47:18 +00:00
|
|
|
{
|
|
|
|
anim::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise watcher for egui hot-reloading
|
|
|
|
#[cfg(feature = "hot-egui")]
|
|
|
|
{
|
|
|
|
voxygen_egui::init();
|
|
|
|
}
|
2020-06-17 07:49:14 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Setup audio
|
2020-11-19 18:46:31 +00:00
|
|
|
let mut audio = match settings.audio.output {
|
|
|
|
AudioOutput::Off => AudioFrontend::no_audio(),
|
2022-01-03 22:40:31 +00:00
|
|
|
AudioOutput::Automatic => AudioFrontend::new(settings.audio.num_sfx_channels),
|
2020-11-19 18:46:31 +00:00
|
|
|
// AudioOutput::Device(ref dev) => Some(dev.clone()),
|
|
|
|
};
|
2019-10-27 07:11:18 +00:00
|
|
|
|
2021-04-18 18:05:27 +00:00
|
|
|
audio.set_master_volume(settings.audio.master_volume);
|
2019-10-27 07:11:18 +00:00
|
|
|
audio.set_music_volume(settings.audio.music_volume);
|
|
|
|
audio.set_sfx_volume(settings.audio.sfx_volume);
|
|
|
|
|
|
|
|
// Load the profile.
|
2021-07-19 02:57:14 +00:00
|
|
|
let profile = Profile::load(&config_dir);
|
2019-10-27 07:11:18 +00:00
|
|
|
|
2021-05-07 11:24:37 +00:00
|
|
|
let mut i18n =
|
|
|
|
LocalizationHandle::load(&settings.language.selected_language).unwrap_or_else(|error| {
|
2020-12-13 01:09:57 +00:00
|
|
|
let selected_language = &settings.language.selected_language;
|
|
|
|
warn!(
|
|
|
|
?error,
|
|
|
|
?selected_language,
|
|
|
|
"Impossible to load language: change to the default language (English) instead.",
|
|
|
|
);
|
|
|
|
settings.language.selected_language = i18n::REFERENCE_LANG.to_owned();
|
2021-05-07 11:24:37 +00:00
|
|
|
LocalizationHandle::load_expect(&settings.language.selected_language)
|
2020-12-13 01:09:57 +00:00
|
|
|
});
|
2020-12-12 22:14:24 +00:00
|
|
|
i18n.read().log_missing_entries();
|
2021-04-24 14:39:35 +00:00
|
|
|
i18n.set_english_fallback(settings.language.use_english_fallback);
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Create window
|
2021-08-03 03:50:07 +00:00
|
|
|
use veloren_voxygen::{error::Error, render::RenderError};
|
2021-08-10 23:23:48 +00:00
|
|
|
let (mut window, event_loop) = match Window::new(&settings, &tokio_runtime) {
|
2021-08-03 03:50:07 +00:00
|
|
|
Ok(ok) => ok,
|
|
|
|
// Custom panic message when a graphics backend could not be found
|
|
|
|
Err(Error::RenderError(RenderError::CouldNotFindAdapter)) => {
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
const POTENTIAL_FIX: &str =
|
|
|
|
" Updating the graphics drivers on this system may resolve this issue.";
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
const POTENTIAL_FIX: &str = "";
|
|
|
|
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
|
|
|
const POTENTIAL_FIX: &str =
|
|
|
|
" Installing or updating vulkan drivers may resolve this issue.";
|
|
|
|
|
|
|
|
panic!(
|
|
|
|
"Failed to select a rendering backend! No compatible backends were found. We \
|
|
|
|
currently support vulkan, metal, dx12, and dx11.{} If the issue persists, please \
|
|
|
|
include the operating system and GPU details in your bug report to help us \
|
|
|
|
identify the cause.",
|
|
|
|
POTENTIAL_FIX
|
|
|
|
);
|
|
|
|
},
|
|
|
|
Err(error) => panic!("Failed to create window!: {:?}", error),
|
|
|
|
};
|
2019-10-27 07:11:18 +00:00
|
|
|
|
2021-06-15 08:01:57 +00:00
|
|
|
let clipboard = iced_winit::Clipboard::connect(window.window());
|
2020-12-02 00:35:32 +00:00
|
|
|
|
2021-04-10 14:53:34 +00:00
|
|
|
let lazy_init = SpriteRenderContext::new(window.renderer_mut());
|
|
|
|
|
2021-07-04 09:47:18 +00:00
|
|
|
#[cfg(feature = "egui-ui")]
|
|
|
|
let egui_state = EguiState::new(&window);
|
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
let global_state = GlobalState {
|
2021-07-19 02:57:14 +00:00
|
|
|
userdata_dir,
|
|
|
|
config_dir,
|
2019-10-27 07:11:18 +00:00
|
|
|
audio,
|
|
|
|
profile,
|
|
|
|
window,
|
2021-08-10 13:55:58 +00:00
|
|
|
tokio_runtime,
|
2021-07-04 09:47:18 +00:00
|
|
|
#[cfg(feature = "egui-ui")]
|
|
|
|
egui_state,
|
2021-04-10 14:53:34 +00:00
|
|
|
lazy_init,
|
2020-11-12 02:47:22 +00:00
|
|
|
clock: Clock::new(std::time::Duration::from_secs_f64(
|
2021-01-23 08:34:38 +00:00
|
|
|
1.0 / get_fps(settings.graphics.max_fps) as f64,
|
2020-11-12 02:47:22 +00:00
|
|
|
)),
|
2019-10-27 07:11:18 +00:00
|
|
|
settings,
|
|
|
|
info_message: None,
|
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
singleplayer: None,
|
2020-12-12 22:14:24 +00:00
|
|
|
i18n,
|
2020-12-02 00:35:32 +00:00
|
|
|
clipboard,
|
2020-12-30 14:50:17 +00:00
|
|
|
client_error: None,
|
2021-07-04 09:47:18 +00:00
|
|
|
clear_shadows_next_frame: false,
|
2019-10-27 07:11:18 +00:00
|
|
|
};
|
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
|
|
|
}
|