add some command line switches for the gpu window

This commit is contained in:
2022-07-23 22:34:59 +02:00
parent 465e66ff4b
commit 760664eb77
12 changed files with 195 additions and 62 deletions

View File

@@ -7,9 +7,9 @@ mod gpu;
pub struct Window(Box<dyn WindowImpl>);
impl Window {
pub fn new(gpu: bool) -> Result<Window> {
if gpu {
match gpu::Window::new() {
pub fn new(config: WindowConfig) -> Result<Window> {
if config.enable_gpu {
match gpu::Window::new(config) {
Ok(window) => return Ok(Window(Box::new(window))),
Err(err) => eprintln!(
"Failed to create gpu window: {}\nFalling back tp cpu window",
@@ -32,6 +32,43 @@ impl Window {
}
}
#[derive(Debug)]
pub struct WindowConfig {
enable_gpu: bool,
filter: u32,
fullscreen: bool,
}
impl Default for WindowConfig {
fn default() -> WindowConfig {
WindowConfig {
enable_gpu: true,
filter: 5,
fullscreen: false,
}
}
}
impl WindowConfig {
pub fn parse_arguments(&mut self, args: &mut pico_args::Arguments) {
self.enable_gpu = !args.contains("--no-gpu");
if let Some(filter) = args.opt_value_from_str::<_, String>("--filter").unwrap() {
self.filter = match filter.as_str() {
"1" | "nearest" => 1,
"2" | "fast_crt" => 2,
"3" | "ss_crt" => 3,
"4" | "chromatic" => 4,
"5" | "auto_crt" => 5,
o => {
println!("Unknown --filter '{}'", o);
std::process::exit(1);
}
}
}
self.fullscreen = args.contains("--fullscreen");
}
}
pub struct Input {
pub gamepads: [u8; 4],
pub reset: bool,