use bevy::prelude::*;
use bevy::window::{CursorLeft, CursorMoved, WindowFocused, WindowResized};
use crate::NoesisLicense;
use crate::render::{NoesisRenderState, build_main_world_pipeline};
#[derive(Default)]
pub struct NoesisHeadlessPlugin {
pub license: Option<NoesisLicense>,
}
impl Plugin for NoesisHeadlessPlugin {
fn build(&self, app: &mut App) {
crate::NoesisPlugin {
license: self.license.clone(),
}
.init_runtime();
app.add_message::<CursorMoved>()
.add_message::<CursorLeft>()
.add_message::<WindowResized>()
.add_message::<WindowFocused>();
build_main_world_pipeline(app);
}
fn finish(&self, app: &mut App) {
let (device, queue) = bevy::tasks::block_on(request_device());
app.insert_non_send(NoesisRenderState::new(device, queue));
}
}
async fn request_device() -> (wgpu::Device, wgpu::Queue) {
let instance =
wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: None,
force_fallback_adapter: false,
})
.await
.expect("no wgpu adapter available for the headless Noesis test harness");
adapter
.request_device(&wgpu::DeviceDescriptor {
label: Some("noesis headless test device"),
required_features: wgpu::Features::empty(),
required_limits: adapter.limits(),
memory_hints: wgpu::MemoryHints::default(),
experimental_features: wgpu::ExperimentalFeatures::default(),
trace: wgpu::Trace::Off,
})
.await
.expect("no wgpu device available for the headless Noesis test harness")
}