-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.rs
75 lines (64 loc) · 1.67 KB
/
lib.rs
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
extern crate cgmath;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate frunk;
#[macro_use]
extern crate glium;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate obj;
extern crate rayon;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate typemap;
#[macro_use]
pub mod util;
mod components;
mod gui;
mod map;
mod state;
pub use crate::{
components::LocationComponent,
gui::{GuiSystem, Model, RenderComponent, RenderData, Vertex},
map::{Map, Tile},
state::{State, World},
};
use frunk::{FuncMut, PolyMut};
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
/// An entity.
#[derive(Clone, Copy, Default, Eq, Hash, PartialEq)]
pub struct Entity(usize);
impl Debug for Entity {
fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
write!(fmt, "Entity(n={:?})", self.0)
}
}
impl Display for Entity {
fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
write!(fmt, "{:?}", self)
}
}
/// The trait for a system.
pub trait System {
/// Runs a single step.
fn step(&mut self, state: &mut State, dt: u64);
}
/// A helper for stepping through a system with Frunk.
pub struct SystemStepper<'a>(pub &'a mut State, pub u64);
impl<'a> SystemStepper<'a> {
/// Creates a `PolyMut` function for calling `System::step` with the given arguments.
pub fn with_args(state: &'a mut State, dt: u64) -> PolyMut<SystemStepper<'a>> {
PolyMut(SystemStepper(state, dt))
}
}
impl<'a, 'b, S: System> FuncMut<&'b mut S> for SystemStepper<'a> {
type Output = ();
fn call(&mut self, system: &'b mut S) {
system.step(self.0, self.1)
}
}