Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4336 was 4166, checked in by bensch, 20 years ago

orxonox/trunk: resourceManager has some new functions

File size: 3.7 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
11#ifndef _RESOURCE_MANAGER_H
12#define _RESOURCE_MANAGER_H
13
14#include "base_object.h"
15
16// FORWARD DEFINITION
17template<class T> class tList;
18
19//! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support
20enum ResourceType {OBJ,
21                   PRIM,
22                   WAV,
23                   MP3,
24                   OGG,
25                   TTF,
26                   IMAGE};
27//! An enumerator for different UNLOAD-types.
28/**
29   RP_NO: will be unloaded on request
30   RP_LEVEL: will be unloaded at the end of a Level
31   RP_CAMPAIGN: will be unloaded at the end of a Campaign
32   RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)
33*/
34enum ResourcePriority {RP_NO = 0,
35                       RP_LEVEL = 1,
36                       RP_CAMPAIGN = 2,
37                       RP_GAME = 3};
38
39//! A Struct that keeps track about A resource its name its Type, and so on
40struct Resource
41{
42  void* pointer;             //!< Pointer to the Resource.
43  int count;                 //!< How many times this Resource has been loaded.
44 
45  char* name;                //!< Name of the Resource.
46  ResourceType type;         //!< ResourceType of this Resource.
47  ResourcePriority prio;     //!< The Priority of this resource. (This will only be increased)
48
49  // more specific
50  float modelSize;
51  unsigned int ttfSize;
52  unsigned char ttfColorR;
53  unsigned char ttfColorG;
54  unsigned char ttfColorB;
55};
56
57
58//! The ResourceManager is a class, that decides if a file/resource should be loaded
59/**
60   If a file/resource was already loaded the resourceManager will
61   return a void pointer to the desired resource.
62   Otherwise it will instruct the corresponding resource-loader to load,
63   and receive the pointer to it.
64
65   It does it by looking, if a desired file has already been loaded.
66
67   \todo loading also dependant by parameters.
68*/
69class ResourceManager : public BaseObject
70{
71 public:
72  static ResourceManager* getInstance();
73  virtual ~ResourceManager();
74
75  bool setDataDir(const char* dataDir);
76  /** \returns the Name of the data directory */
77  inline const char* getDataDir(void) const {return this->dataDir;}
78
79  bool checkDataDir(const char* fileInside);
80  bool addImageDir(char* imageDir);
81  void* load(const char* fileName, ResourcePriority prio = RP_NO,
82             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
83  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
84             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
85  bool unload(void* pointer, ResourcePriority prio = RP_NO);
86  bool unload(Resource* resource, ResourcePriority = RP_NO);
87  bool unloadAllByPriority(ResourcePriority prio);
88
89  void debug(void);
90
91  // utility functions of this class
92  static bool isDir(const char* directory);
93  static bool isFile(const char* fileName);
94  static bool touchFile(const char* fileName);
95  static bool deleteFile(const char* fileName);
96  static char* homeDirCheck(const char* fileName);
97  static char* getFullName(const char* fileName);
98
99 private:
100  ResourceManager();
101  static ResourceManager* singletonRef;
102
103  tList<Resource>* resourceList;       //!< The List of Resources, that has already been loaded.
104  char* dataDir;                       //!< The Data Directory, where all relevant Data is stored.
105  tList<char>* imageDirs;              //!< A list of directories in which images are stored.
106
107
108  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
109  Resource* locateResourceByPointer(const void* pointer);
110 
111};
112
113#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.