A multiplayer VR framework w/voice chat
1use std::{env, net::ToSocketAddrs}; 2 3use bevy::{app::{App, FixedUpdate, Startup, Update}, ecs::system::Commands, prelude::*, render::pipelined_rendering::PipelinedRenderingPlugin}; 4use bevy_mod_openxr::{add_xr_plugins, resources::OxrSessionConfig}; 5use bevy_mod_xr::session::{XrSessionCreated, XrSessionPlugin}; 6use felix_audio::{FelixAudio, voice}; 7use openxr::EnvironmentBlendMode; 8 9use crate::{components::{debug_camera, network_interface, remote_player}, setup::setup}; 10 11mod components; 12mod setup; 13mod net; 14 15fn main() { 16 if let Err(err) = dotenvy::dotenv(){ println!("[WARN] .ENV failed loading {:#?}", err); } 17 18 App::new() 19 .add_plugins(( 20 add_xr_plugins( 21 DefaultPlugins 22 .build() 23 .disable::<PipelinedRenderingPlugin>(), 24 ).set(XrSessionPlugin { auto_handle: true }), 25 FelixAudio 26 )) 27 .insert_resource(OxrSessionConfig { 28 blend_mode_preference: vec![ 29 EnvironmentBlendMode::ALPHA_BLEND, 30 EnvironmentBlendMode::ADDITIVE, 31 EnvironmentBlendMode::OPAQUE 32 ], 33 ..Default::default() 34 }) 35 .add_systems(XrSessionCreated, || { println!("[INFO] Started VR") }) 36 .add_systems(Startup, setup) 37 .add_systems(Startup, move | mut commands: Commands |{ 38 let addr = env::var("HOST").unwrap().to_socket_addrs().unwrap().nth(0).unwrap(); 39 40 let ( comp, voice ) = net::handle_net(addr.clone()).expect("Network Module Failed"); 41 commands.spawn(comp); 42 43 match voice::init_microphone(addr, voice){ 44 Ok(voice) => { commands.spawn(voice); }, 45 Err(err) => println!("[WARN] Failed to start microphone: {}", err) 46 } 47 }) 48 .add_systems(Update, debug_camera::update) 49 .add_systems(Startup, debug_camera::setup) 50 .add_systems(Update, remote_player::update) 51 .add_systems(FixedUpdate, network_interface::fixed_update) 52 .run(); 53}