gui/cli/frontend: anyhow

This commit is contained in:
Alex Janka 2024-06-16 11:43:59 +10:00
parent 0c5324176d
commit ac4446b055
8 changed files with 33 additions and 28 deletions

15
Cargo.lock generated
View file

@ -190,6 +190,9 @@ name = "anyhow"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
dependencies = [
"backtrace",
]
[[package]]
name = "anymap"
@ -778,6 +781,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
name = "cli"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"ctrlc",
"env_logger",
@ -1583,6 +1587,7 @@ dependencies = [
name = "frontend-common"
version = "0.5.1"
dependencies = [
"anyhow",
"bytemuck",
"chrono",
"cpal",
@ -2208,6 +2213,7 @@ dependencies = [
name = "gui"
version = "0.1.0"
dependencies = [
"anyhow",
"cacao",
"cpal",
"env_logger",
@ -2638,7 +2644,6 @@ dependencies = [
[[package]]
name = "librashader"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"ash 0.37.3+1.3.251",
"halfbrown",
@ -2657,7 +2662,6 @@ dependencies = [
[[package]]
name = "librashader-cache"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"bincode",
"blake3",
@ -2673,7 +2677,6 @@ dependencies = [
[[package]]
name = "librashader-common"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"ash 0.37.3+1.3.251",
"halfbrown",
@ -2685,7 +2688,6 @@ dependencies = [
[[package]]
name = "librashader-preprocess"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"encoding_rs",
"librashader-common",
@ -2696,7 +2698,6 @@ dependencies = [
[[package]]
name = "librashader-presets"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"librashader-common",
"nom",
@ -2712,7 +2713,6 @@ dependencies = [
[[package]]
name = "librashader-reflect"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -2734,7 +2734,6 @@ dependencies = [
[[package]]
name = "librashader-runtime"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"array-concat",
"bytemuck",
@ -2750,7 +2749,6 @@ dependencies = [
[[package]]
name = "librashader-runtime-vk"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"array-concat",
"ash 0.37.3+1.3.251",
@ -2770,7 +2768,6 @@ dependencies = [
[[package]]
name = "librashader-runtime-wgpu"
version = "0.2.7"
source = "git+https://git.alexjanka.com/alex/librashader#30bb747e94e7ab11ea5aecf388f4b693ac836434"
dependencies = [
"array-concat",
"bytemuck",

View file

@ -14,3 +14,4 @@ clap = { version = "4.4", features = ["derive"] }
ctrlc = "3.4"
log = { workspace = true }
env_logger = { workspace = true }
anyhow = { version = "1.0.86", features = ["backtrace"] }

View file

@ -121,7 +121,7 @@ impl From<Args> for frontend_common::RunOptions {
}
}
fn main() {
fn main() -> anyhow::Result<()> {
env_logger::init();
let args = Args::parse();
@ -170,7 +170,7 @@ fn main() {
let prepared = frontend_common::prepare(args.into(), receiver);
let (output, stream) = audio::create_output(mute);
let mut window_manager = ActiveWindowManager::new(sender, stream, record);
let mut core = frontend_common::run(prepared, &mut window_manager, output);
let mut core = frontend_common::run(prepared, &mut window_manager, output)?;
if debug {
let mut debugger = Debugger::new(Box::new(core));
let mut since = Instant::now();
@ -190,6 +190,7 @@ fn main() {
window_manager.run_events_blocking().unwrap();
}
}
Ok(())
}
const UPDATE_INTERVAL: Duration = Duration::from_millis(1);

View file

@ -29,3 +29,4 @@ image = { version = "0.24", default-features = false, features = ["png"] }
bytemuck = "1.14"
chrono = "0.4"
log = { workspace = true }
anyhow = "1.0.86"

View file

@ -167,7 +167,7 @@ pub fn run<W>(
prepared: PreparedEmulator,
window_manager: &mut W,
output: AudioOutput,
) -> EmulatorCore<[u8; 4]>
) -> anyhow::Result<EmulatorCore<[u8; 4]>>
where
W: WindowManager,
{
@ -178,16 +178,16 @@ where
prepared.scale_override,
prepared.shader_path,
prepared.resizable,
);
)?;
let tile_window = if prepared.tile_window {
Some(new_tile_window(window_manager))
Some(new_tile_window(window_manager)?)
} else {
None
};
let layer_window = if prepared.layer_window {
Some(new_layer_window(window_manager))
Some(new_layer_window(window_manager)?)
} else {
None
};
@ -224,7 +224,7 @@ where
EmulatorCore::init(true, prepared.receiver, emulator_options)
}
pub fn new_tile_window<W>(window_manager: &mut W) -> RendererChannel
pub fn new_tile_window<W>(window_manager: &mut W) -> anyhow::Result<RendererChannel>
where
W: WindowManager,
{
@ -236,7 +236,7 @@ where
)
}
pub fn new_layer_window<W>(window_manager: &mut W) -> RendererChannel
pub fn new_layer_window<W>(window_manager: &mut W) -> anyhow::Result<RendererChannel>
where
W: WindowManager,
{

View file

@ -21,5 +21,5 @@ pub trait WindowManager {
factor: usize,
shader_path: Option<PathBuf>,
resizable: bool,
) -> RendererChannel;
) -> anyhow::Result<RendererChannel>;
}

View file

@ -56,6 +56,7 @@ where
impl<Backend> WinitWindowManager<Backend>
where
Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{
pub fn new(
sender: Sender<EmulatorMessage<[u8; 4]>>,
@ -97,6 +98,7 @@ where
impl<Backend> WindowManager for WinitWindowManager<Backend>
where
Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{
fn add(
&mut self,
@ -104,7 +106,7 @@ where
factor: usize,
shader_path: Option<PathBuf>,
resizable: bool,
) -> RendererChannel {
) -> anyhow::Result<RendererChannel> {
let is_main = window_type == WindowType::Main;
self.data.add(
@ -121,6 +123,7 @@ where
impl<Backend> WinitWindowManagerData<Backend>
where
Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{
fn add(
&mut self,
@ -130,7 +133,7 @@ where
event_loop: &EventLoop<()>,
is_main: bool,
record: bool,
) -> RendererChannel {
) -> anyhow::Result<RendererChannel> {
let (r, sender) = WindowRenderer::new(
factor,
event_loop,
@ -138,13 +141,13 @@ where
shader_path,
resizable,
record,
);
)?;
let id = r.window.id();
self.windows.insert(id, r);
if is_main {
self.main_window = Some(id);
}
sender
Ok(sender)
}
fn handler(&mut self, run_return: bool, event: Event<()>, target: &EventLoopWindowTarget<()>) {
@ -320,6 +323,7 @@ impl QueuedBuf {
impl<Backend> WindowRenderer<Backend>
where
Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{
#[allow(unused_variables)]
fn new(
@ -329,12 +333,11 @@ where
shader_path: Option<PathBuf>,
resizable: bool,
record: bool,
) -> (Self, RendererChannel) {
) -> anyhow::Result<(Self, RendererChannel)> {
let window = WindowBuilder::new()
.with_title("Gameboy")
.with_resizable(resizable)
.build(event_loop)
.unwrap();
.build(event_loop)?;
let real_factor = (window.scale_factor() * factor as f64) as u32;
let inner_size = window.inner_size();
@ -344,8 +347,9 @@ where
scaled_width: inner_size.width / real_factor,
scaled_height: inner_size.height / real_factor,
};
let renderer = RendererBackend::new(resolutions, &window, shader_path, manager);
let renderer = RendererBackend::new(resolutions, &window, shader_path, manager).unwrap();
let renderer = renderer?;
let recording = if record {
let configs = access_config();
@ -365,7 +369,7 @@ where
let (sender, receiver) = mpsc::channel();
(
Ok((
Self {
receiver,
renderer,
@ -377,7 +381,7 @@ where
recording,
},
sender,
)
))
}
fn render(&mut self, manager: &Backend::RendererBackendManager) {

View file

@ -31,6 +31,7 @@ log = { workspace = true }
env_logger = { workspace = true }
thiserror = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0.86"
[target.'cfg(any(target_os = "macos"))'.dependencies]
cacao = { git = "https://git.alexjanka.com/alex/cacao", optional = true }