add new XrSpace and impl that

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-06-15 15:37:01 +02:00
parent aa2a335074
commit 6003cc7ac6
15 changed files with 860 additions and 52 deletions

View File

@@ -6,11 +6,14 @@ use crate::resources::{
OxrCleanupSession, OxrPassthrough, OxrPassthroughLayer, OxrSessionStarted, OxrSwapchain,
};
use crate::types::{Result, SwapchainCreateInfo};
use bevy::app::AppExit;
use bevy::ecs::event::ManualEventReader;
use bevy::ecs::system::RunSystemOnce;
use bevy::prelude::*;
use bevy::render::RenderApp;
use bevy_xr::session::{status_changed_to, XrSessionCreated, XrSessionExiting, XrStatus};
use bevy_xr::session::{
session_running, status_changed_to, XrSessionCreated, XrSessionExiting, XrStatus,
};
use openxr::AnyGraphics;
use crate::graphics::{graphics_match, GraphicsExt, GraphicsType, GraphicsWrap};
@@ -28,6 +31,12 @@ impl Plugin for OxrSessionPlugin {
app.init_non_send_resource::<OxrSessionCreateNextChain>();
app.add_event::<OxrSessionStatusEvent>();
app.add_systems(OxrLast, run_session_status_schedules.after(OxrHandleEvents));
app.add_systems(
OxrLast,
exits_session_on_app_exit
.before(OxrHandleEvents)
.run_if(on_event::<AppExit>().and_then(session_running)),
);
app.add_systems(XrSessionExiting, clean_session);
app.sub_app_mut(RenderApp)
.add_systems(XrSessionExiting, |mut cmds: Commands| {
@@ -39,6 +48,9 @@ impl Plugin for OxrSessionPlugin {
);
}
}
fn exits_session_on_app_exit(session: Res<OxrSession>) {
session.request_exit().unwrap()
}
fn handle_stopping_state(session: Res<OxrSession>, mut session_started: ResMut<OxrSessionStarted>) {
session.end().expect("Failed to end session");