Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/christmas_branche/src/util/loading/resource_manager.h @ 6186

Last change on this file since 6186 was 6186, checked in by bensch, 18 years ago

christmas less include

File size: 5.1 KB
Line 
1/*!
2 * @file resource_manager.h
3  *  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    it is possible to compile the resource Manager without some modules by
11    just adding the compile flag -D....
12    (NO_MODEL)
13    (NO_AUDIO)
14    (NO_TEXT)
15    (NO_TEXTURES)
16*/
17
18#ifndef _RESOURCE_MANAGER_H
19#define _RESOURCE_MANAGER_H
20
21#include "base_object.h"
22
23#include <list>
24
25//! An eumerator for different fileTypes the resourceManager supports
26typedef enum ResourceType
27{
28#ifndef NO_MODEL
29  OBJ,                  //!< loading .obj file
30  PRIM,                 //!< loading primitive model
31  MD2,                  //!< loading md2-file
32#endif /* NO_MODEL */
33#ifndef NO_TEXT
34  TTF,                  //!< loading a TrueTypeFont
35#endif /* NO_TEXT */
36#ifndef NO_AUDIO
37  WAV,                  //!< loading wav
38  MP3,                  //!< loading mp3
39  OGG,                  //!< loading ogg
40#endif /* NO_AUDIO */
41#ifndef NO_TEXTURES
42  IMAGE,                //!< loading an image
43#endif /* NO_TEXTURES */
44#ifndef NO_SHADERS
45  SHADER,               //!< openGL-shader program
46#endif /* NO_SHADERS */
47};
48
49//! An enumerator for different UNLOAD-types.
50/**
51   RP_NO:        will be unloaded on request
52   RP_LEVEL:     will be unloaded at the end of a Level
53   RP_CAMPAIGN:  will be unloaded at the end of a Campaign
54   RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
55*/
56typedef enum ResourcePriority
57{
58  RP_NO        =   0,
59  RP_LEVEL     =   1,
60  RP_CAMPAIGN  =   2,
61  RP_GAME      =   4
62};
63
64//! A Struct that keeps track about A resource its name its Type, and so on
65struct Resource
66{
67  BaseObject*       pointer;           //!< Pointer to the Resource.
68  unsigned int      count;             //!< How many times this Resource has been loaded.
69
70  char*             name;              //!< Name of the Resource.
71  ResourceType      type;              //!< ResourceType of this Resource.
72  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
73
74  // more specific
75  float             modelSize;         //!< the size of the model (OBJ/PRIM)
76#ifndef NO_MODEL
77  char*             secFileName;       //!< a seconf fileName
78#endif /* NO_MODEL */
79#ifndef NO_TEXT
80  unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
81#endif /* NO_TEXT */
82};
83
84
85//! The ResourceManager is a class, that decides if a file/resource should be loaded
86/**
87 * If a file/resource was already loaded the resourceManager will
88 * return a pointer to the desired resource.
89 * Otherwise it will instruct the corresponding resource-loader to load,
90 * and receive the pointer to it.
91 *
92 * It does it by looking, if a desired file has already been loaded.
93 * There is also the possibility to check for some variables
94 */
95class ResourceManager : public BaseObject
96{
97 public:
98  virtual ~ResourceManager();
99  /** @returns a Pointer to the only object of this Class */
100  inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
101
102  bool setDataDir(const char* dataDir);
103  /** @returns the Name of the data directory */
104  inline const char* getDataDir() const { return this->dataDir; };
105
106
107  bool tryDataDir(const char* dataDir);
108  bool verifyDataDir(const char* fileInside);
109  bool addImageDir(const char* imageDir);
110  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
111               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
112  BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
113               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
114  bool unload(void* pointer, ResourcePriority prio = RP_NO);
115  bool unload(Resource* resource, ResourcePriority = RP_NO);
116  bool unloadAllByPriority(ResourcePriority prio);
117
118  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const;
119  Resource* locateResourceByPointer(const void* pointer) const;
120
121  void debug() const;
122
123
124  // utility functions for handling files in and around the data-directory
125  static bool isDir(const char* directory);
126  static bool isFile(const char* fileName);
127  static bool touchFile(const char* fileName);
128  static bool deleteFile(const char* fileName);
129  static char* homeDirCheck(const char* fileName);
130  static char* getFullName(const char* fileName);
131  static bool isInDataDir(const char* fileName);
132
133  static const char* ResourceTypeToChar(ResourceType type);
134
135
136 private:
137  ResourceManager();
138
139 private:
140  static ResourceManager*  singletonRef;       //!< singleton Reference
141
142  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
143  std::list<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded.
144  std::list<char*>         imageDirs;          //!< A list of directories in which images are stored.
145
146};
147
148#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.