Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: resource manager in new design :)
no no just kidding… only doxy-tags :)

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