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
//! # Goal
//!
//! We want to define components, store them in an efficient manner and
//! make them accessible to systems.
//!
//! We want to define events along with their types and make them available
//! to systems.
//!
//! We want to define systems that operate on lists of components, are
//! triggered by other systems through events.
//!
//! # Implementation
//!
//! For each component type there will be a list that is a tuple of an
//! entity ID and the component values. There will also be a map from
//! entity IDs to component list indexes.
//!
//! A system will consist of state, iterators over components its subscribed
//! to and any number of functions that are triggered by events.
//!
//! # Syntax
//!
//! ```
//! component! { Physics, body: physics.RigidBody, physics_id: physics.ID }
//!
//! // event! { GameStarted } // This one is implicitly defined
//! event! { PhysicsTick, dt: u64 }
//! event! { Bump, e1: EntityID, e2: EntityID }
//!
//! system! { PhysicsSystem,
//!
//! state! { world: physics.World }
//!
//! on! { GameStarted, {
//! state.world = physics.World::new(event.name);
//! state.world.on_collision = |e1, e2| {
//! unwrap_entity = |e| { e.user_data.downcast_ref<EntityID>() }
//! trigger! { Bump, unwrap_entity(e1), unwrap_entity(e2) }
//! };
//! }}
//!
//! on! { PhysicsTick, {
//! state.world.step(event.dt);
//! }}
//!
//! component_added! { Physics, {
//! let id = state.world.add_body(component.body);
//! component.physics_id = id;
//! }}
//!
//! component_removed! { Physics, {
//! state.world.remove_body(component.physics_id);
//! }}
//!
//! }
//!
//! system! { BumpSystem, {
//! on! { Bump, {
//! println!("Entity {:?} bumped into entity {:?}!", e1, e2);
//! }}
//! }}
//! ```
extern crate lazy_static;
extern crate shared_mutex;
extern crate uuid;
use thread;
pub use ;
event!