Some more CSE stuff
Getty Ritter
7 years ago
1 |
use std::collections:: |
|
1 | use std::collections::{BTreeMap}; | |
2 | use std::collections::btree_map; | |
3 | ||
4 | pub struct JoinedIter<'a, K: 'a, A: 'a, B: 'a> { | |
5 | left: btree_map::Iter<'a, K, A>, | |
6 | right: btree_map::Iter<'a, K, B>, | |
7 | } | |
8 | ||
9 | impl<'a, K, A, B> Iterator for JoinedIter<'a, K, A, B> | |
10 | where K: Ord | |
11 | { | |
12 | type Item = (&'a K, (&'a A, &'a B)); | |
13 | ||
14 | fn next(&mut self) -> Option<<Self as Iterator>::Item> { | |
15 | let mut l = self.left.next(); | |
16 | let mut r = self.right.next(); | |
17 | loop { | |
18 | match (l, r) { | |
19 | (None, _) => return None, | |
20 | (_, None) => return None, | |
21 | (Some((lk, lv)), Some((rk, rv))) => { | |
22 | if lk < rk { | |
23 | l = self.left.next(); | |
24 | } else if rk < lk { | |
25 | r = self.right.next(); | |
26 | } else { | |
27 | return Some((lk, (lv, rv))); | |
28 | } | |
29 | } | |
30 | } | |
31 | } | |
32 | } | |
33 | } | |
2 | 34 | |
3 | 35 | // An `Entity` is an abstract 64-bit quantity. Nothing outside this |
4 | 36 | // module should care what an entity is or how it works. |
5 |
#[derive(Debug, Copy, Clone, PartialEq, Eq, |
|
37 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] | |
6 | 38 | pub struct Entity { |
7 | 39 | idx: u64, |
8 | 40 | } |
97 | 129 | } |
98 | 130 | } |
99 | 131 | |
132 | ||
133 | #[derive(Debug)] | |
100 | 134 | pub struct System<Component> { |
101 |
map: |
|
135 | map: BTreeMap<Entity, Component>, | |
102 | 136 | } |
103 | 137 | |
104 | 138 | impl<Component> System<Component> { |
105 | 139 | pub fn new() -> System<Component> { |
106 |
System { map: |
|
140 | System { map: BTreeMap::new() } | |
107 | 141 | } |
108 | 142 | |
109 | 143 | pub fn add(&mut self, e: Entity, c: Component) { |
126 | 160 | } |
127 | 161 | |
128 | 162 | #[derive(Debug)] |
163 | pub struct Interact { | |
164 | interact: (), | |
165 | } | |
166 | ||
167 | #[derive(Debug)] | |
129 | 168 | pub struct DebugInfo { |
130 | 169 | name: String, |
131 | 170 | } |
135 | 174 | mesh: (), |
136 | 175 | } |
137 | 176 | |
177 | #[derive(Debug)] | |
138 | 178 | pub struct SystemState { |
139 | 179 | positions: System<Position>, |
140 | 180 | debug_info: System<DebugInfo>, |
181 | meshes: System<Mesh>, | |
182 | interactions: System<Interact>, | |
141 | 183 | } |