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
use action::{CellAction, EntityAction};
use cell::CellState;
use engine::Engine;
use entity::{EntityState, MutEntityState};
use universe::Universe;
pub mod middleware;
use self::middleware::Middleware;
pub trait Driver<
C: CellState,
E: EntityState<C>,
M: MutEntityState,
CA: CellAction<C>,
EA: EntityAction<C, E>,
U: Universe<C, E, M>,
N: Engine<C, E, M, CA, EA, U>,
>
{
fn init(self, universe: U, N, Vec<Box<Middleware<C, E, M, CA, EA, U, N>>>);
}
pub struct BasicDriver;
impl<
C: CellState,
E: EntityState<C>,
M: MutEntityState,
CA: CellAction<C>,
EA: EntityAction<C, E>,
U: Universe<C, E, M>,
N: Engine<C, E, M, CA, EA, U>,
> Driver<C, E, M, CA, EA, U, N> for BasicDriver
{
fn init(self, mut universe: U, mut engine: N, mut middleware: Vec<Box<Middleware<C, E, M, CA, EA, U, N>>>) {
println!("Starting simulation driver...");
loop {
for m in middleware.iter_mut() {
m.before_render(&mut universe);
}
engine.step(&mut universe);
for m in middleware.iter_mut() {
m.after_render(&mut universe);
}
}
}
}