3#include <Core/ResourceManager/Implementation/WorkerTasks.h>
4#include <Core/ResourceManager/Resource.h>
5#include <Core/ResourceManager/ResourceHandle.h>
6#include <Core/ResourceManager/ResourceTypeLoader.h>
7#include <Foundation/Configuration/Plugin.h>
8#include <Foundation/Containers/HashTable.h>
9#include <Foundation/Threading/LockedObject.h>
10#include <Foundation/Types/UniquePtr.h>
34 static void BroadcastExistsEvent();
47 template <
typename ResourceType>
57 template <
typename ResourceType>
66 static bool IsAnyLoadingInProgress();
80 template <
typename ResourceType,
typename DescriptorType>
88 template <
typename ResourceType,
typename DescriptorType>
95 template <
typename ResourceType>
101 template <
typename ResourceType>
104 plTypelessResourceHandle hTypeless = GetExistingResourceOrCreateAsync(plGetStaticRTTI<ResourceType>(), sResourceID, std::move(pLoader));
108 if (hLoadingFallback.
IsValid())
110 ((ResourceType*)hTypeless.m_pResource)->SetLoadingFallbackResource(hLoadingFallback);
135 static plUInt32 ReloadAllResources(
bool bForce);
139 template <
typename ResourceType>
140 static plUInt32 ReloadResourcesOfType(
bool bForce);
144 static plUInt32 ReloadResourcesOfType(
const plRTTI* pType,
bool bForce);
147 template <
typename ResourceType>
181 template <
typename ResourceType>
184 plResourceAcquireResult* out_pAcquireResult =
nullptr);
191 template <
typename ResourceType>
192 static void EndAcquireResource(ResourceType* pResource);
195 static void EndAcquireResourcePointer(
plResource* pResource);
199 static void ForceNoFallbackAcquisition(plUInt32 uiNumFrames = 0xFFFFFFFF);
203 static plUInt32 GetForceNoFallbackAcquisition();
208 template <
typename ResourceType>
217 static plUInt32 FreeAllUnusedResources();
220 static plUInt32 FreeUnusedResources(
plTime timeout,
plTime lastAcquireThreshold);
223 static void SetAutoFreeUnused(
plTime timeout,
plTime lastAcquireThreshold);
226 template <
typename ResourceType>
227 static void SetIncrementalUnloadForResourceType(
bool bActive);
229 template <
typename TypeBeingUpdated,
typename TypeItWantsToAcquire>
230 static void AllowResourceTypeAcquireDuringUpdateContent()
232 AllowResourceTypeAcquireDuringUpdateContent(plGetStaticRTTI<TypeBeingUpdated>(), plGetStaticRTTI<TypeItWantsToAcquire>());
235 static void AllowResourceTypeAcquireDuringUpdateContent(
const plRTTI* pTypeBeingUpdated,
const plRTTI* pTypeItWantsToAcquire);
237 static bool IsResourceTypeAcquireDuringUpdateContentAllowed(
const plRTTI* pTypeBeingUpdated,
const plRTTI* pTypeItWantsToAcquire);
252 static void PerFrameUpdate();
255 static void EngineAboutToShutdown();
260 static void ResetAllResources();
287 template <
typename ResourceType>
303 static void UnregisterNamedResource(
plStringView sLookupName);
312 static void RegisterResourceForAssetType(
plStringView sAssetTypeName,
const plRTTI* pResourceType);
325 static void EnableExportMode(
bool bEnable);
328 static bool IsExportModeEnabled();
333 template <
typename ResourceType>
359 static void UnregisterResourceOverrideType(
const plRTTI* pDerivedTypeToUse);
367 template <
typename RESOURCE_TYPE>
370 RESOURCE_TYPE::SetResourceTypeLoadingFallback(hResource);
374 template <
typename RESOURCE_TYPE>
377 return RESOURCE_TYPE::GetResourceTypeLoadingFallback();
383 template <
typename RESOURCE_TYPE>
386 RESOURCE_TYPE::SetResourceTypeMissingFallback(hResource);
390 template <
typename RESOURCE_TYPE>
393 return RESOURCE_TYPE::GetResourceTypeMissingFallback();
399 static void AddResourceCleanupCallback(ResourceCleanupCB cb);
402 static void ClearResourceCleanupCallback(ResourceCleanupCB cb);
406 static void ExecuteAllResourceCleanupCallbacks();
414 template <
typename RESOURCE_TYPE>
417 GetResourceTypePriorities()[plGetStaticRTTI<RESOURCE_TYPE>()] = priority;
432 friend class plResourceHandleReadContext;
440 static plMutex s_ResourceMutex;
444 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Core, ResourceManager);
445 static void OnEngineShutdown();
446 static void OnCoreShutdown();
447 static void OnCoreStartup();
452 struct LoadedResources
459 float m_fPriority = 0;
462 PL_ALWAYS_INLINE
bool operator==(
const LoadingInfo& rhs)
const {
return m_pResource == rhs.m_pResource; }
463 PL_ALWAYS_INLINE
bool operator<(
const LoadingInfo& rhs)
const {
return m_fPriority < rhs.m_fPriority; }
465 static void EnsureResourceLoadingState(
plResource* pResource,
const plResourceState RequestedState);
466 static void PreloadResource(
plResource* pResource);
467 static void InternalPreloadResource(
plResource* pResource,
bool bHighestPriority);
469 template <
typename ResourceType>
470 static ResourceType* GetResource(
plStringView sResourceID,
bool bIsReloadable);
472 static void RunWorkerTask(
plResource* pResource);
473 static void UpdateLoadingDeadlines();
475 static bool ReloadResource(
plResource* pResource,
bool bForce);
477 static void SetupWorkerTasks();
478 static plTime GetLastFrameUpdate();
482 PL_ALWAYS_INLINE
static bool IsQueuedForLoading(
plResource* pResource) {
return pResource->m_Flags.
IsSet(plResourceFlags::IsQueuedForLoading); }
484 static void AddToLoadingQueue(
plResource* pResource,
bool bHighPriority);
486 struct ResourceTypeInfo
488 bool m_bIncrementalUnload =
true;
489 bool m_bAllowNestedAcquireCached =
false;
494 static ResourceTypeInfo& GetResourceTypeInfo(
const plRTTI* pRtti);
504 struct DerivedTypeInfo
506 const plRTTI* m_pDerivedType =
nullptr;
514#include <Core/ResourceManager/Implementation/ResourceLock.h>
515#include <Core/ResourceManager/Implementation/ResourceManager_inl.h>
Definition DynamicArray.h:81
Definition HashTable.h:333
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Provides access to an object while managing a lock (e.g. a mutex) that ensures that during its lifeti...
Definition LockedObject.h:7
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
The base class for all resources.
Definition Resource.h:10
The central class for managing all types derived from plResource.
Definition ResourceManager.h:16
static void SetResourceTypeDefaultPriority(plResourcePriority priority)
Specifies which resource to use as a loading fallback for the given type, while a resource is not yet...
Definition ResourceManager.h:415
static const plTypedResourceHandle< RESOURCE_TYPE > & GetResourceTypeMissingFallback()
Definition ResourceManager.h:391
static void SetResourceTypeLoadingFallback(const plTypedResourceHandle< RESOURCE_TYPE > &hResource)
Specifies which resource to use as a loading fallback for the given type, while a resource is not yet...
Definition ResourceManager.h:368
static void SetResourceTypeMissingFallback(const plTypedResourceHandle< RESOURCE_TYPE > &hResource)
Specifies which resource to use as a missing fallback for the given type, when a resource cannot be l...
Definition ResourceManager.h:384
static const plTypedResourceHandle< RESOURCE_TYPE > & GetResourceTypeLoadingFallback()
Definition ResourceManager.h:375
static plMutex & GetMutex()
Returns the resource manager mutex. Allows to lock the manager on a thread when multiple operations n...
Definition ResourceManager.h:249
Definition ResourceManagerState.h:9
[internal] Worker task for loading resources (typically from disk).
Definition WorkerTasks.h:10
[internal] Worker task for uploading resource data. Depending on the resource type,...
Definition WorkerTasks.h:26
Base class for all resource loaders.
Definition ResourceTypeLoader.h:29
Interface for binary in (read) streams.
Definition Stream.h:22
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
The plTypedResourceHandle controls access to an plResource.
Definition ResourceHandle.h:136
PL_ALWAYS_INLINE bool IsValid() const
Returns whether the handle stores a valid pointer to a resource.
Definition ResourceHandle.h:206
The typeless implementation of resource handles. A typed interface is provided by plTypedResourceHand...
Definition ResourceHandle.h:32
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
PL_ALWAYS_INLINE bool IsSet(Enum flag) const
Checks if certain flags are set within the bitfield.
Definition Bitflags.h:127
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
The data that is broadcast whenever a plugin is (un-) loaded.
Definition Plugin.h:11
These events may be sent by a specific plResource or by the plResourceManager.
Definition Declarations.h:22
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12