Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound_engine/src/util/resource_manager.h @ 4225

Last change on this file since 4225 was 3891, checked in by bensch, 20 years ago

orxonox/trunk: sound can be registered with the resource-Manager:
user load(fileName, RESOURCE_SOUND_EFFECT/MUSIC) to load

File size: 3.5 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,
22                   PRIM,
23                   WAV,
24                   MP3,
25                   OGG,
26                   TTF,
27                   IMAGE,
28                   RESOURCE_SOUND_EFFECT,
29                   RESOURCE_SOUND_MUSIC};
30//! An enumerator for different UNLOAD-types.
31/**
32   RP_NO: will be unloaded on request
33   RP_LEVEL: will be unloaded at the end of a Level
34   RP_CAMPAIGN: will be unloaded at the end of a Campaign
35   RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)
36*/
37enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, 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  bool addImageDir(char* imageDir);
77  void* load(const char* fileName, ResourcePriority prio = RP_NO,
78             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
79  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
80             void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
81  bool unload(void* pointer, ResourcePriority prio = RP_NO);
82  bool unload(Resource* resource, ResourcePriority = RP_NO);
83  bool unloadAllByPriority(ResourcePriority prio);
84  void debug(void);
85
86 private:
87  ResourceManager();
88  static ResourceManager* singletonRef;
89
90  tList<Resource>* resourceList;       //!< The List of Resources, that has already been loaded.
91  char* dataDir;                       //!< The Data Directory, where all relevant Data is stored.
92  tList<char>* imageDirs;              //!< A list of directories in which images are stored.
93
94
95  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
96  Resource* locateResourceByPointer(const void* pointer);
97 
98  bool isDir(const char* directory);
99  bool isFile(const char* directory);
100
101};
102
103#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.