Skip to content

Commit

Permalink
Fallback to flat when no oxr runtime is found (#51)
Browse files Browse the repository at this point in the history
* basics done? now to the fun part: changing the ENTIRE lib to work with xr and non xr

* updated stuff and renamed file

* actually add the renamed file into git lol :3

* made lib fallback to flat when no runtime is found but can't compile with default settings under those circumstances
  • Loading branch information
Schmarni-Dev authored Dec 9, 2023
1 parent d9ebd5b commit 28008f7
Show file tree
Hide file tree
Showing 15 changed files with 547 additions and 783 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = ["examples/android", "examples/demo"]
anyhow = "1.0.75"
ash = "0.37.3"
bevy = "0.12"
futures-lite = "2.1.0"
mint = "0.5.9"
wgpu = "0.17.1"
wgpu-core = { version = "0.17.1", features = ["vulkan"] }
Expand Down
1 change: 1 addition & 0 deletions examples/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ color-eyre = "0.6.2"

[target.'cfg(not(target_os="android"))'.dependencies.bevy_oxr]
path = "../../"
# May need to be more specific. needs to be false at least on linux without an active runtime to run in flat
default-features = true
24 changes: 0 additions & 24 deletions examples/demo/Cargo_back.toml

This file was deleted.

31 changes: 24 additions & 7 deletions examples/demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{f32::consts::PI, ops::Mul, time::Duration};
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
ecs::schedule::ScheduleLabel,
input::{keyboard::KeyCode, Input},
log::info,
prelude::{
bevy_main, default, shape, App, Assets, Color, Commands, Component, Entity, Event,
Expand All @@ -16,10 +17,12 @@ use bevy::{
};
use bevy_oxr::{
input::XrInput,
xr_init::{XrEnableRequest, XrEnableStatus, xr_only},
resources::{XrFrameState, XrInstance, XrSession},
xr_input::{
actions::XrActionSets,
debug_gizmos::OpenXrDebugRenderer,
hands::common::{ HandInputDebugRenderer, HandResource, HandsResource, OpenXrHandInput},
hands::common::{HandInputDebugRenderer, HandResource, HandsResource, OpenXrHandInput},
hands::HandBone,
interactions::{
draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions,
Expand All @@ -29,11 +32,25 @@ use bevy_oxr::{
oculus_touch::OculusController,
prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig},
trackers::{OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker},
Hand, actions::XrActionSets,
Hand,
},
DefaultXrPlugins,
};

fn input_stuff(
keys: Res<Input<KeyCode>>,
status: Res<XrEnableStatus>,
mut request: EventWriter<XrEnableRequest>,
) {
if keys.just_pressed(KeyCode::Space) {
match status.into_inner() {
XrEnableStatus::Enabled => request.send(XrEnableRequest::TryDisable),
XrEnableStatus::Disabled => request.send(XrEnableRequest::TryEnable),
XrEnableStatus::Waiting => (),
}
}
}

mod setup;
use crate::setup::setup_scene;
use bevy_rapier3d::prelude::*;
Expand All @@ -45,7 +62,7 @@ pub fn main() {
info!("Running bevy_openxr demo");
let mut app = App::new();

app
app.add_systems(Update, input_stuff)
//lets get the usual diagnostic stuff added
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
Expand All @@ -60,11 +77,11 @@ pub fn main() {
.add_systems(Startup, setup_scene)
.add_systems(Startup, spawn_controllers_example) //you need to spawn controllers or it crashes TODO:: Fix this
//add locomotion
.add_systems(Update, proto_locomotion)
.add_systems(Update, proto_locomotion.run_if(xr_only()))
.insert_resource(PrototypeLocomotionConfig::default())
//lets add the interaction systems
.add_event::<InteractionEvent>()
.add_systems(Update, prototype_interaction_input)
.add_systems(Update, prototype_interaction_input.run_if(xr_only()))
.add_systems(Update, interactions.before(update_interactable_states))
.add_systems(Update, update_interactable_states)
.add_systems(
Expand All @@ -76,7 +93,7 @@ pub fn main() {
//draw the interaction gizmos
.add_systems(
Update,
draw_interaction_gizmos.after(update_interactable_states),
draw_interaction_gizmos.run_if(xr_only()).after(update_interactable_states),
)
.add_systems(Update, draw_socket_gizmos.after(update_interactable_states))
//add our cube spawning system
Expand All @@ -85,7 +102,7 @@ pub fn main() {
0.25,
bevy::time::TimerMode::Once,
)))
.add_systems(Update, request_cube_spawn)
.add_systems(Update, request_cube_spawn.run_if(xr_only()))
.add_systems(Update, cube_spawner.after(request_cube_spawn))
//test capsule
.add_systems(Startup, spawn_capsule)
Expand Down
Loading

0 comments on commit 28008f7

Please sign in to comment.