Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/resource_manager.h @ 4588

Last change on this file since 4588 was 4534, checked in by bensch, 19 years ago

orxonox/trunk: ResourceManager should now be able to compile without some modules

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