Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: objModel's materials should now automatically load textures

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