Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5218 was 5121, checked in by bensch, 19 years ago

orxonox/trunk: color is now a parameter of text not font

File size: 4.8 KB
RevLine 
[4597]1/*!
[5039]2 * @file resource_manager.h
[4836]3  *  The Resource Manager checks if a file/resource is loaded.
[3329]4
[4597]5    If a file/resource was already loaded the resourceManager will
[3655]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
[4597]11    just adding the compile flag -D....
[4534]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
[4597]25// FORWARD DEFINITION
[3911]26template<class T> class tList;
[3660]27
[4462]28//! An eumerator for different fileTypes the resourceManager supports
[4597]29typedef enum ResourceType
30{
[4534]31#ifndef NO_MODEL
32  OBJ,                  //!< loading .obj file
33  PRIM,                 //!< loading primitive model
34  MD2,                  //!< loading md2-file
35#endif /* NO_MODEL */
[4653]36#ifndef NO_TEXT
37  TTF,                  //!< loading a TrueTypeFont
38#endif /* NO_TEXT */
[4534]39#ifndef NO_AUDIO
40  WAV,                  //!< loading wav
41  MP3,                  //!< loading mp3
42  OGG,                  //!< loading ogg
43#endif /* NO_AUDIO */
44#ifndef NO_TEXTURES
45  IMAGE                 //!< loading an image
46#endif /* NO_TEXTURES */
47};
[4462]48
[4597]49//! An enumerator for different UNLOAD-types.
[3660]50/**
[4462]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)
[3660]55*/
[4597]56typedef enum ResourcePriority
57{
58  RP_NO        =   0,
59  RP_LEVEL     =   1,
60  RP_CAMPAIGN  =   2,
61  RP_GAME      =   4
62};
[3543]63
[3660]64//! A Struct that keeps track about A resource its name its Type, and so on
[3658]65struct Resource
66{
[4465]67  void*             pointer;           //!< Pointer to the Resource.
68  int               count;             //!< How many times this Resource has been loaded.
[4597]69
[4465]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)
[3790]73
74  // more specific
[4637]75  float             modelSize;         //!< the size of the model (OBJ/PRIM)
[4534]76#ifndef NO_MODEL
77  char*             skinFileName;      //!< skinFileName (MD2)
78#endif /* NO_MODEL */
79#ifndef NO_TEXT
[4465]80  unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
[4534]81#endif /* NO_TEXT */
[3658]82};
[3543]83
[2036]84
[3655]85//! The ResourceManager is a class, that decides if a file/resource should be loaded
[3329]86/**
[4597]87   If a file/resource was already loaded the resourceManager will
[3655]88   return a void 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.
[3329]93*/
[4597]94class ResourceManager : public BaseObject
[3655]95{
[1904]96 public:
[3655]97  virtual ~ResourceManager();
[4836]98  /** @returns a Pointer to the only object of this Class */
[4746]99  inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
[1853]100
[3883]101  bool setDataDir(const char* dataDir);
[4836]102  /** @returns the Name of the data directory */
[4746]103  inline const char* getDataDir() const {return this->dataDir;}
[4166]104
[4091]105  bool checkDataDir(const char* fileInside);
[4370]106  bool addImageDir(const char* imageDir);
[3790]107  void* load(const char* fileName, ResourcePriority prio = RP_NO,
[4597]108             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
[3790]109  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
[4597]110             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
[3672]111  bool unload(void* pointer, ResourcePriority prio = RP_NO);
112  bool unload(Resource* resource, ResourcePriority = RP_NO);
113  bool unloadAllByPriority(ResourcePriority prio);
[4597]114
[4746]115  void debug() const;
[3245]116
[4597]117
[3983]118  // utility functions of this class
119  static bool isDir(const char* directory);
[4032]120  static bool isFile(const char* fileName);
121  static bool touchFile(const char* fileName);
122  static bool deleteFile(const char* fileName);
[4166]123  static char* homeDirCheck(const char* fileName);
124  static char* getFullName(const char* fileName);
[3983]125
[3245]126 private:
[3655]127  ResourceManager();
[3245]128
[4465]129  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
[4597]130  Resource* locateResourceByPointer(const void* pointer);
[3655]131
[4465]132 private:
133  static ResourceManager*  singletonRef;       //!< singleton Reference
[3672]134
[4465]135  tList<Resource>*         resourceList;       //!< The List of Resources, that has already been loaded.
136  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
137  tList<char>*             imageDirs;          //!< A list of directories in which images are stored.
138
[1853]139};
140
[3655]141#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.