1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#![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),*}
};
}