diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-08 22:09:07 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-09 23:47:51 +0100 |
commit | 32996cee607c52ecef9be4638df554dd89b39c24 (patch) | |
tree | b3c9987ea39b52e46e5969f938c3aa9002a4bd4c /src/resources/resourcemanager.h | |
parent | 8aeb42b16430c85e4bc4052d881b8335d4a2ff36 (diff) | |
download | mana-32996cee607c52ecef9be4638df554dd89b39c24.tar.gz mana-32996cee607c52ecef9be4638df554dd89b39c24.tar.bz2 mana-32996cee607c52ecef9be4638df554dd89b39c24.tar.xz mana-32996cee607c52ecef9be4638df554dd89b39c24.zip |
Fixed wallpaper prescaling issues
Image::SDLgetScaledImage was changed so that it tries to find an existing
scaled version of the image first, and generates it when none exists.
When it needs to generate one, this resource is added to the resource
manager, partly to avoid duplicating the work later but mainly to keep
memory management straightforward.
This function also used to leak the scaled SDL_Surface since it wrongly
assumed that Image::load would free it.
To avoid filling up the memory with scaled wallpapers that are waiting
30 seconds until they will be deleted, the Resource::decRef function was
extended with a parameter that allows telling it what to do with orphans.
Calling decRef with Resource::DeleteImmediately will delete the resource
immediately in case the resource is orphaned.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/resources/resourcemanager.h')
-rw-r--r-- | src/resources/resourcemanager.h | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 5295be5c..5abc81e2 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -107,6 +107,16 @@ class ResourceManager std::string getPath(const std::string &file); /** + * Returns the resource with the specified idPath, or 0 when no such + * resource is available. Increments the reference count. + * + * @param idPath The resource identifier path. + * @return A valid resource or <code>NULL</code> if the resource could + * not be found. + */ + Resource *get(const std::string &idPath); + + /** * Creates a resource and adds it to the resource map. * * @param idPath The resource identifier path. @@ -178,11 +188,6 @@ class ResourceManager SpriteDef *getSprite(const std::string &path, int variant = 0); /** - * Releases a resource, placing it in the set of orphaned resources. - */ - void release(Resource *); - - /** * Allocates data into a buffer pointer for raw data loading. The * returned data is expected to be freed using <code>free()</code>. * @@ -225,6 +230,18 @@ class ResourceManager private: /** + * Releases a resource, placing it in the set of orphaned resources. + * Only called from Resource::decRef, + */ + void release(Resource *); + + /** + * Removes a resource from the list of resources managed by the + * resource manager. Only called from Resource::decRef, + */ + void remove(Resource *); + + /** * Deletes the resource after logging a cleanup message. */ static void cleanUp(Resource *resource); |