00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef RESOURCE_MANAGER_H
00023 #define RESOURCE_MANAGER_H
00024
00025 #include <ctime>
00026 #include <map>
00027 #include <string>
00028 #include <vector>
00029
00030 class Image;
00031 class ImageSet;
00032 class Music;
00033 class Resource;
00034 class SoundEffect;
00035 class SpriteDef;
00036 struct SDL_Surface;
00037
00041 class ResourceManager
00042 {
00043 friend class Resource;
00044
00045 public:
00046
00047 typedef Resource *(*loader)(void *, unsigned);
00048 typedef Resource *(*generator)(void *);
00049
00050 ResourceManager();
00051
00056 ~ResourceManager();
00057
00064 bool setWriteDir(const std::string &path);
00065
00073 bool addToSearchPath(const std::string &path, bool append);
00074
00078 void searchAndAddArchives(const std::string &path,
00079 const std::string &ext,
00080 bool append);
00081
00085 bool mkdir(const std::string &path);
00086
00090 bool exists(const std::string &path);
00091
00095 bool isDirectory(const std::string &path);
00096
00104 std::string getPath(const std::string &file);
00105
00115 Resource *get(const std::string &idPath, generator fun, void *data);
00116
00125 Resource *load(const std::string &path, loader fun);
00126
00136 bool copyFile(const std::string &src, const std::string &dst);
00137
00142 Image *getImage(const std::string &idPath);
00143
00148 Music *getMusic(const std::string &idPath);
00149
00154 SoundEffect *getSoundEffect(const std::string &idPath);
00155
00160 ImageSet *getImageSet(const std::string &imagePath, int w, int h);
00161
00166 SpriteDef *getSprite(const std::string &path, int variant = 0);
00167
00171 void release(Resource *);
00172
00183 void *loadFile(const std::string &fileName, int &fileSize);
00184
00188 std::vector<std::string> loadTextFile(const std::string &fileName);
00189
00194 SDL_Surface *loadSDLSurface(const std::string &filename);
00195
00200 static ResourceManager *getInstance();
00201
00205 static void deleteInstance();
00206
00207 private:
00211 static void cleanUp(Resource *resource);
00212
00213 void cleanOrphans();
00214
00215 static ResourceManager *instance;
00216 typedef std::map<std::string, Resource*> Resources;
00217 typedef Resources::iterator ResourceIterator;
00218 Resources mResources;
00219 Resources mOrphanedResources;
00220 time_t mOldestOrphan;
00221 };
00222
00223 #endif