summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index c7552b9b7..c26526b97 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -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 0;
+ 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)