@@ -289,6 +289,42 @@ class IAssetLoader : public virtual core::IReferenceCounted
289
289
SAssetBundle interm_getAssetInHierarchy (IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override);
290
290
SAssetBundle interm_getAssetInHierarchy (IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel);
291
291
SAssetBundle interm_getAssetInHierarchy (IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel);
292
+ // ! ECF_DUPLICATE_* flags are ignored (since there's no point in **restoring** if we're not even looking into the cache) -- only ECF_DONT_CACHE_* are honored
293
+ // ! `Args` ought to be same parameter types as interm_getAssetInHierarchy(...) overloads offer
294
+ template <typename ...Args>
295
+ SAssetBundle interm_getRestoredAssetInHierarchy (uint32_t _restoreLevels, Args&&... args)
296
+ {
297
+ if (_restoreLevels == 0u )
298
+ return interm_getAssetInHierarchy (std::forward<Args>(args)...);
299
+
300
+ auto any_dummy = [](const SAssetBundle& b) {
301
+ for (const auto & a : b.getContents ())
302
+ if (a->isADummyObjectForCache ())
303
+ return true ;
304
+ };
305
+
306
+ auto bundle = interm_getAssetInHierarchy_find (std::forward<Args>(args)...);
307
+
308
+ if (bundle.getContents ().empty () || !any_dummy (bundle))
309
+ return bundle;
310
+ auto reloadedBundle = interm_getAssetInHierarchy_reload (_restoreLevels, std::forward<Args>(args)...);
311
+
312
+ assert (bundle.getContents ().size () == reloadedBundle.getContents ().size ());
313
+
314
+ const uint32_t count = bundle.getContents ().size ();
315
+ auto * dummies = bundle.getContents ().begin ();
316
+ auto * reloaded = reloadedBundle.getContents ().begin ();
317
+ for (uint32_t i = 0u ; i < count; ++i)
318
+ if (dummies[i]->isADummyObjectForCache () && !dummies[i]->canBeRestoredFrom (reloaded[i].get ()))
319
+ return {}; // return empty bundle
320
+
321
+ for (uint32_t i = 0u ; i < count; ++i)
322
+ if (dummies[i]->isADummyObjectForCache ())
323
+ dummies[i]->restoreFromDummy (reloaded[i].get (), _restoreLevels);
324
+
325
+ return bundle;
326
+ }
327
+
292
328
void interm_setAssetMutability (const IAssetManager* _mgr, IAsset* _asset, IAsset::E_MUTABILITY _val);
293
329
// void interm_restoreDummyAsset(IAssetManager* _mgr, SAssetBundle& _bundle);
294
330
// void interm_restoreDummyAsset(IAssetManager* _mgr, IAsset* _asset, const std::string _path);
@@ -301,6 +337,50 @@ class IAssetLoader : public virtual core::IReferenceCounted
301
337
{
302
338
bundle.setAsset (offset,std::move (_asset));
303
339
}
340
+
341
+ private:
342
+ static IAssetLoader::SAssetLoadParams getFindParams (IAssetLoader::SAssetLoadParams _params)
343
+ {
344
+ _params.cacheFlags = static_cast <E_CACHING_FLAGS>(_params.cacheFlags & ECF_DONT_CACHE_REFERENCES);
345
+ return _params;
346
+ }
347
+ SAssetBundle interm_getAssetInHierarchy_find (IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
348
+ {
349
+ return interm_getAssetInHierarchy (_mgr, _file, _supposedFilename, getFindParams (_params), _hierarchyLevel);
350
+ }
351
+ SAssetBundle interm_getAssetInHierarchy_find (IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
352
+ {
353
+ return interm_getAssetInHierarchy (_mgr, _filename, getFindParams (_params), _hierarchyLevel, _override);
354
+ }
355
+ SAssetBundle interm_getAssetInHierarchy_find (IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel)
356
+ {
357
+ return interm_getAssetInHierarchy (_mgr, _file, _supposedFilename, getFindParams (_params), _hierarchyLevel);
358
+ }
359
+ SAssetBundle interm_getAssetInHierarchy_find (IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel)
360
+ {
361
+ return interm_getAssetInHierarchy (_mgr, _filename, getFindParams (_params), _hierarchyLevel);
362
+ }
363
+ static IAssetLoader::SAssetLoadParams getReloadParams (IAssetLoader::SAssetLoadParams _params, uint32_t _restoreLevels, uint32_t _hierLevel)
364
+ {
365
+ _params.cacheFlags = ECF_DUPLICATE_UNTIL_LEVEL (_restoreLevels + _hierLevel);
366
+ return _params;
367
+ }
368
+ SAssetBundle interm_getAssetInHierarchy_reload (uint32_t _restoreLevels, IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
369
+ {
370
+ return interm_getAssetInHierarchy (_mgr, _file, _supposedFilename, getReloadParams (_params, _restoreLevels, _hierarchyLevel), _hierarchyLevel);
371
+ }
372
+ SAssetBundle interm_getAssetInHierarchy_reload (uint32_t _restoreLevels, IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
373
+ {
374
+ return interm_getAssetInHierarchy (_mgr, _filename, getReloadParams (_params, _restoreLevels, _hierarchyLevel), _hierarchyLevel);
375
+ }
376
+ SAssetBundle interm_getAssetInHierarchy_reload (uint32_t _restoreLevels, IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel)
377
+ {
378
+ return interm_getAssetInHierarchy (_mgr, _file, _supposedFilename, getReloadParams (_params, _restoreLevels, _hierarchyLevel), _hierarchyLevel);
379
+ }
380
+ SAssetBundle interm_getAssetInHierarchy_reload (uint32_t _restoreLevels, IAssetManager* _mgr, const std::string& _filename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel)
381
+ {
382
+ return interm_getAssetInHierarchy (_mgr, _filename, getReloadParams (_params, _restoreLevels, _hierarchyLevel), _hierarchyLevel);
383
+ }
304
384
};
305
385
306
386
}
0 commit comments