Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader.tmp/src/util/resource_manager.h @ 3903

Last change on this file since 3903 was 3883, checked in by bensch, 20 years ago

orxonox/trunk: now a check for a directory should return true also in Windows

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