aboutsummaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/arena.rs12
-rw-r--r--src/data/component_set.rs17
2 files changed, 23 insertions, 6 deletions
diff --git a/src/data/arena.rs b/src/data/arena.rs
index bc7176d..c7cbf07 100644
--- a/src/data/arena.rs
+++ b/src/data/arena.rs
@@ -770,13 +770,13 @@ impl<T> Arena<T> {
/// other kinds of bit-efficient indexing.
///
/// You should use the `get` method instead most of the time.
- pub fn get_unknown_gen(&self, i: usize) -> Option<(&T, Index)> {
- match self.items.get(i) {
+ pub fn get_unknown_gen(&self, i: u32) -> Option<(&T, Index)> {
+ match self.items.get(i as usize) {
Some(Entry::Occupied { generation, value }) => Some((
value,
Index {
generation: *generation,
- index: i as u32,
+ index: i,
},
)),
_ => None,
@@ -793,13 +793,13 @@ impl<T> Arena<T> {
/// other kinds of bit-efficient indexing.
///
/// You should use the `get_mut` method instead most of the time.
- pub fn get_unknown_gen_mut(&mut self, i: usize) -> Option<(&mut T, Index)> {
- match self.items.get_mut(i) {
+ pub fn get_unknown_gen_mut(&mut self, i: u32) -> Option<(&mut T, Index)> {
+ match self.items.get_mut(i as usize) {
Some(Entry::Occupied { generation, value }) => Some((
value,
Index {
generation: *generation,
- index: i as u32,
+ index: i,
},
)),
_ => None,
diff --git a/src/data/component_set.rs b/src/data/component_set.rs
index ca7df67..6e0461c 100644
--- a/src/data/component_set.rs
+++ b/src/data/component_set.rs
@@ -5,30 +5,47 @@ use crate::data::Index;
// fn get(&self, handle: Index) -> Option<&T>;
// }
+/// A set of optional elements of type `T`.
pub trait ComponentSetOption<T>: Sync {
+ /// Get the element associated to the given `handle`, if there is one.
fn get(&self, handle: Index) -> Option<&T>;
}
+/// A set of elements of type `T`.
pub trait ComponentSet<T>: ComponentSetOption<T> {
+ /// The estimated number of elements in this set.
+ ///
+ /// This value is typically used for preallocating some arrays for
+ /// better performances.
fn size_hint(&self) -> usize;
// TODO ECS: remove this, its only needed by the query pipeline update
// which should only take the modified colliders into account.
+ /// Iterate through all the elements on this set.
fn for_each(&self, f: impl FnMut(Index, &T));
+ /// Get the element associated to the given `handle`.
fn index(&self, handle: Index) -> &T {
self.get(handle).unwrap()
}
}
+/// A set of mutable elements of type `T`.
pub trait ComponentSetMut<T>: ComponentSet<T> {
+ /// Applies the given closure to the element associated to the given `handle`.
+ ///
+ /// Return `None` if the element doesn't exist.
fn map_mut_internal<Result>(
&mut self,
handle: crate::data::Index,
f: impl FnOnce(&mut T) -> Result,
) -> Option<Result>;
+
+ /// Set the value of this element.
fn set_internal(&mut self, handle: crate::data::Index, val: T);
}
+/// Helper trait to address multiple elements at once.
pub trait BundleSet<'a, T> {
+ /// Access multiple elements from this set.
fn index_bundle(&'a self, handle: Index) -> T;
}