Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: better check for data-dir

File size: 5.1 KB
RevLine 
[4597]1/*!
[5039]2 * @file resource_manager.h
[4836]3  *  The Resource Manager checks if a file/resource is loaded.
[3329]4
[4597]5    If a file/resource was already loaded the resourceManager will
[3655]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.
[4534]9
10    it is possible to compile the resource Manager without some modules by
[4597]11    just adding the compile flag -D....
[4534]12    (NO_MODEL)
13    (NO_AUDIO)
14    (NO_TEXT)
15    (NO_TEXTURES)
[3245]16*/
[1853]17
[3655]18#ifndef _RESOURCE_MANAGER_H
19#define _RESOURCE_MANAGER_H
[1853]20
[3543]21#include "base_object.h"
[1853]22
[4381]23#include "stdlibincl.h"
24
[5405]25// FORWARD DECLARATION
[3911]26template<class T> class tList;
[3660]27
[4462]28//! An eumerator for different fileTypes the resourceManager supports
[4597]29typedef enum ResourceType
30{
[4534]31#ifndef NO_MODEL
32  OBJ,                  //!< loading .obj file
33  PRIM,                 //!< loading primitive model
34  MD2,                  //!< loading md2-file
35#endif /* NO_MODEL */
[4653]36#ifndef NO_TEXT
37  TTF,                  //!< loading a TrueTypeFont
38#endif /* NO_TEXT */
[4534]39#ifndef NO_AUDIO
40  WAV,                  //!< loading wav
41  MP3,                  //!< loading mp3
42  OGG,                  //!< loading ogg
43#endif /* NO_AUDIO */
44#ifndef NO_TEXTURES
[5323]45  IMAGE,                //!< loading an image
[4534]46#endif /* NO_TEXTURES */
[5323]47#ifndef NO_SHADERS
48  SHADER,               //!< openGL-shader program
49#endif /* NO_SHADERS */
[4534]50};
[4462]51
[4597]52//! An enumerator for different UNLOAD-types.
[3660]53/**
[4462]54   RP_NO:        will be unloaded on request
55   RP_LEVEL:     will be unloaded at the end of a Level
56   RP_CAMPAIGN:  will be unloaded at the end of a Campaign
57   RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
[3660]58*/
[4597]59typedef enum ResourcePriority
60{
61  RP_NO        =   0,
62  RP_LEVEL     =   1,
63  RP_CAMPAIGN  =   2,
64  RP_GAME      =   4
65};
[3543]66
[3660]67//! A Struct that keeps track about A resource its name its Type, and so on
[3658]68struct Resource
69{
[5304]70  BaseObject*       pointer;           //!< Pointer to the Resource.
[5308]71  unsigned int      count;             //!< How many times this Resource has been loaded.
[4597]72
[4465]73  char*             name;              //!< Name of the Resource.
74  ResourceType      type;              //!< ResourceType of this Resource.
75  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
[3790]76
77  // more specific
[4637]78  float             modelSize;         //!< the size of the model (OBJ/PRIM)
[4534]79#ifndef NO_MODEL
[5323]80  char*             secFileName;       //!< a seconf fileName
[4534]81#endif /* NO_MODEL */
82#ifndef NO_TEXT
[4465]83  unsigned int      ttfSize;           //!< the size of the ttf-font (TTF)
[4534]84#endif /* NO_TEXT */
[3658]85};
[3543]86
[2036]87
[3655]88//! The ResourceManager is a class, that decides if a file/resource should be loaded
[3329]89/**
[5308]90 * If a file/resource was already loaded the resourceManager will
91 * return a pointer to the desired resource.
92 * Otherwise it will instruct the corresponding resource-loader to load,
93 * and receive the pointer to it.
94 *
95 * It does it by looking, if a desired file has already been loaded.
96 * There is also the possibility to check for some variables
97 */
[4597]98class ResourceManager : public BaseObject
[3655]99{
[1904]100 public:
[3655]101  virtual ~ResourceManager();
[4836]102  /** @returns a Pointer to the only object of this Class */
[4746]103  inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
[1853]104
[3883]105  bool setDataDir(const char* dataDir);
[4836]106  /** @returns the Name of the data directory */
[5308]107  inline const char* getDataDir() const { return this->dataDir; };
[4166]108
[5480]109
110  bool tryDataDir(const char* dataDir);
111  bool verifyDataDir(const char* fileInside);
112  bool addImageDir(const char* imageDir);
[5304]113  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
[5306]114               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
[5304]115  BaseObject* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO,
[5306]116               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
[3672]117  bool unload(void* pointer, ResourcePriority prio = RP_NO);
118  bool unload(Resource* resource, ResourcePriority = RP_NO);
119  bool unloadAllByPriority(ResourcePriority prio);
[4597]120
[4746]121  void debug() const;
[3245]122
[4597]123
[5480]124  // utility functions for handling files in and around the data-directory
[3983]125  static bool isDir(const char* directory);
[4032]126  static bool isFile(const char* fileName);
127  static bool touchFile(const char* fileName);
128  static bool deleteFile(const char* fileName);
[4166]129  static char* homeDirCheck(const char* fileName);
130  static char* getFullName(const char* fileName);
[5335]131  static bool isInDataDir(const char* fileName);
[3983]132
[5306]133  static const char* ResourceTypeToChar(ResourceType type);
134
[5480]135
[3245]136 private:
[3655]137  ResourceManager();
[3245]138
[4465]139  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
[4597]140  Resource* locateResourceByPointer(const void* pointer);
[3655]141
[4465]142 private:
143  static ResourceManager*  singletonRef;       //!< singleton Reference
[3672]144
[5308]145  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
[4465]146  tList<Resource>*         resourceList;       //!< The List of Resources, that has already been loaded.
147  tList<char>*             imageDirs;          //!< A list of directories in which images are stored.
148
[1853]149};
150
[3655]151#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.