Add CLI flags to open windows at startup

This commit is contained in:
Simon Gellis 2025-11-23 13:58:46 -05:00
parent 0c68cffc0e
commit 2e474df3e8
3 changed files with 93 additions and 29 deletions

View File

@ -16,6 +16,7 @@ use winit::{
};
use crate::{
config::CliArgs,
controller::ControllerManager,
emulator::{EmulatorClient, EmulatorCommand, SimId},
images::ImageProcessor,
@ -55,6 +56,13 @@ pub struct Application {
focused: Option<ViewportId>,
init_debug_port: Option<u16>,
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 {
@ -62,8 +70,7 @@ impl Application {
client: EmulatorClient,
proxy: EventLoopProxy<UserEvent>,
persistence: Persistence,
debug_port: Option<u16>,
profiling: bool,
args: CliArgs,
) -> Self {
let wgpu = WgpuState::new();
let icon = load_icon().ok().map(Arc::new);
@ -90,8 +97,15 @@ impl Application {
persistence,
viewports: HashMap::new(),
focused: None,
init_debug_port: debug_port,
init_profiling: profiling,
init_debug_port: args.debug_port,
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,
);
self.open(event_loop, Box::new(app));
let sim_id = SimId::Player1;
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();
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(
@ -244,8 +287,8 @@ impl ApplicationHandler<UserEvent> for Application {
self.open(event_loop, Box::new(world));
}
UserEvent::OpenFrameBuffers(sim_id) => {
let world = FrameBufferWindow::new(sim_id, &self.memory, &mut self.images);
self.open(event_loop, Box::new(world));
let fb = FrameBufferWindow::new(sim_id, &self.memory, &mut self.images);
self.open(event_loop, Box::new(fb));
}
UserEvent::OpenRegisters(sim_id) => {
let registers = RegisterWindow::new(sim_id, &self.memory);

View File

@ -1,8 +1,43 @@
use anyhow::Result;
use clap::Parser;
use egui::{Color32, Vec2};
use serde::{Deserialize, Serialize};
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] = [
[

View File

@ -1,7 +1,7 @@
// hide console in release mode
#![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 app::Application;
@ -12,7 +12,11 @@ use tracing::error;
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
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 audio;
@ -28,18 +32,6 @@ mod persistence;
mod profiler;
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() {
let directives = std::env::var("RUST_LOG").unwrap_or("error,lemur=info".into());
let filter = EnvFilter::builder().parse_lossy(directives);
@ -101,7 +93,7 @@ fn main() -> Result<()> {
#[cfg(windows)]
set_process_priority_to_high()?;
let args = Args::parse();
let args = CliArgs::parse();
let persistence = Persistence::new();
@ -139,12 +131,6 @@ fn main() -> Result<()> {
let event_loop = EventLoop::with_user_event().build().unwrap();
event_loop.set_control_flow(ControlFlow::Poll);
let proxy = event_loop.create_proxy();
event_loop.run_app(&mut Application::new(
client,
proxy,
persistence,
args.debug_port,
args.profile,
))?;
event_loop.run_app(&mut Application::new(client, proxy, persistence, args))?;
Ok(())
}