use clap::Parser;
#[derive(Parser)]
#[command(name = "dreamwell-runtime")]
struct Args {
#[arg(long)]
pack_file: Option<String>,
#[arg(long)]
lock_file: Option<String>,
#[arg(long, default_value = "default")]
scene_name: String,
#[arg(long)]
host: Option<String>,
#[arg(long, default_value = "dreamwell")]
db_name: String,
#[arg(long, default_value = "Dreamwell")]
title: String,
#[arg(long, default_value_t = 1920)]
width: u32,
#[arg(long, default_value_t = 1080)]
height: u32,
}
const MAIN_STACK_SIZE: usize = 8 * 1024 * 1024;
fn main() {
let builder = std::thread::Builder::new()
.name("dreamwell-main".into())
.stack_size(MAIN_STACK_SIZE);
let handler = builder.spawn(run).expect("failed to spawn main thread");
if let Err(e) = handler.join() {
eprintln!("runtime thread panicked: {e:?}");
std::process::exit(1);
}
}
fn run() {
env_logger::init();
std::panic::set_hook(Box::new(|info| {
let msg = format!("{info}");
eprintln!("PANIC: {msg}");
let _ = std::fs::write("dreamwell-runtime.panic.log", &msg);
}));
let args = Args::parse();
log::info!("Dreamwell Runtime starting");
let authority_mode = if args.host.is_some() {
dreamwell_runtime::AuthorityMode::Remote
} else {
dreamwell_runtime::AuthorityMode::Local
};
let config = dreamwell_runtime::RuntimeConfig {
title: args.title,
width: args.width,
height: args.height,
authority_mode,
pack_file: args.pack_file,
lock_file: args.lock_file,
db_host: args.host,
db_name: args.db_name,
..Default::default()
};
let runtime = match dreamwell_runtime::Runtime::new(config) {
Ok(r) => r,
Err(e) => {
log::error!("Failed to create runtime: {e}");
std::process::exit(1);
}
};
if let Err(e) = runtime.run() {
log::error!("Runtime exited with error: {e}");
std::process::exit(1);
}
}