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