[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 |
---|
[3658] | 21 | enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, 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. |
---|
| 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) |
---|
[3658] | 39 | int count; //!< How many times this Resource has been loaded. |
---|
| 40 | }; |
---|
[3543] | 41 | |
---|
[2036] | 42 | |
---|
[3655] | 43 | //! The ResourceManager is a class, that decides if a file/resource should be loaded |
---|
[3329] | 44 | /** |
---|
[3655] | 45 | If a file/resource was already loaded the resourceManager will |
---|
| 46 | return a void pointer to the desired resource. |
---|
| 47 | Otherwise it will instruct the corresponding resource-loader to load, |
---|
| 48 | and receive the pointer to it. |
---|
| 49 | |
---|
| 50 | It does it by looking, if a desired file has already been loaded. |
---|
[3329] | 51 | */ |
---|
[3655] | 52 | class ResourceManager : public BaseObject |
---|
| 53 | { |
---|
[1904] | 54 | public: |
---|
[3655] | 55 | static ResourceManager* getInstance(); |
---|
| 56 | virtual ~ResourceManager(); |
---|
[1853] | 57 | |
---|
[3658] | 58 | static bool setDataDir(char* dataDir); |
---|
| 59 | static bool addImageDir(char* imageDir); |
---|
[3660] | 60 | static void* load(const char* fileName, ResourcePriority prio = RP_NO); |
---|
| 61 | static void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO); |
---|
| 62 | static bool unload(void* pointer, ResourcePriority prio = RP_NO); |
---|
| 63 | static bool unload(Resource* resource, ResourcePriority = RP_NO); |
---|
| 64 | static bool unloadAllByPriority(ResourcePriority prio); |
---|
[3245] | 65 | |
---|
| 66 | private: |
---|
[3655] | 67 | ResourceManager(); |
---|
| 68 | static ResourceManager* singletonRef; |
---|
[3245] | 69 | |
---|
[3658] | 70 | static tList<Resource>* resourceList; |
---|
| 71 | static char* dataDir; |
---|
| 72 | static tList<char>* imageDirs; |
---|
[3655] | 73 | |
---|
[3658] | 74 | static Resource* locateResourceByName(const char* fileName); |
---|
| 75 | static Resource* locateResourceByPointer(const void* pointer); |
---|
| 76 | |
---|
[3655] | 77 | static bool isDir(const char* directory); |
---|
| 78 | static bool isFile(const char* directory); |
---|
[1853] | 79 | }; |
---|
| 80 | |
---|
[3655] | 81 | #endif /* _RESOURCE_MANAGER_H */ |
---|