From ca2f8b286fe6b9a7317455e5ae280a955d5774e6 Mon Sep 17 00:00:00 2001 From: Rajveer Date: Sun, 10 Nov 2024 23:45:59 +0530 Subject: [PATCH] Support for `get_many` and `get_many_mut` functions for `Assets` Part of #16244 --- crates/bevy_asset/src/assets.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 5f4a053846599..6f30e3428fa99 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -215,6 +215,19 @@ impl DenseAssetStorage { } } + pub(crate) fn get_many(&self, indices: [AssetIndex; N]) -> [Option<&A>; N] { + indices.map(|index| match self.storage.get(index.index as usize)? { + Entry::None => None, + Entry::Some { value, generation } => { + if *generation == index.generation { + value.as_ref() + } else { + None + } + } + }) + } + pub(crate) fn get_mut(&mut self, index: AssetIndex) -> Option<&mut A> { let entry = self.storage.get_mut(index.index as usize)?; match entry { @@ -229,6 +242,13 @@ impl DenseAssetStorage { } } + pub(crate) fn get_many_mut( + &mut self, + indices: [AssetIndex; N], + ) -> [Option<&mut A>; N] { + todo!() + } + pub(crate) fn flush(&mut self) { // NOTE: this assumes the allocator index is monotonically increasing. let new_len = self