Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. impl<'r> Ecs<'r> {
  2. pub fn add_entity<A: 'static>(&'r mut self) {
  3. let index: usize = {
  4. let p: Option<usize> = {
  5. self.world // immutable borrow here
  6. .iter()
  7. .position(|store| {
  8. store.types().len() == 1 && store.types().all(|ty| *ty == TypeId::of::<A>())
  9. })
  10. };
  11. let index = p.unwrap_or(self.world.len());
  12. if p.is_none() {
  13. let mut store = VecTypeStore::new();
  14. store.insert(Vec::<A>::new());
  15. self.world.push(store); // mutable borrow here
  16. }
  17. index
  18. };
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement