| [4597] | 1 | /*! | 
|---|
| [5039] | 2 |  * @file resource_manager.h | 
|---|
| [4836] | 3 |   *  The Resource Manager checks if a file/resource is loaded. | 
|---|
| [3329] | 4 |  | 
|---|
| [4597] | 5 |     If a file/resource was already loaded the resourceManager will | 
|---|
| [3655] | 6 |     return a void pointer to the desired resource. | 
|---|
 | 7 |     Otherwise it will instruct the coresponding resource-loader to load, | 
|---|
 | 8 |     and receive a pointer to it. | 
|---|
| [4534] | 9 |  | 
|---|
 | 10 |     it is possible to compile the resource Manager without some modules by | 
|---|
| [4597] | 11 |     just adding the compile flag -D.... | 
|---|
| [4534] | 12 |     (NO_MODEL) | 
|---|
 | 13 |     (NO_AUDIO) | 
|---|
 | 14 |     (NO_TEXT) | 
|---|
 | 15 |     (NO_TEXTURES) | 
|---|
| [3245] | 16 | */ | 
|---|
| [1853] | 17 |  | 
|---|
| [3655] | 18 | #ifndef _RESOURCE_MANAGER_H | 
|---|
 | 19 | #define _RESOURCE_MANAGER_H | 
|---|
| [1853] | 20 |  | 
|---|
| [3543] | 21 | #include "base_object.h" | 
|---|
| [1853] | 22 |  | 
|---|
| [4381] | 23 |  | 
|---|
| [6222] | 24 | #include <list> | 
|---|
| [3660] | 25 |  | 
|---|
| [4462] | 26 | //! An eumerator for different fileTypes the resourceManager supports | 
|---|
| [4597] | 27 | typedef enum ResourceType | 
|---|
 | 28 | { | 
|---|
| [4534] | 29 | #ifndef NO_MODEL | 
|---|
 | 30 |   OBJ,                  //!< loading .obj file | 
|---|
 | 31 |   PRIM,                 //!< loading primitive model | 
|---|
 | 32 |   MD2,                  //!< loading md2-file | 
|---|
 | 33 | #endif /* NO_MODEL */ | 
|---|
| [4653] | 34 | #ifndef NO_TEXT | 
|---|
 | 35 |   TTF,                  //!< loading a TrueTypeFont | 
|---|
 | 36 | #endif /* NO_TEXT */ | 
|---|
| [4534] | 37 | #ifndef NO_AUDIO | 
|---|
 | 38 |   WAV,                  //!< loading wav | 
|---|
 | 39 |   MP3,                  //!< loading mp3 | 
|---|
 | 40 |   OGG,                  //!< loading ogg | 
|---|
 | 41 | #endif /* NO_AUDIO */ | 
|---|
 | 42 | #ifndef NO_TEXTURES | 
|---|
| [5323] | 43 |   IMAGE,                //!< loading an image | 
|---|
| [4534] | 44 | #endif /* NO_TEXTURES */ | 
|---|
| [5323] | 45 | #ifndef NO_SHADERS | 
|---|
 | 46 |   SHADER,               //!< openGL-shader program | 
|---|
 | 47 | #endif /* NO_SHADERS */ | 
|---|
| [4534] | 48 | }; | 
|---|
| [4462] | 49 |  | 
|---|
| [4597] | 50 | //! An enumerator for different UNLOAD-types. | 
|---|
| [3660] | 51 | /** | 
|---|
| [4462] | 52 |    RP_NO:        will be unloaded on request | 
|---|
 | 53 |    RP_LEVEL:     will be unloaded at the end of a Level | 
|---|
 | 54 |    RP_CAMPAIGN:  will be unloaded at the end of a Campaign | 
|---|
 | 55 |    RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox) | 
|---|
| [3660] | 56 | */ | 
|---|
| [4597] | 57 | typedef enum ResourcePriority | 
|---|
 | 58 | { | 
|---|
 | 59 |   RP_NO        =   0, | 
|---|
 | 60 |   RP_LEVEL     =   1, | 
|---|
 | 61 |   RP_CAMPAIGN  =   2, | 
|---|
 | 62 |   RP_GAME      =   4 | 
|---|
 | 63 | }; | 
|---|
| [3543] | 64 |  | 
|---|
| [3660] | 65 | //! A Struct that keeps track about A resource its name its Type, and so on | 
|---|
| [3658] | 66 | struct Resource | 
|---|
 | 67 | { | 
|---|
| [5304] | 68 |   BaseObject*       pointer;           //!< Pointer to the Resource. | 
|---|
| [5308] | 69 |   unsigned int      count;             //!< How many times this Resource has been loaded. | 
|---|
| [4597] | 70 |  | 
|---|
| [4465] | 71 |   char*             name;              //!< Name of the Resource. | 
|---|
 | 72 |   ResourceType      type;              //!< ResourceType of this Resource. | 
|---|
 | 73 |   ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased) | 
|---|
| [3790] | 74 |  | 
|---|
 | 75 |   // more specific | 
|---|
| [4637] | 76 |   float             modelSize;         //!< the size of the model (OBJ/PRIM) | 
|---|
| [4534] | 77 | #ifndef NO_MODEL | 
|---|
| [5323] | 78 |   char*             secFileName;       //!< a seconf fileName | 
|---|
| [4534] | 79 | #endif /* NO_MODEL */ | 
|---|
 | 80 | #ifndef NO_TEXT | 
|---|
| [4465] | 81 |   unsigned int      ttfSize;           //!< the size of the ttf-font (TTF) | 
|---|
| [4534] | 82 | #endif /* NO_TEXT */ | 
|---|
| [3658] | 83 | }; | 
|---|
| [3543] | 84 |  | 
|---|
| [2036] | 85 |  | 
|---|
| [3655] | 86 | //! The ResourceManager is a class, that decides if a file/resource should be loaded | 
|---|
| [3329] | 87 | /** | 
|---|
| [5308] | 88 |  * If a file/resource was already loaded the resourceManager will | 
|---|
 | 89 |  * return a pointer to the desired resource. | 
|---|
 | 90 |  * Otherwise it will instruct the corresponding resource-loader to load, | 
|---|
 | 91 |  * and receive the pointer to it. | 
|---|
 | 92 |  * | 
|---|
 | 93 |  * It does it by looking, if a desired file has already been loaded. | 
|---|
 | 94 |  * There is also the possibility to check for some variables | 
|---|
 | 95 |  */ | 
|---|
| [4597] | 96 | class ResourceManager : public BaseObject | 
|---|
| [3655] | 97 | { | 
|---|
| [1904] | 98 |  public: | 
|---|
| [3655] | 99 |   virtual ~ResourceManager(); | 
|---|
| [4836] | 100 |   /** @returns a Pointer to the only object of this Class */ | 
|---|
| [4746] | 101 |   inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; }; | 
|---|
| [1853] | 102 |  | 
|---|
| [3883] | 103 |   bool setDataDir(const char* dataDir); | 
|---|
| [4836] | 104 |   /** @returns the Name of the data directory */ | 
|---|
| [5308] | 105 |   inline const char* getDataDir() const { return this->dataDir; }; | 
|---|
| [4166] | 106 |  | 
|---|
| [5480] | 107 |  | 
|---|
 | 108 |   bool tryDataDir(const char* dataDir); | 
|---|
 | 109 |   bool verifyDataDir(const char* fileInside); | 
|---|
 | 110 |   bool addImageDir(const char* imageDir); | 
|---|
| [5304] | 111 |   BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO, | 
|---|
| [5306] | 112 |                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); | 
|---|
| [5304] | 113 |   BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, | 
|---|
| [5306] | 114 |                void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); | 
|---|
| [3672] | 115 |   bool unload(void* pointer, ResourcePriority prio = RP_NO); | 
|---|
 | 116 |   bool unload(Resource* resource, ResourcePriority = RP_NO); | 
|---|
 | 117 |   bool unloadAllByPriority(ResourcePriority prio); | 
|---|
| [4597] | 118 |  | 
|---|
| [5994] | 119 |   Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const; | 
|---|
 | 120 |   Resource* locateResourceByPointer(const void* pointer) const; | 
|---|
 | 121 |  | 
|---|
| [4746] | 122 |   void debug() const; | 
|---|
| [3245] | 123 |  | 
|---|
| [4597] | 124 |  | 
|---|
| [5480] | 125 |   // utility functions for handling files in and around the data-directory | 
|---|
| [3983] | 126 |   static bool isDir(const char* directory); | 
|---|
| [4032] | 127 |   static bool isFile(const char* fileName); | 
|---|
 | 128 |   static bool touchFile(const char* fileName); | 
|---|
 | 129 |   static bool deleteFile(const char* fileName); | 
|---|
| [4166] | 130 |   static char* homeDirCheck(const char* fileName); | 
|---|
 | 131 |   static char* getFullName(const char* fileName); | 
|---|
| [5335] | 132 |   static bool isInDataDir(const char* fileName); | 
|---|
| [3983] | 133 |  | 
|---|
| [5306] | 134 |   static const char* ResourceTypeToChar(ResourceType type); | 
|---|
 | 135 |  | 
|---|
| [5480] | 136 |  | 
|---|
| [3245] | 137 |  private: | 
|---|
| [3655] | 138 |   ResourceManager(); | 
|---|
| [3245] | 139 |  | 
|---|
| [4465] | 140 |  private: | 
|---|
 | 141 |   static ResourceManager*  singletonRef;       //!< singleton Reference | 
|---|
| [3672] | 142 |  | 
|---|
| [5308] | 143 |   char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored. | 
|---|
| [6222] | 144 |   std::list<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded. | 
|---|
 | 145 |   std::list<char*>         imageDirs;          //!< A list of directories in which images are stored. | 
|---|
| [4465] | 146 |  | 
|---|
| [1853] | 147 | }; | 
|---|
 | 148 |  | 
|---|
| [3655] | 149 | #endif /* _RESOURCE_MANAGER_H */ | 
|---|