/*! * @file resource.h * @brief Definition of a Resource. */ #ifndef _RESOURCE_H #define _RESOURCE_H #include "base_object.h" #include "multi_type.h" #include #include #include namespace Loading { // FORWARD DECLARATION //! An enumerator for different (UN)LOAD-types. /** * RP_NO: will be unloaded on request * RP_LEVEL: will be unloaded at the end of a Level * RP_CAMPAIGN: will be unloaded at the end of a Campaign * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) */ typedef enum ResourcePriority { RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3 }; //! A Resource is an Object, that can be loaded from Disk /** * A Resource can cahnge the internal type, meaning it is a * SmartPointer, that keeps track of the InternalCount of the * Resource (SharedResource). */ class Resource : virtual public BaseObject { protected: /** * This is a Class for the internal handling of the Resource. * Any Resource keeps exactly one of these Classes, so it can * reference and move it around, and keep track of how many * references of it are stored. */ class SharedResource { public: SharedResource(); std::string fileName; unsigned int referenceCount; //!< How many times this Resource has been loaded. ClassID type; //!< ResourceType of this Resource. ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this) MultiType param[3]; //!< The Parameters given to this Resource. }; public: Resource(const std::string& fileName = "", ResourcePriority prio = RP_LEVEL); virtual ~Resource(); // looks if the resource was already loaded and (if not) loads it. virtual bool load(std::string& fileName = "", ResourcePriority prio = RP_LEVEL, const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL, const MultiType& param2 = MT_NULL); // reloads the resource. virtual bool reload() { }; // unloads the sharedResource (from this Resource) virtual bool unload(); // checks if a resource was already loaded. bool isLoaded(std::string& fileName, const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL, const MultiType& param2 = MT_NULL); // raises the priority can only be raised void raisePriority(ResourcePriority prio); /** @returns the referenceCount of the shared resource behind this resource or 0 if no internal Resource is stored */ unsigned int referenceCount() const { return (this->resource)? this->resource->referenceCount : 0; }; protected: const SharedResource* findResource(std::string& fileName, const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL, const MultiType& param2 = MT_NULL); protected: SharedResource* resource; //!< The internal Resource, this Resource is keeping (at the moment). static std::map > storedResources; }; } #endif /* _RESOURCE_H */