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
ファイルを表示 Open project: WolfgangSt/axiom Class Usage Examples

Public Methods

Method 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.

Protected Methods

Method 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 method

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
return Axiom.Core.Resource

Create() public method

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
return Axiom.Core.Resource

Create() public method

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
return Axiom.Core.Resource

CreateOrRetrieve() public method

public CreateOrRetrieve ( string name, string group ) : Tuple,Axiom.Math
name string
group string
return Tuple,Axiom.Math

CreateOrRetrieve() public method

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
return Tuple,Axiom.Math

GetByHandle() public method

public GetByHandle ( System.UInt64 handle ) : Axiom.Core.Resource
handle System.UInt64
return Axiom.Core.Resource

GetByName() public method

public GetByName ( string name ) : Axiom.Core.Resource
name string
return Axiom.Core.Resource

Load() public method

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
return Axiom.Core.Resource

Load() public method

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. ///
return Axiom.Core.Resource

Load() public method

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. ///
return Axiom.Core.Resource

NotifyResourceLoaded() public method

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
return void

NotifyResourceTouched() public method

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
return void

NotifyResourceUnloaded() public method

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
return void

ParseScript() public method

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
return void

ReloadAll() public method

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
return void

Remove() public method

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
return void

Remove() public method

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

Remove() public method

public Remove ( string name ) : void
name string The name of the resource to remove
return void

RemoveAll() public method

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
return void

ResourceExists() public method

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
return bool

ResourceExists() public method

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

ResourceManager() protected method

Default constructor
protected ResourceManager ( ) : System
return System

Unload() public method

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
return void

Unload() public method

public Unload ( System.UInt64 handle ) : void
handle System.UInt64 Handle of the resource
return void

Unload() public method

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.
return void

UnloadAll() public method

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
return void

_add() protected method

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

_create() protected abstract method

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. ///
return Resource

_remove() protected method

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

checkUsage() protected method

Makes sure we are still within budget.
protected checkUsage ( ) : void
return void

dispose() protected method

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.
return void

this() public method

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

this() public method

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