Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
resource::ResourceManager Class Reference

#include <ResourceManager.h>

Inheritance diagram for resource::ResourceManager:
engine::Object core::Singleton< ResourceManager >

List of all members.

Public Member Functions

void addLoadEventReceiver (LoadEventReceiver *newEventReceiver)
void addSearchPath (const std::string &path, const std::string &type)
 Adds a relative path to search for resources.
ResourcecreateResource (const ResourceType &type, const std::string &filename)
 Creates a resource.
Resourcefind (const u32 &id)
 Retrieves a pointer to a resource by id, or null if the resource does not exist.
Resourcefind (const ResourceType &type, const u32 &id)
 Retrieves a pointer to a resource by type and by id, or null if the resource does not exist.
u32 getMemoryBudget () const
 Get the limit on the amount of memory in bytes the resource manager may use.
u32 getMemoryUsage () const
 Gets the current memory usage, in bytes.
bool loadResource (Resource *resource)
void loadResources ()
 Load all resource waiting for load.
DataStreamopenResource (const std::string &filename)
void registerResourceFactory (const ResourceType &type, ResourceFactory *factory)
void registerSerializer (const ResourceType &type, Serializer *serializer)
bool reloadResource (Resource *resource)
void removeAllResources ()
void removeLoadEventReceiver (LoadEventReceiver *oldEventReceiver)
void removeResource (Resource *resource)
 Remove a Resource from the managed resources list, calling it's unload() method.
void removeResource (const u32 &id)
void removeResourceFactory (const ResourceType &type)
void removeSerializer (const ResourceType &type)
 ResourceManager ()
void setPaths (const std::string &resourcesfile)
void start ()
void stop ()
void unloadResource (Resource *resource)
void unloadResources ()
 Unload all resources.
 ~ResourceManager ()

Static Public Member Functions

static ResourceManagergetInstance ()
 Get instance.

Protected Member Functions

void fireLoadEnded ()
void fireLoadStarted ()
void fireLoadUpdate ()
void initializeImpl ()
void uninitializeImpl ()
void updateImpl (f32 elapsedTime)

Protected Attributes

core::ConfigFilemConfigFile
std::map< std::string,
platform::FileSystem * > 
mFiles
u32 mLoadedSize
LoadEventmLoadEvent
std::list< LoadEventReceiver * > mLoadEventReceivers
std::vector< std::list
< Resource * > > 
mLoadResources
 Central lists of resources for loading created in order of type.
u32 mMemoryBudget
u32 mMemoryUsage
std::vector< ResourceFactory * > mResourceFactories
std::map< u32, Resource * > mResources
 Central list of resources - for easy memory management and lookup.
std::map< std::string, Resource * > mResourcesByFilename
std::vector< Serializer * > mSerializers
u32 mTotalLoadSize

Detailed Description

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 temporaily unload some resources if it needs to to stay within this budget.


Constructor & Destructor Documentation

resource::ResourceManager::ResourceManager ( )
resource::ResourceManager::~ResourceManager ( )

Member Function Documentation

void resource::ResourceManager::addLoadEventReceiver ( LoadEventReceiver newEventReceiver)

References mLoadEventReceivers.

void resource::ResourceManager::addSearchPath ( const std::string &  path,
const std::string &  type 
)

Adds a relative path to search for resources.

References getInstance(), platform::FileSystem::list(), and mFiles.

Referenced by setPaths().

Resource * resource::ResourceManager::createResource ( const ResourceType type,
const std::string &  filename 
)
Resource * resource::ResourceManager::find ( const u32 id)

Retrieves a pointer to a resource by id, or null if the resource does not exist.

References mResources.

Resource * resource::ResourceManager::find ( const ResourceType type,
const u32 id 
)

Retrieves a pointer to a resource by type and by id, or null if the resource does not exist.

References mResources.

void resource::ResourceManager::fireLoadEnded ( ) [protected]
void resource::ResourceManager::fireLoadStarted ( ) [protected]
void resource::ResourceManager::fireLoadUpdate ( ) [protected]
ResourceManager * resource::ResourceManager::getInstance ( ) [static]
u32 resource::ResourceManager::getMemoryBudget ( ) const

Get the limit on the amount of memory in bytes the resource manager may use.

References mMemoryBudget.

u32 resource::ResourceManager::getMemoryUsage ( ) const

Gets the current memory usage, in bytes.

References mMemoryUsage.

void resource::ResourceManager::initializeImpl ( ) [protected, virtual]

Reimplemented from engine::Object.

References getInstance(), and mMemoryBudget.

bool resource::ResourceManager::loadResource ( Resource resource)
void resource::ResourceManager::loadResources ( )
DataStream * resource::ResourceManager::openResource ( const std::string &  filename)
void resource::ResourceManager::registerResourceFactory ( const ResourceType type,
ResourceFactory factory 
)

References mResourceFactories.

void resource::ResourceManager::registerSerializer ( const ResourceType type,
Serializer serializer 
)

References mSerializers.

bool resource::ResourceManager::reloadResource ( Resource resource)
void resource::ResourceManager::removeAllResources ( )
void resource::ResourceManager::removeLoadEventReceiver ( LoadEventReceiver oldEventReceiver)

References mLoadEventReceivers.

void resource::ResourceManager::removeResource ( Resource resource)

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

References engine::Object::getID().

void resource::ResourceManager::removeResource ( const u32 id)
void resource::ResourceManager::removeResourceFactory ( const ResourceType type)

References mResourceFactories.

void resource::ResourceManager::removeSerializer ( const ResourceType type)

References mSerializers.

void resource::ResourceManager::setPaths ( const std::string &  resourcesfile)

Method reads a resource configuration file and instantiates all found resource search paths.

Parameters:
resourcesfile,:The file that contains resources information.

References addSearchPath(), core::ConfigFile::getSettingsBegin(), core::ConfigFile::getSettingsEnd(), core::ConfigFile::load(), and mConfigFile.

Referenced by engine::EngineManager::setPaths().

void resource::ResourceManager::start ( )
void resource::ResourceManager::stop ( )
void resource::ResourceManager::uninitializeImpl ( ) [protected, virtual]
void resource::ResourceManager::unloadResource ( Resource resource)
void resource::ResourceManager::unloadResources ( )
void resource::ResourceManager::updateImpl ( f32  elapsedTime) [protected, virtual]

Reimplemented from engine::Object.

References mResources, and engine::Object::update().


Member Data Documentation

Referenced by ResourceManager(), and setPaths().

std::map<std::string, platform::FileSystem*> resource::ResourceManager::mFiles [protected]
std::vector<std::list<Resource*> > resource::ResourceManager::mLoadResources [protected]

Central lists of resources for loading created in order of type.

Referenced by createResource(), loadResources(), removeResource(), ResourceManager(), and uninitializeImpl().

Central list of resources - for easy memory management and lookup.

Referenced by createResource(), find(), removeAllResources(), removeResource(), unloadResources(), and updateImpl().

std::map<std::string, Resource*> resource::ResourceManager::mResourcesByFilename [protected]

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

The KG Game Engine
The KG Game Engine Documentation © 2006-2011 by Kat'Oun. Generated on Sat Jul 2 2011 00:50:10 by Doxygen (1.7.4)