class
Resources
Manager for dealing with all engine resources.
It allows you to save new resources and load existing ones.
Public
Constructors
Resources
Methods
~Resources
Load
Loads a resource at the specified path.
Resources are searched in all currently loaded packages within the PackageManager, as well as any in-memory resources registered with the Resources manager.
- resourcePath
- Path to the resource. This may be a virtual or physical path. e.g.: Virtual path: '/game/textures/path/to/resource' Physical path: 'D:/path/to/package.b3d/path/to/resource'
- loadOptions
- Options to control the loading process.
Returns: Handle to the resource. Note if performing async loading this method will return immediately, but the resource may not yet be loaded. Returns null if resource cannot be loaded, and logs why it failed.
Load
Loads a resource with the specified ID.
Resources are searched in all currently loaded packages within the PackageManager, as well as any in-memory resources registered with the Resources manager.
- resourceId
- ID of the resource.
- loadOptions
- Options to control the loading process.
Returns: Handle to the resource. Note if performing async loading this method will return immediately, but the resource may not yet be loaded. Returns null if resource cannot be loaded, and logs why it failed.
Exists
Checks if the resource at the provided path exists.
- resourcePath
- Path to the resource. This may be a virtual or physical path. e.g.: Virtual path: '/game/textures/path/to/resource' Physical path: 'D:/path/to/package.b3d/path/to/resource'
Returns: True if the resource can be located, false otherwise.
Exists
Checks if the resource with the provided ID exists.
- resourceId
- ID of the resource.
Returns: True if the resource can be located, false otherwise.
ReleaseInternalReference
Releases an internal reference to the resource held by the resources system.
This allows the resource to be unloaded when it goes out of scope, if the resource was loaded with option.
Alternatively you can also skip manually calling ReleaseInternalReference() and call UnloadAllUnused() which will unload all resources that do not have any external references, but you lose the fine grained control of what will be unloaded.
ReleaseInternalReference
UnloadAllUnused
Finds all resources that aren't being referenced outside of the resources system and unloads them.
UnloadAll
Forces unload of all resources, whether they are being used or not.
SaveAsSinglePackage
Saves a resource into its own package.
The package will be created in , with as the package name. There will be a single resource in the package, also named .
- resource
- Resource to save.
- folder
- Absolute path to a folder in which to create the package.
- name
- Name of the package to create, as well as the name of the resource within the package.
- saveOptions
- Options to control the save operation.
IsLoaded
Checks is the resource with the specified UUID loaded.
- uuid
- UUID of the resource to check.
- checkInProgress
- Should this method also check resources that are in progress of being asynchronously loaded.
Returns: True if loaded or loading in progress, false otherwise.
GetLoadProgress
Returns the loading progress of a resource that's being loaded
- resource
- Resource whose load progress to check.
Returns: Load progress in range [0, 1].
staticInstance
Returns a reference to the module instance.
Module has to have been started up first otherwise an exception will be thrown.
staticInstancePtr
Returns a pointer to the module instance.
Module has to have been started up first otherwise an exception will be thrown.
staticShutDown
Shuts down this module and frees any resources it is using.
staticIsStarted
Query if the module has been started.
Fields
OnResourceLoaded
Called when the resource has been successfully loaded.
OnResourceDestroyed
Called when the resource has been destroyed.
Provides UUID of the destroyed resource.
OnResourceModified
Called when the internal resource the handle is pointing to has changed.
Internal
Methods
CreateResourceHandle
Creates a new resource handle from a resource pointer.
CreateResourceHandle
Creates a new resource handle from a resource pointer, with a user defined UUID.
GetOrCreateResourceHandle
Returns an existing handle for the specified UUID if one exists, or creates a new one.
UpdateResourcesFromPackage
Updates all resources from the resource data in the package locked by the provided write lock.
This means if a resource is already loaded by the resource system, the resource will be retrieved from the package and handle to the resource updated with the new resource. This may involve loading the resource, if the new package doesn't have the resource loaded. If the resource is loaded in the package, but not marked as loaded by the resource system, it will be unloaded from the package.
UpdateHandle
Updates an existing resource handle with a new resource.
Caller must ensure that new resource type matches the original resource type.
DestroyHandleData
Triggered when the last resource handle for a particular resource goes out of scope.
Protected
Methods
~Module<T>
OnStartUp
Override if you want your module to be notified once it has been constructed and started.
OnShutDown
Override if you want your module to be notified just before it is deleted.
staticInstanceInternal
Returns a singleton instance of this module.
Private
Methods
GetLoadProgressRecursive
Calculates the load progress of the provided resource and appends the progress information to the .
Then calls this method recursively for any in-progress dependency loads. If the resource is already fully loaded, or not being loaded at all the LoadProgress structure will not contain a valid size value.
LoadFromPackage
Performs a load of the provided resource from the package locked by the write lock.
If requested this will also trigger a load of all dependencies of the resource. Triggers TryFinalizeLoad() when a resource or any of its dependencies complete loading.
This is an internal method to be shared by public Load() overloads.
TryFinalizeLoad
Checks if the provided in-progress load has completed any finalizes the operation.
Operation is deemed complete once its primary resource and all dependencies (and their dependencies) have finished loading. At that point we will clear the in-progress load map and add the resource into the loaded resource map. External code will be notified that load completed, and if any other resource is waiting on this resource to finish loading, they will be notified so they may try to finalize their operations as well.