1 | /*! |
---|
2 | \file resource_manager.h |
---|
3 | \brief The Resource Manager checks if a file/resource is loaded. |
---|
4 | |
---|
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. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef _RESOURCE_MANAGER_H |
---|
12 | #define _RESOURCE_MANAGER_H |
---|
13 | |
---|
14 | #include "base_object.h" |
---|
15 | |
---|
16 | // FORWARD DEFINITION \\ |
---|
17 | //template<class T> class tList; |
---|
18 | #include "list.h" //! \todo do this by forward definition (ask Patrick) |
---|
19 | |
---|
20 | //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support |
---|
21 | enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE}; |
---|
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}; |
---|
30 | |
---|
31 | //! A Struct that keeps track about A resource its name its Type, and so on |
---|
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. |
---|
38 | ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) |
---|
39 | int count; //!< How many times this Resource has been loaded. |
---|
40 | }; |
---|
41 | |
---|
42 | |
---|
43 | //! The ResourceManager is a class, that decides if a file/resource should be loaded |
---|
44 | /** |
---|
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. |
---|
51 | */ |
---|
52 | class ResourceManager : public BaseObject |
---|
53 | { |
---|
54 | public: |
---|
55 | static ResourceManager* getInstance(); |
---|
56 | virtual ~ResourceManager(); |
---|
57 | |
---|
58 | static bool setDataDir(char* dataDir); |
---|
59 | static bool addImageDir(char* imageDir); |
---|
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); |
---|
65 | |
---|
66 | private: |
---|
67 | ResourceManager(); |
---|
68 | static ResourceManager* singletonRef; |
---|
69 | |
---|
70 | static tList<Resource>* resourceList; |
---|
71 | static char* dataDir; |
---|
72 | static tList<char>* imageDirs; |
---|
73 | |
---|
74 | static Resource* locateResourceByName(const char* fileName); |
---|
75 | static Resource* locateResourceByPointer(const void* pointer); |
---|
76 | |
---|
77 | static bool isDir(const char* directory); |
---|
78 | static bool isFile(const char* directory); |
---|
79 | }; |
---|
80 | |
---|
81 | #endif /* _RESOURCE_MANAGER_H */ |
---|