mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Removed any unnecessary async from functions.
This commit is contained in:
parent
0512e94ede
commit
d710ce595d
@ -141,9 +141,8 @@ clippy.struct_field_names = "allow"
|
||||
# Performance of floats isn't paramount
|
||||
clippy.suboptimal_flops = "allow"
|
||||
|
||||
# Some functions might return an error / be async in the future
|
||||
# Some functions might return an error in the future
|
||||
clippy.unnecessary_wraps = "allow"
|
||||
clippy.unused_async = "allow"
|
||||
|
||||
# Due to working with windows and rendering, which use `u32` / `f32` liberally
|
||||
# and interchangeably, we can't do much aside from casting and accepting possible
|
||||
|
||||
@ -38,7 +38,7 @@ static SHARED: OnceCell<WgpuShared> = OnceCell::const_new();
|
||||
pub async fn get_or_create_shared() -> Result<&'static WgpuShared, AppError> {
|
||||
SHARED
|
||||
.get_or_try_init(async || {
|
||||
let instance = self::create_instance().await.context("Unable to create instance")?;
|
||||
let instance = self::create_instance().context("Unable to create instance")?;
|
||||
let adapter = self::create_adapter(&instance)
|
||||
.await
|
||||
.context("Unable to create adaptor")?;
|
||||
@ -80,7 +80,7 @@ async fn create_device(adapter: &wgpu::Adapter) -> Result<(wgpu::Device, wgpu::Q
|
||||
}
|
||||
|
||||
/// Creates the instance
|
||||
async fn create_instance() -> Result<wgpu::Instance, AppError> {
|
||||
fn create_instance() -> Result<wgpu::Instance, AppError> {
|
||||
let instance_desc = wgpu::InstanceDescriptor::from_env_or_default();
|
||||
tracing::debug!(?instance_desc, "Requesting wgpu instance");
|
||||
let instance = wgpu::Instance::new(&instance_desc);
|
||||
|
||||
@ -34,11 +34,11 @@ pub struct WgpuRenderer {
|
||||
}
|
||||
|
||||
impl WgpuRenderer {
|
||||
pub async fn new(window: Arc<Window>, shared: &WgpuShared) -> Result<Self, AppError> {
|
||||
pub fn new(window: Arc<Window>, shared: &WgpuShared) -> Result<Self, AppError> {
|
||||
// Create the surface
|
||||
// SAFETY: We keep an `Arc<Window>` that we only drop
|
||||
// *after* dropping the surface.
|
||||
let surface = unsafe { self::create_surface(shared, &window) }.await?;
|
||||
let surface = unsafe { self::create_surface(shared, &window) }?;
|
||||
|
||||
// Configure the surface and get the preferred texture format and surface size
|
||||
let surface_size = window.inner_size();
|
||||
@ -201,7 +201,7 @@ fn configure_window_surface(
|
||||
///
|
||||
/// # Safety
|
||||
/// The returned surface *must* be dropped before the window.
|
||||
async unsafe fn create_surface(shared: &WgpuShared, window: &Window) -> Result<wgpu::Surface<'static>, AppError> {
|
||||
unsafe fn create_surface(shared: &WgpuShared, window: &Window) -> Result<wgpu::Surface<'static>, AppError> {
|
||||
// Create the surface
|
||||
tracing::debug!(?window, "Requesting wgpu surface");
|
||||
// SAFETY: User ensures that the surface is dropped before the window.
|
||||
|
||||
@ -126,14 +126,14 @@ struct WinitApp {
|
||||
|
||||
impl winit::application::ApplicationHandler<AppEvent> for WinitApp {
|
||||
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||
if let Err(err) = self.init_window(event_loop).block_on() {
|
||||
if let Err(err) = self.init_window(event_loop) {
|
||||
tracing::warn!("Unable to initialize window: {}", err.pretty());
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
|
||||
fn suspended(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
|
||||
if let Err(err) = self.destroy_window().block_on() {
|
||||
if let Err(err) = self.destroy_window() {
|
||||
tracing::warn!("Unable to destroy window: {}", err.pretty());
|
||||
event_loop.exit();
|
||||
}
|
||||
@ -208,17 +208,15 @@ impl WinitApp {
|
||||
}
|
||||
|
||||
/// Initializes the window related things
|
||||
pub async fn init_window(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) -> Result<(), AppError> {
|
||||
pub fn init_window(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) -> Result<(), AppError> {
|
||||
let windows = window::create(event_loop).context("Unable to create winit event loop and window")?;
|
||||
for app_window in windows {
|
||||
let window = Arc::new(app_window.window);
|
||||
let wgpu_renderer = WgpuRenderer::new(Arc::clone(&window), self.shared.wgpu)
|
||||
.await
|
||||
.context("Unable to create wgpu renderer")?;
|
||||
let wgpu_renderer =
|
||||
WgpuRenderer::new(Arc::clone(&window), self.shared.wgpu).context("Unable to create wgpu renderer")?;
|
||||
|
||||
let panels_renderer = PanelsRenderer::new(&wgpu_renderer, self.shared.wgpu)
|
||||
.await
|
||||
.context("Unable to create panels renderer")?;
|
||||
let panels_renderer =
|
||||
PanelsRenderer::new(&wgpu_renderer, self.shared.wgpu).context("Unable to create panels renderer")?;
|
||||
let egui_event_handler = EguiEventHandler::new(&window);
|
||||
let egui_painter = EguiPainter::new(&egui_event_handler);
|
||||
let egui_renderer = EguiRenderer::new(&wgpu_renderer, self.shared.wgpu);
|
||||
@ -286,7 +284,7 @@ impl WinitApp {
|
||||
|
||||
/// Destroys the window related things
|
||||
#[expect(clippy::needless_pass_by_ref_mut, reason = "We'll use it in the future")]
|
||||
pub async fn destroy_window(&mut self) -> Result<(), AppError> {
|
||||
pub fn destroy_window(&mut self) -> Result<(), AppError> {
|
||||
// TODO: Handle destroying all tasks that use the window
|
||||
todo!();
|
||||
}
|
||||
@ -504,9 +502,7 @@ async fn egui_painter(
|
||||
let Some(panel_images) = panels_images.get_mut(&panel.name) else {
|
||||
continue;
|
||||
};
|
||||
panel
|
||||
.skip(panel_images, shared.wgpu, &shared.panels_renderer_layouts)
|
||||
.await;
|
||||
panel.skip(panel_images, shared.wgpu, &shared.panels_renderer_layouts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,9 +540,7 @@ async fn egui_painter(
|
||||
let Some(panel_images) = panels_images.get_mut(&panel.name) else {
|
||||
continue;
|
||||
};
|
||||
panel
|
||||
.step(panel_images, shared.wgpu, &shared.panels_renderer_layouts, time_delta)
|
||||
.await;
|
||||
panel.step(panel_images, shared.wgpu, &shared.panels_renderer_layouts, time_delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -66,25 +66,25 @@ impl Panel {
|
||||
/// Skips to the next image.
|
||||
///
|
||||
/// If the images aren't loaded, does nothing
|
||||
pub async fn skip(
|
||||
pub fn skip(
|
||||
&mut self,
|
||||
images: &mut PanelImages,
|
||||
wgpu_shared: &WgpuShared,
|
||||
renderer_layouts: &PanelsRendererLayouts,
|
||||
) {
|
||||
match images.step_next(wgpu_shared, renderer_layouts).await {
|
||||
match images.step_next(wgpu_shared, renderer_layouts) {
|
||||
Ok(()) => self.state.progress = self.state.duration.saturating_sub(self.state.fade_duration),
|
||||
Err(()) => self.state.progress = Self::max_duration(images, &self.state),
|
||||
}
|
||||
|
||||
// Then load any missing images
|
||||
images.load_missing(wgpu_shared, renderer_layouts).await;
|
||||
images.load_missing(wgpu_shared, renderer_layouts);
|
||||
}
|
||||
|
||||
/// Steps this panel's state by a certain number of frames (potentially negative).
|
||||
///
|
||||
/// If the images aren't loaded, does nothing
|
||||
pub async fn step(
|
||||
pub fn step(
|
||||
&mut self,
|
||||
images: &mut PanelImages,
|
||||
wgpu_shared: &WgpuShared,
|
||||
@ -101,13 +101,13 @@ impl Panel {
|
||||
// Update the progress, potentially rolling over to the previous/next image
|
||||
self.state.progress = match next_progress {
|
||||
Some(next_progress) => match next_progress >= self.state.duration {
|
||||
true => match images.step_next(wgpu_shared, renderer_layouts).await {
|
||||
true => match images.step_next(wgpu_shared, renderer_layouts) {
|
||||
Ok(()) => next_progress - self.state.duration,
|
||||
Err(()) => Self::max_duration(images, &self.state),
|
||||
},
|
||||
false => next_progress.clamp(Duration::ZERO, Self::max_duration(images, &self.state)),
|
||||
},
|
||||
None => match images.step_prev(wgpu_shared, renderer_layouts).await {
|
||||
None => match images.step_prev(wgpu_shared, renderer_layouts) {
|
||||
// Note: This branch is only taken when `delta` is negative, so we can always
|
||||
// subtract without checking `delta_is_positive`.
|
||||
Ok(()) => match (self.state.duration + self.state.progress).checked_sub(delta_abs) {
|
||||
@ -120,13 +120,13 @@ impl Panel {
|
||||
};
|
||||
|
||||
// Then load any missing images
|
||||
images.load_missing(wgpu_shared, renderer_layouts).await;
|
||||
images.load_missing(wgpu_shared, renderer_layouts);
|
||||
}
|
||||
|
||||
/// Updates this panel's state
|
||||
///
|
||||
/// If the images aren't loaded, does nothing
|
||||
pub async fn update(
|
||||
pub fn update(
|
||||
&mut self,
|
||||
images: &mut PanelImages,
|
||||
wgpu_shared: &WgpuShared,
|
||||
@ -135,14 +135,14 @@ impl Panel {
|
||||
delta: TimeDelta,
|
||||
) {
|
||||
// Then load any missing images
|
||||
images.load_missing(wgpu_shared, renderer_layouts).await;
|
||||
images.load_missing(wgpu_shared, renderer_layouts);
|
||||
|
||||
// If we're paused, don't update anything
|
||||
if self.state.paused {
|
||||
return;
|
||||
}
|
||||
|
||||
self.step(images, wgpu_shared, renderer_layouts, delta).await;
|
||||
self.step(images, wgpu_shared, renderer_layouts, delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -81,11 +81,7 @@ impl PanelImages {
|
||||
/// Steps to the previous image, if any
|
||||
///
|
||||
/// Returns `Err(())` if this would erase the current image.
|
||||
pub async fn step_prev(
|
||||
&mut self,
|
||||
wgpu_shared: &WgpuShared,
|
||||
renderer_layouts: &PanelsRendererLayouts,
|
||||
) -> Result<(), ()> {
|
||||
pub fn step_prev(&mut self, wgpu_shared: &WgpuShared, renderer_layouts: &PanelsRendererLayouts) -> Result<(), ()> {
|
||||
self.playlist_player.step_prev()?;
|
||||
mem::swap(&mut self.cur, &mut self.next);
|
||||
mem::swap(&mut self.prev, &mut self.cur);
|
||||
@ -97,11 +93,7 @@ impl PanelImages {
|
||||
/// Steps to the next image.
|
||||
///
|
||||
/// Returns `Err(())` if this would erase the current image.
|
||||
pub async fn step_next(
|
||||
&mut self,
|
||||
wgpu_shared: &WgpuShared,
|
||||
renderer_layouts: &PanelsRendererLayouts,
|
||||
) -> Result<(), ()> {
|
||||
pub fn step_next(&mut self, wgpu_shared: &WgpuShared, renderer_layouts: &PanelsRendererLayouts) -> Result<(), ()> {
|
||||
if !self.next.is_loaded() {
|
||||
return Err(());
|
||||
}
|
||||
@ -118,10 +110,10 @@ impl PanelImages {
|
||||
/// Loads any missing images, prioritizing the current, then next, then previous.
|
||||
///
|
||||
/// Requests images if missing any.
|
||||
pub async fn load_missing(&mut self, wgpu_shared: &WgpuShared, renderer_layouts: &PanelsRendererLayouts) {
|
||||
pub fn load_missing(&mut self, wgpu_shared: &WgpuShared, renderer_layouts: &PanelsRendererLayouts) {
|
||||
// Get the image receiver, or schedule it.
|
||||
let Some(image_receiver) = self.scheduled_image_receiver.as_mut() else {
|
||||
_ = self.schedule_load_image(wgpu_shared).await;
|
||||
_ = self.schedule_load_image(wgpu_shared);
|
||||
return;
|
||||
};
|
||||
|
||||
@ -155,7 +147,7 @@ impl PanelImages {
|
||||
);
|
||||
self.playlist_player.remove(&res.path);
|
||||
|
||||
_ = self.schedule_load_image(wgpu_shared).await;
|
||||
_ = self.schedule_load_image(wgpu_shared);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -193,7 +185,7 @@ impl PanelImages {
|
||||
///
|
||||
/// If the playlist player is empty, does not schedule.
|
||||
/// If already scheduled, returns
|
||||
async fn schedule_load_image(&mut self, wgpu_shared: &WgpuShared) -> Option<usize> {
|
||||
fn schedule_load_image(&mut self, wgpu_shared: &WgpuShared) -> Option<usize> {
|
||||
// If we already have an image scheduled, don't schedule another
|
||||
if self.scheduled_image_receiver.is_some() {
|
||||
return None;
|
||||
|
||||
@ -90,7 +90,7 @@ pub struct PanelsRenderer {
|
||||
|
||||
impl PanelsRenderer {
|
||||
/// Creates a new renderer for the panels
|
||||
pub async fn new(wgpu_renderer: &WgpuRenderer, wgpu_shared: &WgpuShared) -> Result<Self, AppError> {
|
||||
pub fn new(wgpu_renderer: &WgpuRenderer, wgpu_shared: &WgpuShared) -> Result<Self, AppError> {
|
||||
// Create the index / vertex buffer
|
||||
let indices = self::create_indices(wgpu_shared);
|
||||
let vertices = self::create_vertices(wgpu_shared);
|
||||
@ -192,7 +192,7 @@ impl PanelsRenderer {
|
||||
panel.state.last_update = now;
|
||||
let delta = TimeDelta::from_std(delta).expect("Frame duration did not fit into time delta");
|
||||
|
||||
panel.update(panel_images, wgpu_shared, layouts, delta).await;
|
||||
panel.update(panel_images, wgpu_shared, layouts, delta);
|
||||
}
|
||||
|
||||
// If the panel images are empty, there's no sense in rendering it either
|
||||
|
||||
@ -165,9 +165,7 @@ fn draw_panels_editor(ui: &mut egui::Ui, shared: &Shared, shared_window: &Shared
|
||||
|
||||
ui.label("Skip");
|
||||
if ui.button("🔄").clicked() {
|
||||
panel
|
||||
.skip(panel_images, shared.wgpu, &shared.panels_renderer_layouts)
|
||||
.block_on();
|
||||
panel.skip(panel_images, shared.wgpu, &shared.panels_renderer_layouts);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user