nuke user specializers
This commit is contained in:
parent
33fcee8393
commit
f1ccd01381
@ -256,34 +256,22 @@ macro_rules! impl_specialization_key_tuple {
|
|||||||
// TODO: How to we fake_variadics this?
|
// TODO: How to we fake_variadics this?
|
||||||
all_tuples!(impl_specialization_key_tuple, 0, 12, T);
|
all_tuples!(impl_specialization_key_tuple, 0, 12, T);
|
||||||
|
|
||||||
pub type SpecializerFn<T, S> =
|
|
||||||
fn(<S as Specializer<T>>::Key, &mut <T as Specializable>::Descriptor) -> Result<(), BevyError>;
|
|
||||||
|
|
||||||
/// A cache for specializable resources. For a given key type the resulting
|
/// A cache for specializable resources. For a given key type the resulting
|
||||||
/// resource will only be created if it is missing, retrieving it from the
|
/// resource will only be created if it is missing, retrieving it from the
|
||||||
/// cache otherwise.
|
/// cache otherwise.
|
||||||
pub struct SpecializedCache<T: Specializable, S: Specializer<T>> {
|
pub struct SpecializedCache<T: Specializable, S: Specializer<T>> {
|
||||||
specializer: S,
|
specializer: S,
|
||||||
user_specializer: Option<SpecializerFn<T, S>>,
|
|
||||||
base_descriptor: T::Descriptor,
|
base_descriptor: T::Descriptor,
|
||||||
primary_cache: HashMap<S::Key, T::CachedId>,
|
primary_cache: HashMap<S::Key, T::CachedId>,
|
||||||
secondary_cache: HashMap<Canonical<S::Key>, T::CachedId>,
|
secondary_cache: HashMap<Canonical<S::Key>, T::CachedId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Specializable, S: Specializer<T>> SpecializedCache<T, S> {
|
impl<T: Specializable, S: Specializer<T>> SpecializedCache<T, S> {
|
||||||
/// Creates a new [`SpecializedCache`] from a [`Specializer`],
|
/// Creates a new [`SpecializedCache`] from a [`Specializer`] and a base descriptor.
|
||||||
/// an optional "user specializer", and a base descriptor. The
|
|
||||||
/// user specializer is applied after the [`Specializer`], with
|
|
||||||
/// the same key.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(specializer: S, base_descriptor: T::Descriptor) -> Self {
|
||||||
specializer: S,
|
|
||||||
user_specializer: Option<SpecializerFn<T, S>>,
|
|
||||||
base_descriptor: T::Descriptor,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
specializer,
|
specializer,
|
||||||
user_specializer,
|
|
||||||
base_descriptor,
|
base_descriptor,
|
||||||
primary_cache: Default::default(),
|
primary_cache: Default::default(),
|
||||||
secondary_cache: Default::default(),
|
secondary_cache: Default::default(),
|
||||||
@ -302,7 +290,6 @@ impl<T: Specializable, S: Specializer<T>> SpecializedCache<T, S> {
|
|||||||
Entry::Occupied(entry) => Ok(entry.get().clone()),
|
Entry::Occupied(entry) => Ok(entry.get().clone()),
|
||||||
Entry::Vacant(entry) => Self::specialize_slow(
|
Entry::Vacant(entry) => Self::specialize_slow(
|
||||||
&self.specializer,
|
&self.specializer,
|
||||||
self.user_specializer,
|
|
||||||
self.base_descriptor.clone(),
|
self.base_descriptor.clone(),
|
||||||
pipeline_cache,
|
pipeline_cache,
|
||||||
key,
|
key,
|
||||||
@ -315,7 +302,6 @@ impl<T: Specializable, S: Specializer<T>> SpecializedCache<T, S> {
|
|||||||
#[cold]
|
#[cold]
|
||||||
fn specialize_slow(
|
fn specialize_slow(
|
||||||
specializer: &S,
|
specializer: &S,
|
||||||
user_specializer: Option<SpecializerFn<T, S>>,
|
|
||||||
base_descriptor: T::Descriptor,
|
base_descriptor: T::Descriptor,
|
||||||
pipeline_cache: &PipelineCache,
|
pipeline_cache: &PipelineCache,
|
||||||
key: S::Key,
|
key: S::Key,
|
||||||
@ -325,10 +311,6 @@ impl<T: Specializable, S: Specializer<T>> SpecializedCache<T, S> {
|
|||||||
let mut descriptor = base_descriptor.clone();
|
let mut descriptor = base_descriptor.clone();
|
||||||
let canonical_key = specializer.specialize(key.clone(), &mut descriptor)?;
|
let canonical_key = specializer.specialize(key.clone(), &mut descriptor)?;
|
||||||
|
|
||||||
if let Some(user_specializer) = user_specializer {
|
|
||||||
(user_specializer)(key, &mut descriptor)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the whole key is canonical, the secondary cache isn't needed.
|
// if the whole key is canonical, the secondary cache isn't needed.
|
||||||
if <S::Key as SpecializerKey>::IS_CANONICAL {
|
if <S::Key as SpecializerKey>::IS_CANONICAL {
|
||||||
return Ok(primary_entry
|
return Ok(primary_entry
|
||||||
|
@ -336,8 +336,7 @@ impl FromWorld for CustomPhasePipeline {
|
|||||||
..default()
|
..default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let specialized_cache =
|
let specialized_cache = SpecializedCache::new(CustomPhaseSpecializer, base_descriptor);
|
||||||
SpecializedCache::new(CustomPhaseSpecializer, None, base_descriptor);
|
|
||||||
|
|
||||||
Self { specialized_cache }
|
Self { specialized_cache }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user