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
use crate::{BitSet, BitSetVec, Entity};
pub struct EntityIterator<'a> {
pub(crate) current_id: usize,
pub(crate) next_id: usize,
pub(crate) entities: &'a BitSetVec,
pub(crate) generations: &'a Vec<u32>,
pub(crate) bitset: std::rc::Rc<BitSetVec>,
}
impl<'a> Iterator for EntityIterator<'a> {
type Item = Option<Entity>;
fn next(&mut self) -> Option<Self::Item> {
while !self.bitset.bit_test(self.current_id) && self.current_id < self.next_id {
self.current_id += 1;
}
let ret = if self.current_id < self.next_id {
if self.entities.bit_test(self.current_id) {
Some(Some(Entity::new(
self.current_id as u32,
self.generations[self.current_id],
)))
} else {
Some(None)
}
} else {
None
};
self.current_id += 1;
ret
}
}