[3245] | 1 | /*! |
---|
[3655] | 2 | \file resource_manager.h |
---|
| 3 | \brief The Resource Manager checks if a file/resource is loaded. |
---|
[3329] | 4 | |
---|
[3655] | 5 | If a file/resource was already loaded the resourceManager will |
---|
| 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. |
---|
[3245] | 9 | */ |
---|
[1853] | 10 | |
---|
[3655] | 11 | #ifndef _RESOURCE_MANAGER_H |
---|
| 12 | #define _RESOURCE_MANAGER_H |
---|
[1853] | 13 | |
---|
[3543] | 14 | #include "base_object.h" |
---|
[1853] | 15 | |
---|
[3911] | 16 | // FORWARD DEFINITION |
---|
| 17 | template<class T> class tList; |
---|
[3660] | 18 | |
---|
| 19 | //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support |
---|
[3790] | 20 | enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE}; |
---|
[3660] | 21 | //! An enumerator for different UNLOAD-types. |
---|
| 22 | /** |
---|
| 23 | RP_NO: will be unloaded on request |
---|
| 24 | RP_LEVEL: will be unloaded at the end of a Level |
---|
| 25 | RP_CAMPAIGN: will be unloaded at the end of a Campaign |
---|
| 26 | RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) |
---|
| 27 | */ |
---|
| 28 | enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3}; |
---|
[3543] | 29 | |
---|
[3660] | 30 | //! A Struct that keeps track about A resource its name its Type, and so on |
---|
[3658] | 31 | struct Resource |
---|
| 32 | { |
---|
| 33 | void* pointer; //!< Pointer to the Resource. |
---|
[3790] | 34 | int count; //!< How many times this Resource has been loaded. |
---|
[3658] | 35 | |
---|
| 36 | char* name; //!< Name of the Resource. |
---|
| 37 | ResourceType type; //!< ResourceType of this Resource. |
---|
[3660] | 38 | ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) |
---|
[3790] | 39 | |
---|
| 40 | // more specific |
---|
| 41 | float modelSize; |
---|
| 42 | unsigned int ttfSize; |
---|
| 43 | unsigned char ttfColorR; |
---|
| 44 | unsigned char ttfColorG; |
---|
| 45 | unsigned char ttfColorB; |
---|
[3658] | 46 | }; |
---|
[3543] | 47 | |
---|
[2036] | 48 | |
---|
[3655] | 49 | //! The ResourceManager is a class, that decides if a file/resource should be loaded |
---|
[3329] | 50 | /** |
---|
[3655] | 51 | If a file/resource was already loaded the resourceManager will |
---|
| 52 | return a void pointer to the desired resource. |
---|
| 53 | Otherwise it will instruct the corresponding resource-loader to load, |
---|
| 54 | and receive the pointer to it. |
---|
| 55 | |
---|
| 56 | It does it by looking, if a desired file has already been loaded. |
---|
[3790] | 57 | |
---|
| 58 | \todo loading also dependant by parameters. |
---|
[3329] | 59 | */ |
---|
[3655] | 60 | class ResourceManager : public BaseObject |
---|
| 61 | { |
---|
[1904] | 62 | public: |
---|
[3655] | 63 | static ResourceManager* getInstance(); |
---|
| 64 | virtual ~ResourceManager(); |
---|
[1853] | 65 | |
---|
[3883] | 66 | bool setDataDir(const char* dataDir); |
---|
[4091] | 67 | /** \returns the Name of the data directory */ |
---|
[4115] | 68 | inline const char* getDataDir(void) {return this->dataDir;} |
---|
[4091] | 69 | bool checkDataDir(const char* fileInside); |
---|
[3672] | 70 | bool addImageDir(char* imageDir); |
---|
[3790] | 71 | void* load(const char* fileName, ResourcePriority prio = RP_NO, |
---|
| 72 | void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); |
---|
| 73 | void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO, |
---|
| 74 | void* param1 = NULL, void* param2 = NULL, void* param3 = NULL); |
---|
[3672] | 75 | bool unload(void* pointer, ResourcePriority prio = RP_NO); |
---|
| 76 | bool unload(Resource* resource, ResourcePriority = RP_NO); |
---|
| 77 | bool unloadAllByPriority(ResourcePriority prio); |
---|
[3983] | 78 | |
---|
[3676] | 79 | void debug(void); |
---|
[3245] | 80 | |
---|
[3983] | 81 | // utility functions of this class |
---|
| 82 | static bool isDir(const char* directory); |
---|
[4032] | 83 | static bool isFile(const char* fileName); |
---|
| 84 | static bool touchFile(const char* fileName); |
---|
| 85 | static bool deleteFile(const char* fileName); |
---|
[4054] | 86 | static char* homeDirCheck(const char* name); |
---|
[3983] | 87 | |
---|
[3245] | 88 | private: |
---|
[3655] | 89 | ResourceManager(); |
---|
| 90 | static ResourceManager* singletonRef; |
---|
[3245] | 91 | |
---|
[3672] | 92 | tList<Resource>* resourceList; //!< The List of Resources, that has already been loaded. |
---|
| 93 | char* dataDir; //!< The Data Directory, where all relevant Data is stored. |
---|
| 94 | tList<char>* imageDirs; //!< A list of directories in which images are stored. |
---|
[3655] | 95 | |
---|
[3672] | 96 | |
---|
[3790] | 97 | Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3); |
---|
[3672] | 98 | Resource* locateResourceByPointer(const void* pointer); |
---|
[3658] | 99 | |
---|
[1853] | 100 | }; |
---|
| 101 | |
---|
[3655] | 102 | #endif /* _RESOURCE_MANAGER_H */ |
---|