From 68a7e54612656da45a3102cb592896989bde64df Mon Sep 17 00:00:00 2001 From: awtterpip Date: Sat, 16 Mar 2024 23:09:27 -0500 Subject: [PATCH] removed unnecessary mutex --- crates/bevy_openxr/src/init.rs | 1 - crates/bevy_openxr/src/render.rs | 4 ++-- crates/bevy_openxr/src/resources.rs | 19 +++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/bevy_openxr/src/init.rs b/crates/bevy_openxr/src/init.rs index d643ddb..e2b1ee8 100644 --- a/crates/bevy_openxr/src/init.rs +++ b/crates/bevy_openxr/src/init.rs @@ -431,7 +431,6 @@ pub fn create_xr_session( commands.insert_resource(images.clone()); commands.insert_resource(graphics_info.clone()); commands.insert_resource(stage.clone()); - commands.insert_resource(frame_stream.clone()); commands.insert_resource(XrRenderResources { session, frame_stream, diff --git a/crates/bevy_openxr/src/render.rs b/crates/bevy_openxr/src/render.rs index 2263bea..543f2d0 100644 --- a/crates/bevy_openxr/src/render.rs +++ b/crates/bevy_openxr/src/render.rs @@ -322,12 +322,12 @@ pub fn add_texture_view( handle } -pub fn begin_frame(frame_stream: ResMut) { +pub fn begin_frame(mut frame_stream: ResMut) { frame_stream.begin().expect("Failed to begin frame") } pub fn end_frame( - frame_stream: ResMut, + mut frame_stream: ResMut, mut swapchain: ResMut, stage: Res, display_time: Res, diff --git a/crates/bevy_openxr/src/resources.rs b/crates/bevy_openxr/src/resources.rs index 71efc3c..123f9b5 100644 --- a/crates/bevy_openxr/src/resources.rs +++ b/crates/bevy_openxr/src/resources.rs @@ -1,5 +1,5 @@ use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use crate::error::XrError; use crate::graphics::*; @@ -94,7 +94,7 @@ impl XrInstance { info.0; info => { let (session, frame_waiter, frame_stream) = self.0.create_session::(system_id, &info)?; - Ok((session.into(), XrFrameWaiter(frame_waiter), XrFrameStream(Api::wrap(Arc::new(Mutex::new(frame_stream)))))) + Ok((session.into(), XrFrameWaiter(frame_waiter), XrFrameStream(Api::wrap(frame_stream)))) } ) } @@ -139,31 +139,30 @@ impl XrSession { } } -#[derive(Resource, Clone)] +#[derive(Resource)] pub struct XrFrameStream(pub(crate) GraphicsWrap); impl GraphicsType for XrFrameStream { - type Inner = Arc>>; + type Inner = openxr::FrameStream; } impl XrFrameStream { - pub fn begin(&self) -> openxr::Result<()> { + pub fn begin(&mut self) -> openxr::Result<()> { graphics_match!( - &self.0; - stream => stream.lock().unwrap().begin() + &mut self.0; + stream => stream.begin() ) } pub fn end( - &self, + &mut self, display_time: openxr::Time, environment_blend_mode: openxr::EnvironmentBlendMode, layers: &[&dyn CompositionLayer], ) -> Result<()> { graphics_match!( - &self.0; + &mut self.0; stream => { - let mut stream = stream.lock().unwrap(); let mut new_layers = vec![]; for (i, layer) in layers.into_iter().enumerate() {