Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: made include more local. stdincl.h not in base_object.h anymore

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