Urho3D
Public Member Functions | Private Member Functions | Private Attributes
Urho3D::ResourceCache Class Reference

Resource cache subsystem. Loads resources on demand and stores them for later access. More...

#include <ResourceCache.h>

Inheritance diagram for Urho3D::ResourceCache:
Urho3D::Object Urho3D::RefCounted

List of all members.

Public Member Functions

 ResourceCache (Context *context)
 Construct.
virtual ~ResourceCache ()
 Destruct. Free all resources.
bool AddResourceDir (const String &pathName)
 Add a resource load directory.
void AddPackageFile (PackageFile *package, bool addAsFirst=false)
 Add a package file for loading resources from.
bool AddManualResource (Resource *resource)
 Add a manually created resource. Must be uniquely named.
void RemoveResourceDir (const String &pathName)
 Remove a resource load directory.
void RemovePackageFile (PackageFile *package, bool releaseResources=true, bool forceRelease=false)
 Remove a package file. Optionally release the resources loaded from it.
void RemovePackageFile (const String &fileName, bool releaseResources=true, bool forceRelease=false)
 Remove a package file by name. Optionally release the resources loaded from it.
void ReleaseResource (ShortStringHash type, const String &name, bool force=false)
 Release a resource by name.
void ReleaseResource (ShortStringHash type, StringHash nameHash, bool force=false)
 Release a resource by name hash.
void ReleaseResources (ShortStringHash type, bool force=false)
 Release all resources of a specific type.
void ReleaseResources (ShortStringHash type, const String &partialName, bool force=false)
 Release resources of a specific type and partial name.
void ReleaseAllResources (bool force=false)
 Release all resources.
bool ReloadResource (Resource *resource)
 Reload a resource. Return false and release it if fails.
void SetMemoryBudget (ShortStringHash type, unsigned budget)
 Set memory budget for a specific resource type, default 0 is unlimited.
void SetAutoReloadResources (bool enable)
 Enable or disable automatic reloading of resources as files are modified.
SharedPtr< FileGetFile (const String &name)
 Open and return a file from the resource load paths or from inside a package file. If not found, use a fallback search with absolute path. Return null if fails.
ResourceGetResource (ShortStringHash type, const String &name)
 Return a resource by type and name. Load if not loaded yet. Return null if fails.
ResourceGetResource (ShortStringHash type, StringHash nameHash)
 Return a resource by type and name hash. Load if not loaded yet. Return null if fails.
void GetResources (PODVector< Resource * > &result, ShortStringHash type) const
 Return all loaded resources of a specific type.
const HashMap< ShortStringHash,
ResourceGroup > & 
GetAllResources () const
 Return all loaded resources.
const Vector< String > & GetResourceDirs () const
 Return added resource load directories.
const Vector< SharedPtr
< PackageFile > > & 
GetPackageFiles () const
 Return added package files.
template<class T >
T * GetResource (const String &name)
 Template version of returning a resource by name.
template<class T >
T * GetResource (StringHash nameHash)
 Template version of returning a resource by name hash.
template<class T >
void GetResources (PODVector< T * > &result) const
 Template version of returning loaded resources of a specific type.
bool Exists (const String &name) const
 Return whether a file exists by name.
bool Exists (StringHash nameHash) const
 Return whether a file exists by name hash.
unsigned GetMemoryBudget (ShortStringHash type) const
 Return memory budget for a resource type.
unsigned GetMemoryUse (ShortStringHash type) const
 Return total memory use for a resource type.
unsigned GetTotalMemoryUse () const
 Return total memory use for all resources.
const StringGetResourceName (StringHash nameHash) const
 Return resource name from hash, or empty if not found.
String GetResourceFileName (const String &name) const
 Return full absolute file name of resource if possible.
bool GetAutoReloadResources () const
 Return whether automatic resource reloading is enabled.
String GetPreferredResourceDir (const String &path) const
 Return either the path itself or its parent, based on which of them has recognized resource subdirectories.
String SanitateResourceName (const String &name) const
 Remove unsupported constructs from the resource name to prevent ambiguity.
void StoreNameHash (const String &name)
 Store a hash-to-name mapping.
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
virtual ShortStringHash GetType () const =0
 Return type hash.
virtual const StringGetTypeName () const =0
 Return type name.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
ContextGetContext () const
 Return execution context.
ObjectGetSubsystem (ShortStringHash type) const
 Return subsystem by type.
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
int Refs () const
 Return reference count.
int WeakRefs () const
 Return weak reference count.
RefCountRefCountPtr ()
 Return pointer to the reference count structure.

Private Member Functions

 OBJECT (ResourceCache)
const SharedPtr< Resource > & FindResource (ShortStringHash type, StringHash nameHash)
 Find a resource.
void ReleasePackageResources (PackageFile *package, bool force=false)
 Release resources loaded from a package file.
void UpdateResourceGroup (ShortStringHash type)
 Update a resource group. Recalculate memory use and release resources if over memory budget.
void HandleBeginFrame (StringHash eventType, VariantMap &eventData)
 Handle begin frame event. Automatic resource reloads are processed here.

Private Attributes

HashMap< ShortStringHash,
ResourceGroup
resourceGroups_
 Resources by type.
Vector< StringresourceDirs_
 Resource load directories.
Vector< SharedPtr< FileWatcher > > fileWatchers_
 File watchers for resource directories, if automatic reloading enabled.
Vector< SharedPtr< PackageFile > > packages_
 Package files.
HashMap< StringHash, StringhashToName_
 Mapping of hashes to filenames.
bool autoReloadResources_
 Automatic resource reloading flag.

Additional Inherited Members

- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.

Detailed Description

Resource cache subsystem. Loads resources on demand and stores them for later access.


The documentation for this class was generated from the following files: