diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-22 18:31:25 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-24 19:05:14 +0100 |
commit | dd1386684b6430337d3b270bec1ca53fa69f9593 (patch) | |
tree | 68ec0caa9e81af7ebd38f45e4a9fcbf8ed35625c /src/resources/resourcemanager.cpp | |
parent | 8a4b82e3ed75e426d44b69640f009e1e731c75c4 (diff) | |
download | mana-dd1386684b6430337d3b270bec1ca53fa69f9593.tar.gz mana-dd1386684b6430337d3b270bec1ca53fa69f9593.tar.bz2 mana-dd1386684b6430337d3b270bec1ca53fa69f9593.tar.xz mana-dd1386684b6430337d3b270bec1ca53fa69f9593.zip |
Use SDL_RWops directly on top of PhysFS
This avoids the creation of a temporary buffer containing a complete
file for the sole purpose of wrapping it up in an SDL_RWops.
The necessary wrapper is by Ryan C. Gordon and is included in the
PhysFS repository under 'extras'.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r-- | src/resources/resourcemanager.cpp | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 00e4726e..c7e20111 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -32,6 +32,7 @@ #include "resources/spritedef.h" #include "utils/zlib.h" +#include "utils/physfsrwops.h" #include <physfs.h> @@ -273,14 +274,14 @@ struct ResourceLoader ResourceManager *manager; std::string path; ResourceManager::loader fun; + static Resource *load(void *v) { ResourceLoader *l = static_cast< ResourceLoader * >(v); - int fileSize; - void *buffer = l->manager->loadFile(l->path, fileSize); - if (!buffer) return NULL; - Resource *res = l->fun(buffer, fileSize); - free(buffer); + SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); + if (!rw) + return NULL; + Resource *res = l->fun(rw); return res; } }; @@ -316,16 +317,14 @@ struct DyedImageLoader d = new Dye(path.substr(p + 1)); path = path.substr(0, p); } - int fileSize; - void *buffer = l->manager->loadFile(path, fileSize); - if (!buffer) + SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str()); + if (!rw) { delete d; return NULL; } - Resource *res = d ? Image::load(buffer, fileSize, *d) - : Image::load(buffer, fileSize); - free(buffer); + Resource *res = d ? Image::load(rw, *d) + : Image::load(rw); delete d; return res; } @@ -520,18 +519,10 @@ std::vector<std::string> ResourceManager::loadTextFile( SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) { - int fileSize; - void *buffer = loadFile(filename, fileSize); - SDL_Surface *tmp = NULL; - - if (buffer) - { - SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); - tmp = IMG_Load_RW(rw, 1); - ::free(buffer); - } - - return tmp; + SDL_Surface *surface = 0; + if (SDL_RWops *rw = PHYSFSRWOPS_openRead(filename.c_str())) + surface = IMG_Load_RW(rw, 1); + return surface; } void ResourceManager::scheduleDelete(SDL_Surface* surface) |