gdritter repos outlander / 5942e1e
Some more CSE stuff Getty Ritter 7 years ago
1 changed file(s) with 46 addition(s) and 4 deletion(s). Collapse all Expand all
1 use std::collections::HashMap;
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 }
234
335 // An `Entity` is an abstract 64-bit quantity. Nothing outside this
436 // module should care what an entity is or how it works.
5 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
37 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
638 pub struct Entity {
739 idx: u64,
840 }
97129 }
98130 }
99131
132
133 #[derive(Debug)]
100134 pub struct System<Component> {
101 map: HashMap<Entity, Component>,
135 map: BTreeMap<Entity, Component>,
102136 }
103137
104138 impl<Component> System<Component> {
105139 pub fn new() -> System<Component> {
106 System { map: HashMap::new() }
140 System { map: BTreeMap::new() }
107141 }
108142
109143 pub fn add(&mut self, e: Entity, c: Component) {
126160 }
127161
128162 #[derive(Debug)]
163 pub struct Interact {
164 interact: (),
165 }
166
167 #[derive(Debug)]
129168 pub struct DebugInfo {
130169 name: String,
131170 }
135174 mesh: (),
136175 }
137176
177 #[derive(Debug)]
138178 pub struct SystemState {
139179 positions: System<Position>,
140180 debug_info: System<DebugInfo>,
181 meshes: System<Mesh>,
182 interactions: System<Interact>,
141183 }