use alloc::boxed::Box;
use concinnity_core::Driver;
use concinnity_core::ecs::HEADLESS_SYSTEMS;
use crate::world::Inner;
#[cfg(feature = "std")]
pub(crate) fn select(world: Inner) -> Box<dyn Driver> {
adopt(concinnity_engine::App::from_world(world))
}
#[cfg(not(feature = "std"))]
pub(crate) fn select(world: Inner) -> Box<dyn Driver> {
headless(world)
}
#[cfg(feature = "std")]
pub(crate) fn adopt(app: concinnity_engine::App) -> Box<dyn Driver> {
if concinnity_engine::HAS_RENDER_BACKEND {
Box::new(app)
} else {
headless(app.into_world())
}
}
pub(crate) fn headless(world: Inner) -> Box<dyn Driver> {
Box::new(concinnity_core::App::with_systems(world, HEADLESS_SYSTEMS))
}
#[cfg(test)]
mod tests {
use crate::components::{GraphicsConfig, TextLabel};
use crate::{App, World};
#[test]
fn a_headless_run_returns_in_process() {
let mut world = World::new();
world.add_component(TextLabel {
content: "Hello, world!".into(),
..Default::default()
});
assert_eq!(App::from_world(world).into_headless().run(), Ok(()));
}
#[test]
fn a_world_that_would_render_runs_headless_as_well() {
let mut world = World::new();
world.add_component(GraphicsConfig::default());
assert_eq!(App::from_world(world).into_headless().run(), Ok(()));
}
#[cfg(not(any(
feature = "native",
feature = "metal",
feature = "directx",
feature = "vulkan"
)))]
#[test]
fn the_default_loop_is_headless_with_no_backend_compiled_in() {
let mut world = World::new();
world.add_component(GraphicsConfig::default());
assert_eq!(App::from_world(world).run(), Ok(()));
}
}