C# Class Axiom.Core.ResourceManager

Defines a generic resource handler.
A resource manager is responsible for managing a pool of resources of a particular type. It must index them, look them up, load and destroy them. It may also need to stay within a defined memory budget, and temporarily unload some resources if it needs to stay within this budget. Resource managers use a priority system to determine what can be unloaded, and a Least Recently Used (LRU) policy within resources of the same priority. Resources can be loaded using the generalized load interface, and they can be unloaded and removed. In addition, each subclass of ResourceManager will likely define custom 'load' methods which take explicit parameters depending on the kind of resource being created. Resources can be loaded and unloaded through the Resource class, but they can only be removed (and thus eventually destroyed) using their parent ResourceManager.
Inheritance: DisposableObject, IScriptLoader
Afficher le fichier Open project: WolfgangSt/axiom Class Usage Examples

Méthodes publiques

Méthode Description
Create ( string name, string group ) : Axiom.Core.Resource

Creates a new blank resource, but does not immediately load it.

Resource managers handle disparate types of resources. This method returns a pointer to a valid new instance of the kind of resource managed here. The caller should complete the details of the returned resource and call ResourceManager.Load to load the resource. Note that it is the CALLERS responsibility to destroy this object when it is no longer required (after calling ResourceManager.Unload if it had been loaded). If you want to get at the detailed interface of this resource, you'll have to cast the result to the subclass you know you're creating.

Create ( string name, string group, NameValuePairList createParams ) : Axiom.Core.Resource
Create ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList createParams ) : Axiom.Core.Resource
CreateOrRetrieve ( string name, string group ) : Tuple,Axiom.Math
CreateOrRetrieve ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList paramaters ) : Tuple,Axiom.Math
GetByHandle ( System.UInt64 handle ) : Axiom.Core.Resource
GetByName ( string name ) : Axiom.Core.Resource
Load ( string name, string group ) : Axiom.Core.Resource

Generic load method, used to create a Resource specific to this ResourceManager without using one of the specialised 'load' methods (containing per-Resource-type parameters).

Load ( string name, string group, NameValuePairList loadParams ) : Axiom.Core.Resource
Load ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList loadParams ) : Axiom.Core.Resource
NotifyResourceLoaded ( Axiom.Core.Resource res ) : void

Notify this manager that a resource which it manages has been loaded.

NotifyResourceTouched ( Axiom.Core.Resource res ) : void

Notify this manager that a resource which it manages has been 'touched', ie used.

NotifyResourceUnloaded ( Axiom.Core.Resource res ) : void

Notify this manager that a resource which it manages has been unloaded.

ParseScript ( Stream stream, string groupName, string fileName ) : void

Parse a script file.

ReloadAll ( ) : void

Causes all currently loaded resources to be reloaded.

Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.

Remove ( Axiom.Core.Resource resource ) : void

Remove a single resource.

Removes a single resource, meaning it will be removed from the list of valid resources in this manager, also causing it to be unloaded. The word 'Destroy' is not used here, since if any other pointers are referring to this resource, it will persist until they have finished with it; however to all intents and purposes it no longer exists and will likely get destroyed imminently. If you do have references to resources hanging around after the ResourceManager is destroyed, you may get problems on destruction of these resources if they were relying on the manager (especially if it is a plugin). If you find you get problems on shutdown in the destruction of resources, try making sure you release all your references before you shutdown OGRE.

Remove ( System.UInt64 handle ) : void
Remove ( string name ) : void
RemoveAll ( ) : void

Removes all resources.

Removes all resources, meaning they will be removed from the list of valid resources in this manager, also causing them to be unloaded. The word 'Destroy' is not used here, since if any other pointers are referring to this resource, it will persist until they have finished with it; however to all intents and purposes it no longer exists and will likely get destroyed imminently. If you do have references to resources hanging around after the ResourceManager is destroyed, you may get problems on destruction of these resources if they were relying on the manager (especially if it is a plugin). If you find you get problems on shutdown in the destruction of resources, try making sure you release all your references before you shutdown Axiom.

ResourceExists ( System.UInt64 handle ) : bool

Returns whether a resource with the given handle exists in this manager

ResourceExists ( string name ) : bool

Returns whether the named resource exists in this manager

Unload ( Resource resource ) : void

Unloads a Resource from the managed resources list, calling it's Unload() method.

This method removes a resource from the list maintained by this manager, and unloads it from memory. It does NOT destroy the resource itself, although the memory used by it will be largely freed up. This would allow you to reload the resource again if you wished.

Unload ( System.UInt64 handle ) : void
Unload ( string name ) : void

Unloads a single resource by name.

Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.

UnloadAll ( ) : void

Unloads all resources.

Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.

this ( System.UInt64 handle ) : Resource

Gets a resource with the given handle.

this ( string name ) : Resource

Gets a reference to the specified named resource.

Méthodes protégées

Méthode Description
ResourceManager ( ) : System

Default constructor

_add ( Resource res ) : void

Add a newly created resource to the manager

_create ( string name, System.UInt64 handle, string group, bool isManual, IManualResourceLoader loader, NameValuePairList createParams ) : Resource

Create a new resource instance compatible with this manager (no custom parameters are populated at this point).

_remove ( Resource res ) : void

Remove a resource from this manager; remove it from the lists.

checkUsage ( ) : void

Makes sure we are still within budget.

dispose ( bool disposeManagedResources ) : void

Class level dispose method

When implementing this method in an inherited class the following template should be used; protected override void dispose( bool disposeManagedResources ) { if ( !isDisposed ) { if ( disposeManagedResources ) { // Dispose managed resources. } // There are no unmanaged resources to release, but // if we add them, they need to be released here. } // If it is available, make the call to the // base class's Dispose(Boolean) method base.dispose( disposeManagedResources ); }

Method Details

Create() public méthode

Creates a new blank resource, but does not immediately load it.
Resource managers handle disparate types of resources. This method returns a pointer to a valid new instance of the kind of resource managed here. The caller should complete the details of the returned resource and call ResourceManager.Load to load the resource. Note that it is the CALLERS responsibility to destroy this object when it is no longer required (after calling ResourceManager.Unload if it had been loaded). If you want to get at the detailed interface of this resource, you'll have to cast the result to the subclass you know you're creating.
public Create ( string name, string group ) : Axiom.Core.Resource
name string The unique name of the resource
group string
Résultat Axiom.Core.Resource

Create() public méthode

public Create ( string name, string group, NameValuePairList createParams ) : Axiom.Core.Resource
name string
group string
createParams NameValuePairList If any parameters are required to create an instance, they should be supplied here as name / value pairs
Résultat Axiom.Core.Resource

Create() public méthode

public Create ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList createParams ) : Axiom.Core.Resource
name string
group string
isManual bool /// Is this resource manually loaded? If so, you should really /// populate the loader parameter in order that the load process /// can call the loader back when loading is required. ///
loader IManualResourceLoader /// Pointer to a ManualLoader implementation which will be called /// when the Resource wishes to load (should be supplied if you set /// isManual to true). You can in fact leave this parameter null /// if you wish, but the Resource will never be able to reload if /// anything ever causes it to unload. Therefore provision of a proper /// ManualLoader instance is strongly recommended. ///
createParams NameValuePairList If any parameters are required to create an instance, they should be supplied here as name / value pairs
Résultat Axiom.Core.Resource

CreateOrRetrieve() public méthode

public CreateOrRetrieve ( string name, string group ) : Tuple,Axiom.Math
name string
group string
Résultat Tuple,Axiom.Math

CreateOrRetrieve() public méthode

public CreateOrRetrieve ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList paramaters ) : Tuple,Axiom.Math
name string
group string
isManual bool
loader IManualResourceLoader
paramaters NameValuePairList
Résultat Tuple,Axiom.Math

GetByHandle() public méthode

public GetByHandle ( System.UInt64 handle ) : Axiom.Core.Resource
handle System.UInt64
Résultat Axiom.Core.Resource

GetByName() public méthode

public GetByName ( string name ) : Axiom.Core.Resource
name string
Résultat Axiom.Core.Resource

Load() public méthode

Generic load method, used to create a Resource specific to this ResourceManager without using one of the specialised 'load' methods (containing per-Resource-type parameters).
public Load ( string name, string group ) : Axiom.Core.Resource
name string The name of the Resource
group string The resource group to which this resource will belong
Résultat Axiom.Core.Resource

Load() public méthode

public Load ( string name, string group, NameValuePairList loadParams ) : Axiom.Core.Resource
name string The name of the Resource
group string The resource group to which this resource will belong
loadParams NameValuePairList /// Optional pointer to a list of name/value pairs /// containing loading parameters for this type of resource. ///
Résultat Axiom.Core.Resource

Load() public méthode

public Load ( string name, string group, bool isManual, IManualResourceLoader loader, NameValuePairList loadParams ) : Axiom.Core.Resource
name string The name of the Resource
group string The resource group to which this resource will belong
isManual bool /// Is the resource to be manually loaded? If so, you should /// provide a value for the loader parameter ///
loader IManualResourceLoader /// The manual loader which is to perform the required actions /// when this resource is loaded; only applicable when you specify true /// for the previous parameter ///
loadParams NameValuePairList /// Optional pointer to a list of name/value pairs /// containing loading parameters for this type of resource. ///
Résultat Axiom.Core.Resource

NotifyResourceLoaded() public méthode

Notify this manager that a resource which it manages has been loaded.
public NotifyResourceLoaded ( Axiom.Core.Resource res ) : void
res Axiom.Core.Resource the resource
Résultat void

NotifyResourceTouched() public méthode

Notify this manager that a resource which it manages has been 'touched', ie used.
public NotifyResourceTouched ( Axiom.Core.Resource res ) : void
res Axiom.Core.Resource the resource
Résultat void

NotifyResourceUnloaded() public méthode

Notify this manager that a resource which it manages has been unloaded.
public NotifyResourceUnloaded ( Axiom.Core.Resource res ) : void
res Axiom.Core.Resource the resource
Résultat void

ParseScript() public méthode

Parse a script file.
public ParseScript ( Stream stream, string groupName, string fileName ) : void
stream Stream reference to a data stream which is the source of the script
groupName string /// The name of a resource group which should be used if any resources /// are created during the parse of this script. ///
fileName string
Résultat void

ReloadAll() public méthode

Causes all currently loaded resources to be reloaded.
Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.
public ReloadAll ( ) : void
Résultat void

Remove() public méthode

Remove a single resource.
Removes a single resource, meaning it will be removed from the list of valid resources in this manager, also causing it to be unloaded. The word 'Destroy' is not used here, since if any other pointers are referring to this resource, it will persist until they have finished with it; however to all intents and purposes it no longer exists and will likely get destroyed imminently. If you do have references to resources hanging around after the ResourceManager is destroyed, you may get problems on destruction of these resources if they were relying on the manager (especially if it is a plugin). If you find you get problems on shutdown in the destruction of resources, try making sure you release all your references before you shutdown OGRE.
public Remove ( Axiom.Core.Resource resource ) : void
resource Axiom.Core.Resource The resource to remove
Résultat void

Remove() public méthode

public Remove ( System.UInt64 handle ) : void
handle System.UInt64 The Handle of the resource to remove
Résultat void

Remove() public méthode

public Remove ( string name ) : void
name string The name of the resource to remove
Résultat void

RemoveAll() public méthode

Removes all resources.
Removes all resources, meaning they will be removed from the list of valid resources in this manager, also causing them to be unloaded. The word 'Destroy' is not used here, since if any other pointers are referring to this resource, it will persist until they have finished with it; however to all intents and purposes it no longer exists and will likely get destroyed imminently. If you do have references to resources hanging around after the ResourceManager is destroyed, you may get problems on destruction of these resources if they were relying on the manager (especially if it is a plugin). If you find you get problems on shutdown in the destruction of resources, try making sure you release all your references before you shutdown Axiom.
public RemoveAll ( ) : void
Résultat void

ResourceExists() public méthode

Returns whether a resource with the given handle exists in this manager
public ResourceExists ( System.UInt64 handle ) : bool
handle System.UInt64 handle of the resource
Résultat bool

ResourceExists() public méthode

Returns whether the named resource exists in this manager
public ResourceExists ( string name ) : bool
name string name of the resource
Résultat bool

ResourceManager() protected méthode

Default constructor
protected ResourceManager ( ) : System
Résultat System

Unload() public méthode

Unloads a Resource from the managed resources list, calling it's Unload() method.
This method removes a resource from the list maintained by this manager, and unloads it from memory. It does NOT destroy the resource itself, although the memory used by it will be largely freed up. This would allow you to reload the resource again if you wished.
public Unload ( Resource resource ) : void
resource Resource
Résultat void

Unload() public méthode

public Unload ( System.UInt64 handle ) : void
handle System.UInt64 Handle of the resource
Résultat void

Unload() public méthode

Unloads a single resource by name.
Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.
public Unload ( string name ) : void
name string Name of the resource.
Résultat void

UnloadAll() public méthode

Unloads all resources.
Unloaded resources are not removed, they simply free up their memory as much as they can and wait to be reloaded. ResourceGroupManager for unloading of resource groups.
public UnloadAll ( ) : void
Résultat void

_add() protected méthode

Add a newly created resource to the manager
protected _add ( Resource res ) : void
res Resource
Résultat void

_create() protected abstract méthode

Create a new resource instance compatible with this manager (no custom parameters are populated at this point).
protected abstract _create ( string name, System.UInt64 handle, string group, bool isManual, IManualResourceLoader loader, NameValuePairList createParams ) : Resource
name string The unique name of the resource
handle System.UInt64
group string The name of the resource group to attach this new resource to
isManual bool /// Is this resource manually loaded? If so, you should really /// populate the loader parameter in order that the load process /// can call the loader back when loading is required. ///
loader IManualResourceLoader /// A ManualLoader implementation which will be called /// when the Resource wishes to load (should be supplied if you set /// isManual to true). You can in fact leave this parameter null /// if you wish, but the Resource will never be able to reload if /// anything ever causes it to unload. Therefore provision of a proper /// ManualLoader instance is strongly recommended. ///
createParams NameValuePairList /// If any parameters are required to create an instance, /// they should be supplied here as name / value pairs. These do not need /// to be set on the instance (handled elsewhere), just used if required /// to differentiate which concrete class is created. ///
Résultat Resource

_remove() protected méthode

Remove a resource from this manager; remove it from the lists.
protected _remove ( Resource res ) : void
res Resource
Résultat void

checkUsage() protected méthode

Makes sure we are still within budget.
protected checkUsage ( ) : void
Résultat void

dispose() protected méthode

Class level dispose method
When implementing this method in an inherited class the following template should be used; protected override void dispose( bool disposeManagedResources ) { if ( !isDisposed ) { if ( disposeManagedResources ) { // Dispose managed resources. } // There are no unmanaged resources to release, but // if we add them, they need to be released here. } // If it is available, make the call to the // base class's Dispose(Boolean) method base.dispose( disposeManagedResources ); }
protected dispose ( bool disposeManagedResources ) : void
disposeManagedResources bool True if Unmanaged resources should be released.
Résultat void

this() public méthode

Gets a resource with the given handle.
public this ( System.UInt64 handle ) : Resource
handle System.UInt64 Handle of the resource to retrieve.
Résultat Resource

this() public méthode

Gets a reference to the specified named resource.
public this ( string name ) : Resource
name string Name of the resource to retrieve.
Résultat Resource