Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3917 was 3911, checked in by bensch, 20 years ago

orxonox/trunk: minor changes at model

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