Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4569 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
RevLine 
[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.
[4534]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)
[3245]16*/
[1853]17
[3655]18#ifndef _RESOURCE_MANAGER_H
19#define _RESOURCE_MANAGER_H
[1853]20
[3543]21#include "base_object.h"
[1853]22
[4381]23#include "stdlibincl.h"
24
[3911]25// FORWARD DEFINITION
26template<class T> class tList;
[3660]27
[4462]28//! An eumerator for different fileTypes the resourceManager supports
[4534]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};
[4462]47
[3660]48//! An enumerator for different UNLOAD-types.
49/**
[4462]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)
[3660]54*/
[4462]55typedef enum ResourcePriority { RP_NO        =   0,
56                                RP_LEVEL     =   1,
57                                RP_CAMPAIGN  =   2,
58                                RP_GAME      =   4 };
[3543]59
[3660]60//! A Struct that keeps track about A resource its name its Type, and so on
[3658]61struct Resource
62{
[4465]63  void*             pointer;           //!< Pointer to the Resource.
64  int               count;             //!< How many times this Resource has been loaded.
[3658]65 
[4465]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)
[3790]69
70  // more specific
[4534]71#ifndef NO_MODEL
[4465]72  float             modelSize;         //!< the size of the model (OBJ/PRIM)
[4534]73  char*             skinFileName;      //!< skinFileName (MD2)
74#endif /* NO_MODEL */
75#ifndef NO_TEXT
[4465]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)
[4534]80#endif /* NO_TEXT */
[3658]81};
[3543]82
[2036]83
[3655]84//! The ResourceManager is a class, that decides if a file/resource should be loaded
[3329]85/**
[3655]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.
[3329]92*/
[3655]93class ResourceManager : public BaseObject
94{
[1904]95 public:
[3655]96  virtual ~ResourceManager();
[4519]97  /** \returns a Pointer to the only object of this Class */
98  inline static ResourceManager* getInstance(void) { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
[1853]99
[3883]100  bool setDataDir(const char* dataDir);
[4091]101  /** \returns the Name of the data directory */
[4166]102  inline const char* getDataDir(void) const {return this->dataDir;}
103
[4091]104  bool checkDataDir(const char* fileInside);
[4370]105  bool addImageDir(const char* imageDir);
[3790]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);
[3672]110  bool unload(void* pointer, ResourcePriority prio = RP_NO);
111  bool unload(Resource* resource, ResourcePriority = RP_NO);
112  bool unloadAllByPriority(ResourcePriority prio);
[4465]113 
[3676]114  void debug(void);
[4465]115 
[3245]116
[3983]117  // utility functions of this class
118  static bool isDir(const char* directory);
[4032]119  static bool isFile(const char* fileName);
120  static bool touchFile(const char* fileName);
121  static bool deleteFile(const char* fileName);
[4166]122  static char* homeDirCheck(const char* fileName);
123  static char* getFullName(const char* fileName);
[3983]124
[3245]125 private:
[3655]126  ResourceManager();
[3245]127
[4465]128  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
129  Resource* locateResourceByPointer(const void* pointer); 
[3655]130
[4465]131 private:
132  static ResourceManager*  singletonRef;       //!< singleton Reference
[3672]133
[4465]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
[1853]138};
139
[3655]140#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.