Mana
|
A class for loading and managing resources. More...
#include <resourcemanager.h>
Public Member Functions | |
ResourceManager () | |
~ResourceManager () | |
Destructor. | |
ResourceRef< Image > | getImage (const std::string &idPath) |
Loads the Image resource found at the given identifier path. | |
ResourceRef< Music > | getMusic (const std::string &path) |
Loads the Music resource found at the given path. | |
ResourceRef< SoundEffect > | getSoundEffect (const std::string &path) |
Loads the SoundEffect resource found at the given path. | |
ResourceRef< ImageSet > | getImageSet (const std::string &imagePath, int w, int h) |
Loads a image set based on the image referenced by the given path and the supplied sprite sizes. | |
ResourceRef< SpriteDef > | getSprite (const std::string &path, int variant=0) |
Loads a SpriteDef based on a given path and the supplied variant. | |
Static Public Member Functions | |
static bool | addToSearchPath (const std::string &path, bool append) |
Adds a directory or archive to the search path. | |
static void | searchAndAddArchives (const std::string &path, const std::string &ext, bool append) |
Searches for zip files and adds them to the search path. | |
static std::string | getPath (const std::string &file) |
Returns the real path to a file. | |
static ResourceManager * | getInstance () |
Returns an instance of the class, creating one if it does not already exist. | |
static void | deleteInstance () |
Deletes the class instance if it exists. | |
Private Member Functions | |
Resource * | get (const std::string &idPath, const std::function< Resource *()> &generator) |
Looks up a resource, creating it with the generator function if it does not exist. | |
void | release (Resource *) |
Releases a resource, placing it in the set of orphaned resources. | |
void | remove (Resource *) |
Removes a resource from the list of resources managed by the resource manager. | |
void | cleanOrphans () |
Static Private Member Functions | |
static void | cleanUp (Resource *resource) |
Deletes the resource after logging a cleanup message. | |
Private Attributes | |
std::map< std::string, Resource * > | mResources |
std::map< std::string, Resource * > | mOrphanedResources |
time_t | mOldestOrphan = 0 |
Static Private Attributes | |
static ResourceManager * | instance = nullptr |
Friends | |
class | Resource |
A class for loading and managing resources.
Definition at line 40 of file resourcemanager.h.
ResourceManager::ResourceManager | ( | ) |
Definition at line 46 of file resourcemanager.cpp.
ResourceManager::~ResourceManager | ( | ) |
Destructor.
Cleans up remaining resources, warning about resources that were still referenced.
Definition at line 51 of file resourcemanager.cpp.
|
static |
Adds a directory or archive to the search path.
If append is true then the directory is added to the end of the search path, otherwise it is added at the front.
true
on success, false
otherwise. Definition at line 130 of file resourcemanager.cpp.
|
private |
Definition at line 99 of file resourcemanager.cpp.
|
staticprivate |
Deletes the resource after logging a cleanup message.
Definition at line 85 of file resourcemanager.cpp.
|
static |
Deletes the class instance if it exists.
Definition at line 308 of file resourcemanager.cpp.
|
private |
Looks up a resource, creating it with the generator function if it does not exist.
Does not increment the reference count of the resource.
idPath | The resource identifier path. |
generator | A function for generating the resource. |
nullptr
if the resource could not be generated. Definition at line 182 of file resourcemanager.cpp.
ResourceRef< Image > ResourceManager::getImage | ( | const std::string & | idPath | ) |
Loads the Image resource found at the given identifier path.
The path can include a dye specification after a '|' character.
Definition at line 232 of file resourcemanager.cpp.
ResourceRef< ImageSet > ResourceManager::getImageSet | ( | const std::string & | imagePath, |
int | w, | ||
int | h | ||
) |
Loads a image set based on the image referenced by the given path and the supplied sprite sizes.
Definition at line 253 of file resourcemanager.cpp.
|
static |
Returns an instance of the class, creating one if it does not already exist.
Definition at line 300 of file resourcemanager.cpp.
ResourceRef< Music > ResourceManager::getMusic | ( | const std::string & | path | ) |
Loads the Music resource found at the given path.
Definition at line 212 of file resourcemanager.cpp.
|
static |
Returns the real path to a file.
Note that this method will always return a path, it does not check whether the file exists.
file | The file to get the real path to. |
Definition at line 163 of file resourcemanager.cpp.
ResourceRef< SoundEffect > ResourceManager::getSoundEffect | ( | const std::string & | path | ) |
Loads the SoundEffect resource found at the given path.
Definition at line 222 of file resourcemanager.cpp.
ResourceRef< SpriteDef > ResourceManager::getSprite | ( | const std::string & | path, |
int | variant = 0 |
||
) |
Loads a SpriteDef based on a given path and the supplied variant.
Definition at line 268 of file resourcemanager.cpp.
|
private |
Releases a resource, placing it in the set of orphaned resources.
Only called from Resource::decRef,
Definition at line 278 of file resourcemanager.cpp.
|
private |
Removes a resource from the list of resources managed by the resource manager.
Only called from Resource::decRef,
Definition at line 295 of file resourcemanager.cpp.
|
static |
Searches for zip files and adds them to the search path.
Definition at line 141 of file resourcemanager.cpp.
|
friend |
Definition at line 42 of file resourcemanager.h.
|
staticprivate |
Definition at line 149 of file resourcemanager.h.
|
private |
Definition at line 152 of file resourcemanager.h.
|
private |
Definition at line 151 of file resourcemanager.h.
|
private |
Definition at line 150 of file resourcemanager.h.