Add AppError
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
This commit is contained in:
parent
f4694157ab
commit
df99ef3a3f
4 changed files with 47 additions and 22 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -65,7 +65,7 @@ dependencies = [
|
||||||
"ndk-context",
|
"ndk-context",
|
||||||
"ndk-sys",
|
"ndk-sys",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"thiserror",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -384,7 +384,7 @@ dependencies = [
|
||||||
"polling",
|
"polling",
|
||||||
"rustix",
|
"rustix",
|
||||||
"slab",
|
"slab",
|
||||||
"thiserror",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -863,7 +863,7 @@ dependencies = [
|
||||||
"combine",
|
"combine",
|
||||||
"jni-sys",
|
"jni-sys",
|
||||||
"log",
|
"log",
|
||||||
"thiserror",
|
"thiserror 1.0.69",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"windows-sys 0.45.0",
|
"windows-sys 0.45.0",
|
||||||
]
|
]
|
||||||
|
@ -975,7 +975,7 @@ dependencies = [
|
||||||
"ndk-sys",
|
"ndk-sys",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"thiserror",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1537,6 +1537,7 @@ dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"glam",
|
"glam",
|
||||||
"log",
|
"log",
|
||||||
|
"thiserror 2.0.12",
|
||||||
"vulkano",
|
"vulkano",
|
||||||
"vulkano-shaders",
|
"vulkano-shaders",
|
||||||
"winit",
|
"winit",
|
||||||
|
@ -1695,7 +1696,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
"rustix",
|
"rustix",
|
||||||
"thiserror",
|
"thiserror 1.0.69",
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
"wayland-client",
|
"wayland-client",
|
||||||
"wayland-csd-frame",
|
"wayland-csd-frame",
|
||||||
|
@ -1738,7 +1739,16 @@ version = "1.0.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl 2.0.12",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1752,6 +1762,17 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "1.1.8"
|
version = "1.1.8"
|
||||||
|
|
|
@ -7,6 +7,7 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
thiserror = "2.0"
|
||||||
winit = { version = "0.30", features = ["rwh_06"] }
|
winit = { version = "0.30", features = ["rwh_06"] }
|
||||||
|
|
||||||
vulkano = "0.35"
|
vulkano = "0.35"
|
||||||
|
|
|
@ -7,7 +7,15 @@ pub enum AppExit {
|
||||||
Error(Box<dyn Error>),
|
Error(Box<dyn Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type RunnerFn = Box<dyn FnOnce() -> AppExit>;
|
pub type RunnerFn = Box<dyn FnOnce(App) -> AppExit>;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum AppError {
|
||||||
|
#[error("Runner is not set")]
|
||||||
|
RunnerNotSet,
|
||||||
|
#[error("Runner returned an error : {0}")]
|
||||||
|
RunnerError(Box<dyn Error>),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
world: World,
|
world: World,
|
||||||
|
@ -35,16 +43,13 @@ impl App {
|
||||||
&self.world
|
&self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) -> Result<(), Box<dyn Error>> {
|
pub fn run(mut self) -> Result<(), AppError> {
|
||||||
match self.runner.take() {
|
match self.runner.take() {
|
||||||
Some(runner) => match runner() {
|
Some(runner) => match runner(self) {
|
||||||
AppExit::Success => Ok(()),
|
AppExit::Success => Ok(()),
|
||||||
AppExit::Error(e) => Err(e),
|
AppExit::Error(e) => Err(AppError::RunnerError(e)),
|
||||||
},
|
},
|
||||||
None => Err(Box::new(std::io::Error::new(
|
None => Err(AppError::RunnerNotSet),
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"runner is not set",
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -5,25 +5,23 @@ pub mod core;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
pub mod vulkan;
|
pub mod vulkan;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), impl Error> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
run_old_app()
|
run_new_app()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_new_app() -> Result<(), Box<dyn Error>> {
|
fn run_new_app() -> Result<(), impl Error> {
|
||||||
let mut app = core::app::App::default();
|
let app = core::app::App::default();
|
||||||
app.run()
|
app.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_old_app() -> Result<(), Box<dyn Error>> {
|
fn run_old_app() -> Result<(), impl Error> {
|
||||||
let event_loop = EventLoop::new().unwrap();
|
let event_loop = EventLoop::new().unwrap();
|
||||||
event_loop.set_control_flow(ControlFlow::Poll);
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
|
|
||||||
let vulkan_context = vulkan::vulkan_context::VulkanContext::from(&event_loop);
|
let vulkan_context = vulkan::vulkan_context::VulkanContext::from(&event_loop);
|
||||||
let mut app = core::old_app::App::from(vulkan_context);
|
let mut app = core::old_app::App::from(vulkan_context);
|
||||||
|
|
||||||
event_loop.run_app(&mut app).map_err(Box::new)?;
|
event_loop.run_app(&mut app)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue