Fix the obvious problems, still recipe book isn't hot reloading any more

This commit is contained in:
Christof Petig 2024-01-27 15:19:37 +01:00
parent cc93474c2f
commit b407a2b186
2 changed files with 12 additions and 16 deletions

View File

@ -129,7 +129,7 @@ pub trait AssetCombined: AssetExt {
/// Load combined table without hot-reload support
fn load_and_combine_static(specifier: &str) -> Result<AssetHandle<Self>, Error> {
Self::load_and_combine(ASSETS.filesystem_cache(), specifier)
Self::load_and_combine(ASSETS.non_reloading_cache(), specifier)
}
#[track_caller]
@ -149,7 +149,7 @@ pub trait AssetCombined: AssetExt {
/// Load combined table without hot-reload support, panic on error
#[track_caller]
fn load_expect_combined_static(specifier: &str) -> AssetHandle<Self> {
Self::load_expect_combined(ASSETS.filesystem_cache(), specifier)
Self::load_expect_combined(ASSETS.non_reloading_cache(), specifier)
}
}
@ -157,7 +157,6 @@ pub trait AssetCombined: AssetExt {
pub trait CacheCombined<'a> {
fn load_and_combine<A: Compound + Concatenate>(
self,
// reloading_cache: AnyCache,
id: &str,
) -> Result<&'a assets_manager::Handle<A>, Error>;
}
@ -188,20 +187,14 @@ impl<T: Compound> AssetExt for T {
impl<'a> CacheCombined<'a> for AnyCache<'a> {
fn load_and_combine<A: Compound + Concatenate>(
self,
// reloading_cache: AnyCache,
specifier: &str,
) -> Result<&'a assets_manager::Handle<A>, Error> {
#[cfg(feature = "plugins")]
{
self.get_cached(specifier).map_or_else(
|| {
tracing::info!("combine {specifier}");
let data: Result<A, _> =
ASSETS.combine(self, |cache: AnyCache| cache.load_owned::<A>(specifier));
data.map(|data| self.get_or_insert(specifier, data))
},
Ok,
)
tracing::info!("combine {specifier}");
let data: Result<A, _> =
ASSETS.combine(self, |cache: AnyCache| cache.load_owned::<A>(specifier));
data.map(|data| self.get_or_insert(specifier, data))
}
#[cfg(not(feature = "plugins"))]
{
@ -210,7 +203,6 @@ impl<'a> CacheCombined<'a> for AnyCache<'a> {
}
}
// this function bypasses hot-reloading!
impl<T: Compound + Concatenate> AssetCombined for T {
fn load_and_combine(
reloading_cache: AnyCache<'static>,

View File

@ -133,8 +133,11 @@ impl CombinedCache {
}
#[doc(hidden)]
// when not using a compound
pub(crate) fn filesystem_cache(&self) -> AnyCache<'_> { self.0.raw_source().fs.as_any_cache() }
// Provide a cache to the "combine_static" functions as they omit
// wrapping in a Compound (which enables hot-reload)
pub(crate) fn non_reloading_cache(&self) -> AnyCache<'_> {
self.0.raw_source().fs.as_any_cache()
}
/// Combine objects from filesystem and plugins
pub fn combine<T: Concatenate>(
@ -200,6 +203,7 @@ impl CombinedCache {
// Just forward these methods to the cache
#[inline]
#[cfg(feature = "hot-reloading")]
pub fn enhance_hot_reloading(&'static self) { self.0.enhance_hot_reloading(); }
#[inline]