Skip to content

Commit

Permalink
feat: Added a few methods on Entities (#451)
Browse files Browse the repository at this point in the history
Extra helper methods added: iter(), all_cloned(), kill_all().
  • Loading branch information
RockasMockas authored Aug 29, 2024
1 parent 76bd342 commit 90d6be0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions framework_crates/bones_ecs/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,19 @@ impl Entities {
}
}

/// Returns a list of all `Entity`s cloned into a new vec.
pub fn all_cloned(&self) -> Vec<Entity> {
self.iter().collect()
}

/// Kills all entities.
pub fn kill_all(&mut self) {
let entities: Vec<Entity> = self.all_cloned();
for entity in entities {
self.kill(entity);
}
}

/// Returns entities in the killed list.
pub fn killed(&self) -> &Vec<Entity> {
&self.killed
Expand Down Expand Up @@ -528,6 +541,17 @@ impl Entities {
bitset,
}
}

/// Iterates over all alive entities.
pub fn iter(&self) -> EntityIterator {
EntityIterator {
current_id: 0,
next_id: self.next_id,
entities: self.bitset(),
generations: &self.generation,
bitset: self.bitset(),
}
}
}

/// Iterator over entities using the provided bitset.
Expand Down

0 comments on commit 90d6be0

Please sign in to comment.