#![doc(html_logo_url = "https://raw.githubusercontent.com/lowenware/dotrix/master/logo.png")]
#![warn(missing_docs)]
mod application;
mod color;
mod cubemap;
mod frame;
mod globals;
mod id;
mod pipeline;
mod pose;
mod world;
pub mod animation;
pub mod assets;
pub mod camera;
pub mod ecs;
pub mod input;
pub mod ray;
pub mod renderer;
pub mod transform;
pub mod window;
pub use animation::Animator;
pub use application::{ Application, IntoService, Service };
pub use assets::Assets;
pub use camera::Camera;
pub use color::Color;
pub use cubemap::CubeMap;
pub use frame::Frame;
pub use globals::Globals;
pub use id::Id;
pub use pipeline::Pipeline;
pub use pose::Pose;
pub use transform::Transform;
pub use ecs::{ System, Priority, RunLevel };
pub use input::Input;
pub use ray::Ray;
pub use renderer::Renderer;
pub use window::{ Window, Monitor, VideoMode };
pub use world::World;
#[deprecated(since="0.5.0", note="Please use components from dotrix crate instead")]
pub mod components {
pub use crate::{
animation::Animator,
color::Color,
pose::Pose,
transform::Transform,
};
}
#[deprecated(since="0.5.0", note="Please use services from dotrix crate instead")]
pub mod services {
pub use crate::{
assets::Assets,
camera::Camera,
globals::Globals,
input::Input,
frame::Frame,
ray::Ray,
renderer::Renderer,
window::Window,
world::World,
};
}
pub struct Dotrix {
app: Option<Application>,
}
#[derive(Default)]
pub struct Display {
pub clear_color: [f64; 4],
pub fullscreen: bool,
}
impl Dotrix {
pub fn application(name: &'static str) -> Self {
let mut app = Application::new(name);
app.add_service(assets::Assets::default());
app.add_service(camera::Camera::default());
app.add_service(frame::Frame::default());
app.add_service(input::Input::default());
app.add_service(globals::Globals::default());
app.add_service(renderer::Renderer::default());
app.add_service(window::Window::default());
app.add_service(world::World::default());
app.add_system(System::from(renderer::startup));
app.add_system(System::from(camera::startup));
app.add_system(System::from(renderer::resize));
app.add_system(System::from(camera::resize));
app.add_system(System::from(renderer::bind));
app.add_system(System::from(frame::bind));
app.add_system(System::from(camera::bind));
app.add_system(System::from(animation::skeletal));
app.add_system(System::from(renderer::release));
app.add_system(System::from(input::release));
Self {
app: Some(app),
}
}
pub fn bare(name: &'static str) -> Self {
Self {
app: Some(Application::new(name)),
}
}
pub fn with<T>(&mut self, engine_unit: T) -> &mut Self
where Self: ExtendWith<T>
{
self.extend_with(engine_unit);
self
}
pub fn with_system(&mut self, system: System) -> &mut Self {
self.app.as_mut().unwrap().add_system(system);
self
}
pub fn with_service<T: IntoService>(&mut self, service: T) -> &mut Self
{
self.app.as_mut().unwrap().add_service(service);
self
}
pub fn run(&mut self) {
let app = self.app.take().unwrap();
app.run();
}
}
pub trait ExtendWith<T> {
fn extend_with(&mut self, extension: T);
}
impl ExtendWith<System> for Dotrix {
fn extend_with(&mut self, extension: System) {
self.app.as_mut().unwrap().add_system(extension);
}
}
impl<T: IntoService> ExtendWith<Service<T>> for Dotrix {
fn extend_with(&mut self, extension: Service<T>) {
self.app.as_mut().unwrap().add_service(extension.node);
}
}
impl<T: FnOnce(&mut Application)> ExtendWith<T> for Dotrix {
fn extend_with(&mut self, extension: T) {
extension(self.app.as_mut().unwrap())
}
}
#[macro_export]
macro_rules! count {
() => (0usize);
( $x:tt, $($xs:tt)* ) => (1usize + count!($($xs)*));
}
#[macro_export]
macro_rules! recursive {
($macro: ident, $args: ident) => {
$macro!{$args}
};
($macro: ident, $first: ident, $($rest: ident),*) => {
$macro!{$first, $($rest),*}
recursive!{$macro, $($rest),*}
};
}