Add CLI flags to open windows at startup
This commit is contained in:
parent
0c68cffc0e
commit
2e474df3e8
57
src/app.rs
57
src/app.rs
|
|
@ -16,6 +16,7 @@ use winit::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::CliArgs,
|
||||||
controller::ControllerManager,
|
controller::ControllerManager,
|
||||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||||
images::ImageProcessor,
|
images::ImageProcessor,
|
||||||
|
|
@ -55,6 +56,13 @@ pub struct Application {
|
||||||
focused: Option<ViewportId>,
|
focused: Option<ViewportId>,
|
||||||
init_debug_port: Option<u16>,
|
init_debug_port: Option<u16>,
|
||||||
init_profiling: bool,
|
init_profiling: bool,
|
||||||
|
init_bgmap: bool,
|
||||||
|
init_chardata: bool,
|
||||||
|
init_objects: bool,
|
||||||
|
init_worlds: bool,
|
||||||
|
init_framebuffers: bool,
|
||||||
|
init_registers: bool,
|
||||||
|
init_terminal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
|
|
@ -62,8 +70,7 @@ impl Application {
|
||||||
client: EmulatorClient,
|
client: EmulatorClient,
|
||||||
proxy: EventLoopProxy<UserEvent>,
|
proxy: EventLoopProxy<UserEvent>,
|
||||||
persistence: Persistence,
|
persistence: Persistence,
|
||||||
debug_port: Option<u16>,
|
args: CliArgs,
|
||||||
profiling: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let wgpu = WgpuState::new();
|
let wgpu = WgpuState::new();
|
||||||
let icon = load_icon().ok().map(Arc::new);
|
let icon = load_icon().ok().map(Arc::new);
|
||||||
|
|
@ -90,8 +97,15 @@ impl Application {
|
||||||
persistence,
|
persistence,
|
||||||
viewports: HashMap::new(),
|
viewports: HashMap::new(),
|
||||||
focused: None,
|
focused: None,
|
||||||
init_debug_port: debug_port,
|
init_debug_port: args.debug_port,
|
||||||
init_profiling: profiling,
|
init_profiling: args.profile,
|
||||||
|
init_bgmap: args.bgmap_data,
|
||||||
|
init_chardata: args.character_data,
|
||||||
|
init_objects: args.object_data,
|
||||||
|
init_worlds: args.worlds,
|
||||||
|
init_framebuffers: args.frame_buffers,
|
||||||
|
init_registers: args.registers,
|
||||||
|
init_terminal: args.terminal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,11 +138,40 @@ impl ApplicationHandler<UserEvent> for Application {
|
||||||
SimId::Player1,
|
SimId::Player1,
|
||||||
);
|
);
|
||||||
self.open(event_loop, Box::new(app));
|
self.open(event_loop, Box::new(app));
|
||||||
|
let sim_id = SimId::Player1;
|
||||||
if self.init_profiling {
|
if self.init_profiling {
|
||||||
let mut profiler = ProfileWindow::new(SimId::Player1, self.client.clone());
|
let mut profiler = ProfileWindow::new(sim_id, self.client.clone());
|
||||||
profiler.launch();
|
profiler.launch();
|
||||||
self.open(event_loop, Box::new(profiler));
|
self.open(event_loop, Box::new(profiler));
|
||||||
}
|
}
|
||||||
|
if self.init_chardata {
|
||||||
|
let chardata = CharacterDataWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
|
self.open(event_loop, Box::new(chardata));
|
||||||
|
}
|
||||||
|
if self.init_bgmap {
|
||||||
|
let bgmap = BgMapWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
|
self.open(event_loop, Box::new(bgmap));
|
||||||
|
}
|
||||||
|
if self.init_objects {
|
||||||
|
let objects = ObjectWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
|
self.open(event_loop, Box::new(objects));
|
||||||
|
}
|
||||||
|
if self.init_worlds {
|
||||||
|
let world = WorldWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
|
self.open(event_loop, Box::new(world));
|
||||||
|
}
|
||||||
|
if self.init_framebuffers {
|
||||||
|
let fb = FrameBufferWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
|
self.open(event_loop, Box::new(fb));
|
||||||
|
}
|
||||||
|
if self.init_registers {
|
||||||
|
let registers = RegisterWindow::new(sim_id, &self.memory);
|
||||||
|
self.open(event_loop, Box::new(registers));
|
||||||
|
}
|
||||||
|
if self.init_terminal {
|
||||||
|
let terminal = TerminalWindow::new(sim_id, &self.client);
|
||||||
|
self.open(event_loop, Box::new(terminal));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_event(
|
fn window_event(
|
||||||
|
|
@ -244,8 +287,8 @@ impl ApplicationHandler<UserEvent> for Application {
|
||||||
self.open(event_loop, Box::new(world));
|
self.open(event_loop, Box::new(world));
|
||||||
}
|
}
|
||||||
UserEvent::OpenFrameBuffers(sim_id) => {
|
UserEvent::OpenFrameBuffers(sim_id) => {
|
||||||
let world = FrameBufferWindow::new(sim_id, &self.memory, &mut self.images);
|
let fb = FrameBufferWindow::new(sim_id, &self.memory, &mut self.images);
|
||||||
self.open(event_loop, Box::new(world));
|
self.open(event_loop, Box::new(fb));
|
||||||
}
|
}
|
||||||
UserEvent::OpenRegisters(sim_id) => {
|
UserEvent::OpenRegisters(sim_id) => {
|
||||||
let registers = RegisterWindow::new(sim_id, &self.memory);
|
let registers = RegisterWindow::new(sim_id, &self.memory);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,43 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
use egui::{Color32, Vec2};
|
use egui::{Color32, Vec2};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{emulator::SimId, persistence::Persistence, window::DisplayMode};
|
use crate::{emulator::SimId, persistence::Persistence, window::DisplayMode};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
pub struct CliArgs {
|
||||||
|
/// The path to a virtual boy ROM to run.
|
||||||
|
pub rom: Option<PathBuf>,
|
||||||
|
/// Start a GDB/LLDB debug server on this port.
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub debug_port: Option<u16>,
|
||||||
|
/// Enable profiling a game
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub profile: bool,
|
||||||
|
/// Open character data window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub character_data: bool,
|
||||||
|
/// Open bgmap data window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub bgmap_data: bool,
|
||||||
|
/// Open object data window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub object_data: bool,
|
||||||
|
/// Open worlds window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub worlds: bool,
|
||||||
|
/// Open frame buffers window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub frame_buffers: bool,
|
||||||
|
/// Open registers window
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub registers: bool,
|
||||||
|
/// Open terminal
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub terminal: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub const COLOR_PRESETS: [[Color32; 2]; 3] = [
|
pub const COLOR_PRESETS: [[Color32; 2]; 3] = [
|
||||||
[
|
[
|
||||||
|
|
|
||||||
30
src/main.rs
30
src/main.rs
|
|
@ -1,7 +1,7 @@
|
||||||
// hide console in release mode
|
// hide console in release mode
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use std::{path::PathBuf, process, time::SystemTime};
|
use std::{process, time::SystemTime};
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use app::Application;
|
use app::Application;
|
||||||
|
|
@ -12,7 +12,11 @@ use tracing::error;
|
||||||
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
|
|
||||||
use crate::{config::SimConfig, emulator::SimId, persistence::Persistence};
|
use crate::{
|
||||||
|
config::{CliArgs, SimConfig},
|
||||||
|
emulator::SimId,
|
||||||
|
persistence::Persistence,
|
||||||
|
};
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod audio;
|
mod audio;
|
||||||
|
|
@ -28,18 +32,6 @@ mod persistence;
|
||||||
mod profiler;
|
mod profiler;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
struct Args {
|
|
||||||
/// The path to a virtual boy ROM to run.
|
|
||||||
rom: Option<PathBuf>,
|
|
||||||
/// Start a GDB/LLDB debug server on this port.
|
|
||||||
#[arg(short, long)]
|
|
||||||
debug_port: Option<u16>,
|
|
||||||
/// Enable profiling a game
|
|
||||||
#[arg(short, long)]
|
|
||||||
profile: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_logger() {
|
fn init_logger() {
|
||||||
let directives = std::env::var("RUST_LOG").unwrap_or("error,lemur=info".into());
|
let directives = std::env::var("RUST_LOG").unwrap_or("error,lemur=info".into());
|
||||||
let filter = EnvFilter::builder().parse_lossy(directives);
|
let filter = EnvFilter::builder().parse_lossy(directives);
|
||||||
|
|
@ -101,7 +93,7 @@ fn main() -> Result<()> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
set_process_priority_to_high()?;
|
set_process_priority_to_high()?;
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = CliArgs::parse();
|
||||||
|
|
||||||
let persistence = Persistence::new();
|
let persistence = Persistence::new();
|
||||||
|
|
||||||
|
|
@ -139,12 +131,6 @@ fn main() -> Result<()> {
|
||||||
let event_loop = EventLoop::with_user_event().build().unwrap();
|
let event_loop = EventLoop::with_user_event().build().unwrap();
|
||||||
event_loop.set_control_flow(ControlFlow::Poll);
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
let proxy = event_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
event_loop.run_app(&mut Application::new(
|
event_loop.run_app(&mut Application::new(client, proxy, persistence, args))?;
|
||||||
client,
|
|
||||||
proxy,
|
|
||||||
persistence,
|
|
||||||
args.debug_port,
|
|
||||||
args.profile,
|
|
||||||
))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue