Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved the File-Classes

File size: 5.9 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)
[6640]16    (NO_SHADERS)
[3245]17*/
[1853]18
[3655]19#ifndef _RESOURCE_MANAGER_H
20#define _RESOURCE_MANAGER_H
[1853]21
[3543]22#include "base_object.h"
[8330]23#include "filesys/file.h"
[7661]24
[6645]25#include "multi_type.h"
[6642]26#include <vector>
[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 */
[6646]50  RESOURCE_TYPE_SIZE
[4534]51};
[4462]52
[4597]53//! An enumerator for different UNLOAD-types.
[3660]54/**
[4462]55   RP_NO:        will be unloaded on request
56   RP_LEVEL:     will be unloaded at the end of a Level
57   RP_CAMPAIGN:  will be unloaded at the end of a Campaign
58   RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
[3660]59*/
[4597]60typedef enum ResourcePriority
61{
62  RP_NO        =   0,
63  RP_LEVEL     =   1,
64  RP_CAMPAIGN  =   2,
65  RP_GAME      =   4
66};
[3543]67
[7193]68//! A Struct that keeps track about a resource its name its Type, and so on
[3658]69struct Resource
70{
[5304]71  BaseObject*       pointer;           //!< Pointer to the Resource.
[5308]72  unsigned int      count;             //!< How many times this Resource has been loaded.
[4597]73
[7221]74  std::string       name;              //!< Name of the Resource.
[4465]75  ResourceType      type;              //!< ResourceType of this Resource.
76  ResourcePriority  prio;              //!< The Priority of this resource. (This will only be increased)
[3790]77
[6645]78  MultiType         param[3];          //!< The Parameters given to this Resource.
[3658]79};
[3543]80
[2036]81
[3655]82//! The ResourceManager is a class, that decides if a file/resource should be loaded
[3329]83/**
[5308]84 * If a file/resource was already loaded the resourceManager will
85 * return a pointer to the desired resource.
86 * Otherwise it will instruct the corresponding resource-loader to load,
87 * and receive the pointer to it.
88 *
89 * It does it by looking, if a desired file has already been loaded.
90 * There is also the possibility to check for some variables
91 */
[4597]92class ResourceManager : public BaseObject
[3655]93{
[1904]94 public:
[3655]95  virtual ~ResourceManager();
[4836]96  /** @returns a Pointer to the only object of this Class */
[4746]97  inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager();  return singletonRef; };
[1853]98
[7221]99  bool setDataDir(const std::string& dataDir);
[4836]100  /** @returns the Name of the data directory */
[7221]101  inline const std::string& getDataDir() const { return this->dataDir; };
[4166]102
[5480]103
[7221]104  bool tryDataDir(const std::string& dataDir);
105  bool verifyDataDir(const std::string& fileInside);
106  bool addImageDir(const std::string& imageDir);
[6640]107
[7221]108  bool cache(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO,
[6645]109             const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
[6651]110  BaseObject* copy(BaseObject* resourcePointer);
[6640]111
[7221]112  BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO,
[6645]113                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
[7221]114  BaseObject* load(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO,
[6645]115                   const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());
[6651]116  bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO);
[3672]117  bool unload(Resource* resource, ResourcePriority = RP_NO);
118  bool unloadAllByPriority(ResourcePriority prio);
[4597]119
[7221]120  Resource* locateResourceByInfo(const std::string& fileName, ResourceType type,
[6645]121                                 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const;
[5994]122  Resource* locateResourceByPointer(const void* pointer) const;
123
[7221]124  std::string toResourcableString(unsigned int i);
125  bool fromResourceableString(const std::string& resourceableString);
[6649]126  /** @returns the Count of Resources the ResourceManager handles */
127  unsigned int resourceCount() const { return this->resourceList.size(); }
[6648]128
[4746]129  void debug() const;
[3245]130
[4597]131
[5480]132  // utility functions for handling files in and around the data-directory
[7221]133  static std::string getFullName(const std::string& fileName);
134  static bool isInDataDir(const std::string& fileName);
[3983]135
[5306]136  static const char* ResourceTypeToChar(ResourceType type);
[7225]137  static ResourceType stringToResourceType(const std::string& resourceType);
[5306]138
[3245]139 private:
[3655]140  ResourceManager();
[7221]141  Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,
[6645]142                         const MultiType& param0, const MultiType& param1, const MultiType& param2);
[3245]143
[4465]144 private:
[7221]145  static ResourceManager*    singletonRef;       //!< singleton Reference
[3672]146
[7221]147  std::string                dataDir;            //!< The Data Directory, where all relevant Data is stored.
148  std::vector<std::string>   imageDirs;          //!< A list of directories in which images are stored.
[4465]149
[7221]150  std::vector<Resource*>     resourceList;       //!< The List of Resources, that has already been loaded.
[6646]151
[7221]152  static const char*         resourceNames[RESOURCE_TYPE_SIZE];
[1853]153};
154
[3655]155#endif /* _RESOURCE_MANAGER_H */
Note: See TracBrowser for help on using the repository browser.