Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4225 was 3746, checked in by chris, 20 years ago

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File size: 3.0 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, 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 
36  char* name;                //!< Name of the Resource.
37  ResourceType type;         //!< ResourceType of this Resource.
38  ResourcePriority prio;     //!< The Priority of this resource. (This will only be increased)
39  int count;                 //!< How many times this Resource has been loaded.
40};
41
42
43//! The ResourceManager is a class, that decides if a file/resource should be loaded
44/**
45   If a file/resource was already loaded the resourceManager will
46   return a void pointer to the desired resource.
47   Otherwise it will instruct the corresponding resource-loader to load,
48   and receive the pointer to it.
49
50   It does it by looking, if a desired file has already been loaded.
51*/
52class ResourceManager : public BaseObject
53{
54 public:
55  static ResourceManager* getInstance();
56  virtual ~ResourceManager();
57
58  bool setDataDir(char* dataDir);
59  bool addImageDir(char* imageDir);
60  void* load(const char* fileName, ResourcePriority prio = RP_NO);
61  void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);
62  bool unload(void* pointer, ResourcePriority prio = RP_NO);
63  bool unload(Resource* resource, ResourcePriority = RP_NO);
64  bool unloadAllByPriority(ResourcePriority prio);
65  void debug(void);
66
67 private:
68  ResourceManager();
69  static ResourceManager* singletonRef;
70
71  tList<Resource>* resourceList;       //!< The List of Resources, that has already been loaded.
72  char* dataDir;                       //!< The Data Directory, where all relevant Data is stored.
73  tList<char>* imageDirs;              //!< A list of directories in which images are stored.
74
75
76  Resource* locateResourceByName(const char* fileName);
77  Resource* locateResourceByPointer(const void* pointer);
78 
79  bool isDir(const char* directory);
80  bool isFile(const char* directory);
81
82};
83
84#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.