Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4413 was 4381, checked in by bensch, 20 years ago

orxonox/trunk: made include more local. stdincl.h not in base_object.h anymore

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