Minor cleanup
parent
a2c45ba5a2
commit
ca3f289de5
21
src/main.rs
21
src/main.rs
|
@ -24,28 +24,19 @@ fn main() -> Result<()> {
|
||||||
consts::STARFIELD_TEXTURE_NAME.to_owned(),
|
consts::STARFIELD_TEXTURE_NAME.to_owned(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
pollster::block_on(run(content))?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run(content: content::Content) -> Result<()> {
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
|
let mut gpu = pollster::block_on(render::GPUState::new(window, &content))?;
|
||||||
|
|
||||||
let mut gpu = render::GPUState::new(window, &content).await?;
|
|
||||||
let mut game = game::Game::new(content);
|
let mut game = game::Game::new(content);
|
||||||
|
|
||||||
gpu.update_starfield_buffer(&game);
|
gpu.update_starfield_buffer(&game);
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
match event {
|
match event {
|
||||||
Event::RedrawRequested(window_id) if window_id == gpu.window().id() => {
|
Event::RedrawRequested(window_id) if window_id == gpu.window().id() => {
|
||||||
game.update();
|
|
||||||
match gpu.render(&game) {
|
match gpu.render(&game) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
// Reconfigure the surface if lost
|
|
||||||
Err(wgpu::SurfaceError::Lost) => gpu.resize(&game, gpu.window_size),
|
Err(wgpu::SurfaceError::Lost) => gpu.resize(&game, gpu.window_size),
|
||||||
// The system is out of memory, we should probably quit
|
|
||||||
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
|
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
|
||||||
// All other errors (Outdated, Timeout) should be resolved by the next frame
|
// All other errors (Outdated, Timeout) should be resolved by the next frame
|
||||||
Err(e) => eprintln!("{:?}", e),
|
Err(e) => eprintln!("{:?}", e),
|
||||||
|
@ -53,16 +44,14 @@ async fn run(content: content::Content) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
// RedrawRequested will only trigger once unless we manually
|
game.update();
|
||||||
// request it.
|
|
||||||
gpu.window().request_redraw();
|
gpu.window().request_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
ref event,
|
ref event,
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == gpu.window.id() => {
|
} if window_id == gpu.window.id() => match event {
|
||||||
match event {
|
|
||||||
WindowEvent::Focused(state) => {
|
WindowEvent::Focused(state) => {
|
||||||
game.set_paused(!state);
|
game.set_paused(!state);
|
||||||
}
|
}
|
||||||
|
@ -86,12 +75,10 @@ async fn run(content: content::Content) -> Result<()> {
|
||||||
gpu.resize(&game, *physical_size);
|
gpu.resize(&game, *physical_size);
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
||||||
// new_inner_size is &&mut so we have to dereference it twice
|
|
||||||
gpu.resize(&game, **new_inner_size);
|
gpu.resize(&game, **new_inner_size);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue