Changeset 3672 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Mar 30, 2005, 3:02:58 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/resource_manager.cc
r3667 r3672 11 11 ### File Specific: 12 12 main-programmer: Benjamin Grauer 13 co-programmer: ...13 co-programmer: Patrick Boenzli 14 14 */ 15 15 … … 38 38 { 39 39 this->setClassName ("ResourceManager"); 40 dataDir = NULL;41 imageDirs = new tList<char>();42 resourceList = new tList<Resource>();40 this->dataDir = "./"; 41 this->imageDirs = new tList<char>(); 42 this->resourceList = new tList<Resource>(); 43 43 } 44 44 … … 55 55 //! Singleton Reference to the ResourceManager 56 56 ResourceManager* ResourceManager::singletonRef = NULL; 57 //! The List of Resources, that has already been loaded.58 tList<Resource>* ResourceManager::resourceList = NULL;59 //! The Data Directory, where all relevant Data is stored.60 char* ResourceManager::dataDir = NULL;61 //! A list of directories in which images are stored.62 tList<char>* ResourceManager::imageDirs = NULL;63 57 64 58 /** … … 68 62 { 69 63 // deleting the Resources-List 70 unloadAllByPriority(RP_GAME); 71 delete resourceList; 72 resourceList = NULL; 64 this->unloadAllByPriority(RP_GAME); 65 delete this->resourceList; 73 66 // deleting the Directorie Lists 74 char* tmpDir = imageDirs->enumerate(); 67 tIterator<char>* tmpIt = imageDirs->getIterator(); 68 char* tmpDir = tmpIt->nextElement(); 75 69 while(tmpDir) 76 70 { 77 71 delete []tmpDir; 78 tmpDir = imageDirs->nextElement(); 79 } 80 81 delete imageDirs; 82 imageDirs = NULL; 72 tmpDir = tmpIt->nextElement(); 73 } 74 delete tmpIt; 75 76 delete this->imageDirs; 77 83 78 ResourceManager::singletonRef = NULL; 84 79 } … … 92 87 if (isDir(dataDir)) 93 88 { 94 ResourceManager::dataDir = new char[strlen(dataDir)+1];95 strcpy( ResourceManager::dataDir, dataDir);89 this->dataDir = new char[strlen(dataDir)+1]; 90 strcpy(this->dataDir, dataDir); 96 91 } 97 92 else … … 113 108 { 114 109 // check if the Directory has been added before 115 char* tmpDir = imageDirs->enumerate(); 110 tIterator<char>* tmpImageDirs = imageDirs->getIterator(); 111 char* tmpDir = tmpImageDirs->nextElement(); 116 112 while(tmpDir) 117 113 { … … 119 115 { 120 116 PRINTF(4)("Path %s already loaded\n", imageDir); 117 delete tmpImageDirs; 121 118 return true; 122 119 } 123 tmpDir = imageDirs->nextElement(); 124 } 120 tmpDir = tmpImageDirs->nextElement(); 121 } 122 delete tmpImageDirs; 123 125 124 // adding the directory to the List 126 125 tmpDir = new char[strlen(imageDir)+1]; 127 126 strcpy(tmpDir, imageDir); 128 imageDirs->add(tmpDir);127 this->imageDirs->add(tmpDir); 129 128 return true; 130 129 } … … 162 161 tmpType = IMAGE; 163 162 164 return ResourceManager::load(fileName, tmpType, prio);163 return this->load(fileName, tmpType, prio); 165 164 } 166 165 … … 175 174 { 176 175 // searching if the resource was loaded before. 177 Resource* tmpResource = ResourceManager::locateResourceByName(fileName);176 Resource* tmpResource = this->locateResourceByName(fileName); 178 177 if (!tmpResource) // if the resource was not loaded before. 179 178 { … … 189 188 // creating the full name. (directoryName + FileName) 190 189 char* fullName = new char[strlen(dataDir)+strlen(fileName)+1]; 191 sprintf(fullName, "%s%s", dataDir, fileName);190 sprintf(fullName, "%s%s", this->dataDir, fileName); 192 191 193 192 // Checking for the type of resource \see ResourceType … … 251 250 tmpResource->pointer = NULL; 252 251 } 253 resourceList->add(tmpResource);252 this->resourceList->add(tmpResource); 254 253 delete []fullName; 255 254 } … … 274 273 { 275 274 // if pointer is existent. and only one resource of this type exists. 276 Resource* tmpResource = ResourceManager::locateResourceByPointer(pointer);275 Resource* tmpResource = this->locateResourceByPointer(pointer); 277 276 if (!tmpResource) 278 277 { … … 310 309 PRINTF(4)("Resource %s safely removed.\n", resource->name); 311 310 delete []resource->name; 312 resourceList->remove(resource);311 this->resourceList->remove(resource); 313 312 } 314 313 else … … 327 326 bool ResourceManager::unloadAllByPriority(ResourcePriority prio) 328 327 { 329 330 328 tIterator<Resource>* iterator = resourceList->getIterator(); 331 329 Resource* enumRes = iterator->nextElement(); -
orxonox/trunk/src/lib/util/resource_manager.h
r3660 r3672 56 56 virtual ~ResourceManager(); 57 57 58 staticbool setDataDir(char* dataDir);59 staticbool addImageDir(char* imageDir);60 staticvoid* load(const char* fileName, ResourcePriority prio = RP_NO);61 staticvoid* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO);62 staticbool unload(void* pointer, ResourcePriority prio = RP_NO);63 staticbool unload(Resource* resource, ResourcePriority = RP_NO);64 staticbool unloadAllByPriority(ResourcePriority prio);58 bool setDataDir(char* dataDir); 59 bool addImageDir(char* imageDir); 60 void* load(const char* fileName, ResourcePriority prio = RP_NO); 61 void* load(const char* fileName, ResourceType type, ResourcePriority prio = RP_NO); 62 bool unload(void* pointer, ResourcePriority prio = RP_NO); 63 bool unload(Resource* resource, ResourcePriority = RP_NO); 64 bool unloadAllByPriority(ResourcePriority prio); 65 65 66 66 private: … … 68 68 static ResourceManager* singletonRef; 69 69 70 static tList<Resource>* resourceList;71 static char* dataDir;72 static tList<char>* imageDirs;70 tList<Resource>* resourceList; //!< The List of Resources, that has already been loaded. 71 char* dataDir; //!< The Data Directory, where all relevant Data is stored. 72 tList<char>* imageDirs; //!< A list of directories in which images are stored. 73 73 74 static Resource* locateResourceByName(const char* fileName); 75 static Resource* locateResourceByPointer(const void* pointer); 74 75 Resource* locateResourceByName(const char* fileName); 76 Resource* locateResourceByPointer(const void* pointer); 76 77 77 staticbool isDir(const char* directory);78 staticbool isFile(const char* directory);78 bool isDir(const char* directory); 79 bool isFile(const char* directory); 79 80 }; 80 81
Note: See TracChangeset
for help on using the changeset viewer.