Changeset 7229 in orxonox.OLD for branches/resources/src/lib/util/loading
- Timestamp:
- Mar 21, 2006, 3:13:34 PM (19 years ago)
- Location:
- branches/resources/src/lib/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/resources/src/lib/util/loading/resource.cc
r7195 r7229 18 18 #include "resource.h" 19 19 20 using namespace std;21 20 21 namespace Loading 22 { 22 23 23 /** 24 * standard constructor 25 */ 26 Resource::Resource (const std::string& fileName) 27 { 28 this->setClassID(CL_RESOURCE, "Resource"); 24 /** 25 * standard constructor 26 */ 27 Resource::Resource (const std::string& fileName, ResourcePriority prio) 28 { 29 this->setClassID(CL_RESOURCE, "Resource"); 30 this->resource = NULL; 29 31 32 } 33 34 /** 35 * standard deconstructor 36 */ 37 Resource::~Resource () 38 { 39 // delete what has to be deleted here 40 } 41 42 Resource::SharedResource::SharedResource() 43 { 44 this->referenceCount = 1; 45 this->type = CL_NULL; 46 this->prio = RP_NO; 47 } 30 48 } 31 32 /**33 * standard deconstructor34 */35 Resource::~Resource ()36 {37 // delete what has to be deleted here38 } -
branches/resources/src/lib/util/loading/resource.h
r7195 r7229 10 10 #include "multi_type.h" 11 11 #include <string> 12 13 // FORWARD DECLARATION 12 #include <map> 13 #include <vector> 14 14 15 15 16 namespace Loading 17 { 18 // FORWARD DECLARATION 16 19 17 //! An enumerator for different (UN)LOAD-types.18 /**19 * RP_NO: will be unloaded on request20 * RP_LEVEL: will be unloaded at the end of a Level21 * RP_CAMPAIGN: will be unloaded at the end of a Campaign22 * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)23 */24 typedef enum ResourcePriority25 {26 RP_NO = 0,27 RP_LEVEL = 1,28 RP_CAMPAIGN = 2,29 RP_GAME = 330 };20 //! An enumerator for different (UN)LOAD-types. 21 /** 22 * RP_NO: will be unloaded on request 23 * RP_LEVEL: will be unloaded at the end of a Level 24 * RP_CAMPAIGN: will be unloaded at the end of a Campaign 25 * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) 26 */ 27 typedef enum ResourcePriority 28 { 29 RP_NO = 0, 30 RP_LEVEL = 1, 31 RP_CAMPAIGN = 2, 32 RP_GAME = 3 33 }; 31 34 32 35 36 //! A Resource is an Object, that can be loaded from Disk 37 /** 38 * A Resource can cahnge the internal type, meaning it is a 39 * SmartPointer, that keeps track of the InternalCount of the 40 * Resource (SharedResource). 41 */ 42 class Resource : virtual public BaseObject 43 { 44 protected: 45 /** 46 * This is a Class for the internal handling of the Resource. 47 * Any Resource keeps exactly one of these Classes, so it can 48 * reference and move it around, and keep track of how many 49 * references of it are stored. 50 */ 51 class SharedResource 52 { 53 public: 54 SharedResource(); 55 std::string fileName; 33 56 34 //! A Resource is an Object, that can be loaded from Disk 35 /** 36 * 37 */ 38 class Resource : virtual public BaseObject { 57 unsigned int referenceCount; //!< How many times this Resource has been loaded. 58 ClassID type; //!< ResourceType of this Resource. 59 ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this) 39 60 40 public: 41 Resource(const std::string& fileName); 42 virtual ~Resource(); 61 MultiType param[3]; //!< The Parameters given to this Resource. 62 }; 43 63 44 virtual bool load(std::string& fileName, const MultiType& param1, const MultiType& param2);45 virtual bool reload();46 virtual bool unload();47 64 48 private: 49 std::string fileName; 65 public: 66 Resource(const std::string& fileName = "", ResourcePriority prio = RP_LEVEL); 67 virtual ~Resource(); 50 68 51 unsigned int referenceCount; //!< How many times this Resource has been loaded. 52 /// TODO REMOVE THIS: ResourceType type; //!< ResourceType of this Resource. 53 ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this) 69 // looks if the resource was already loaded and (if not) loads it. 70 virtual bool load(std::string& fileName = "", 71 ResourcePriority prio = RP_LEVEL, 72 const MultiType& param0 = MT_NULL, 73 const MultiType& param1 = MT_NULL, 74 const MultiType& param2 = MT_NULL); 75 // reloads the resource. 76 virtual bool reload() { }; 77 // unloads the sharedResource (from this Resource) 78 virtual bool unload(); 54 79 55 MultiType param[3]; //!< The Parameters given to this Resource. 56 }; 80 // checks if a resource was already loaded. 81 bool isLoaded(std::string& fileName, 82 const MultiType& param0 = MT_NULL, 83 const MultiType& param1 = MT_NULL, 84 const MultiType& param2 = MT_NULL); 57 85 86 // raises the priority can only be raised 87 void raisePriority(ResourcePriority prio); 88 /** @returns the referenceCount of the shared resource behind this resource or 0 if no internal Resource is stored */ 89 unsigned int referenceCount() const { return (this->resource)? this->resource->referenceCount : 0; }; 90 91 protected: 92 const SharedResource* findResource(std::string& fileName, 93 const MultiType& param0 = MT_NULL, 94 const MultiType& param1 = MT_NULL, 95 const MultiType& param2 = MT_NULL); 96 97 protected: 98 SharedResource* resource; //!< The internal Resource, this Resource is keeping (at the moment). 99 100 static std::map<ClassID, std::vector<SharedResource> > storedResources; 101 }; 102 103 } 58 104 #endif /* _RESOURCE_H */
Note: See TracChangeset
for help on using the changeset viewer.