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