Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4685 was 4653, checked in by bensch, 19 years ago

orxonox/trunk: still a strange bug in the TYPE-case of the resource manager…
temporarily fixed the importer

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{
31#ifndef NO_MODEL
32  OBJ,                  //!< loading .obj file
33  PRIM,                 //!< loading primitive model
34  MD2,                  //!< loading md2-file
35#endif /* NO_MODEL */
36#ifndef NO_TEXT
37  TTF,                  //!< loading a TrueTypeFont
38#endif /* NO_TEXT */
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};
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  void*             pointer;           //!< Pointer to the Resource.
68  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*             skinFileName;      //!< skinFileName (MD2)
78#endif /* NO_MODEL */
79#ifndef NO_TEXT
80  unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
81  unsigned char     ttfColorR;         //!< red Color (TTF)
82  unsigned char     ttfColorG;         //!< green Color (TTF)
83  unsigned char     ttfColorB;         //!< blue Color (TTF)
84#endif /* NO_TEXT */
85};
86
87
88//! The ResourceManager is a class, that decides if a file/resource should be loaded
89/**
90   If a file/resource was already loaded the resourceManager will
91   return a void pointer to the desired resource.
92   Otherwise it will instruct the corresponding resource-loader to load,
93   and receive the pointer to it.
94
95   It does it by looking, if a desired file has already been loaded.
96*/
97class ResourceManager : public BaseObject
98{
99 public:
100  virtual ~ResourceManager();
101  /** \returns a Pointer to the only object of this Class */
102  inline static ResourceManager* getInstance(void) { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
103
104  bool setDataDir(const char* dataDir);
105  /** \returns the Name of the data directory */
106  inline const char* getDataDir(void) const {return this->dataDir;}
107
108  bool checkDataDir(const char* fileInside);
109  bool addImageDir(const char* imageDir);
110  void* load(const char* fileName, ResourcePriority prio = RP_NO,
111             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
112  void* 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  void debug(void) const;
119
120
121  // utility functions of this class
122  static bool isDir(const char* directory);
123  static bool isFile(const char* fileName);
124  static bool touchFile(const char* fileName);
125  static bool deleteFile(const char* fileName);
126  static char* homeDirCheck(const char* fileName);
127  static char* getFullName(const char* fileName);
128
129 private:
130  ResourceManager();
131
132  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
133  Resource* locateResourceByPointer(const void* pointer);
134
135 private:
136  static ResourceManager*  singletonRef;       //!< singleton Reference
137
138  tList<Resource>*         resourceList;       //!< The List of Resources, that has already been loaded.
139  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
140  tList<char>*             imageDirs;          //!< A list of directories in which images are stored.
141
142};
143
144#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.