Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/util/loading/resource_manager.h @ 6594

Last change on this file since 6594 was 6467, checked in by bensch, 19 years ago

orxonox/trunk: Texture loading with GL_TEXTURE_* in ResourceManager and Material

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