diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-22 18:31:25 +0100 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-24 21:46:13 +0300 |
commit | b4e47fb41a19ca09c02bcd009b28cb7c3caa2256 (patch) | |
tree | eada17175623f6281a83aced143bb0940758a547 /src/resources/resourcemanager.cpp | |
parent | 80f61e80228aa0fa617961a4ec30d954fcb15eba (diff) | |
download | plus-b4e47fb41a19ca09c02bcd009b28cb7c3caa2256.tar.gz plus-b4e47fb41a19ca09c02bcd009b28cb7c3caa2256.tar.bz2 plus-b4e47fb41a19ca09c02bcd009b28cb7c3caa2256.tar.xz plus-b4e47fb41a19ca09c02bcd009b28cb7c3caa2256.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
Conflicts:
mana.files
src/CMakeLists.txt
src/resources/resourcemanager.cpp
src/resources/soundeffect.cpp
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r-- | src/resources/resourcemanager.cpp | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 3376394bc..c26526b97 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -35,6 +35,7 @@ #include "resources/spritedef.h" #include "utils/mkdir.h" +#include "utils/physfsrwops.h" #include <physfs.h> #include <SDL_image.h> @@ -42,6 +43,7 @@ #include <fstream> #include <iostream> #include <sstream> +#include <zlib.h> #include <sys/stat.h> #include <sys/time.h> @@ -397,19 +399,16 @@ struct ResourceLoader ResourceManager *manager; std::string path; ResourceManager::loader fun; + static Resource *load(void *v) { if (!v) return nullptr; ResourceLoader *l = static_cast< ResourceLoader * >(v); - int fileSize; - if (!l->manager) + SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); + if (!rw) return nullptr; - void *buffer = l->manager->loadFile(l->path, fileSize); - if (!buffer) - return nullptr; - Resource *res = l->fun(buffer, fileSize); - free(buffer); + Resource *res = l->fun(rw); return res; } }; @@ -451,16 +450,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 nullptr; } - 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; } @@ -695,18 +692,10 @@ void ResourceManager::saveTextFile(std::string path, std::string name, SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) { - int fileSize; - void *buffer = loadFile(filename, fileSize); - SDL_Surface *tmp = nullptr; - - if (buffer) - { - SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); - tmp = IMG_Load_RW(rw, 1); - ::free(buffer); - } - - return tmp; + SDL_Surface *surface = nullptr; + if (SDL_RWops *rw = PHYSFSRWOPS_openRead(filename.c_str())) + surface = IMG_Load_RW(rw, 1); + return surface; } void ResourceManager::scheduleDelete(SDL_Surface* surface) |