Changeset 9800 in orxonox.OLD for branches/new_class_id/src/lib/util/loading/new_resource_manager.cc
- Timestamp:
- Sep 24, 2006, 12:12:14 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/new_resource_manager.cc
r9799 r9800 22 22 #include <cassert> 23 23 24 ObjectListDefinition(NewResourceManager); 24 25 namespace Resources 26 { 27 ObjectListDefinition(NewResourceManager); 28 //! Singleton Reference to the NewResourceManager 29 NewResourceManager* NewResourceManager::_singletonRef = NULL; 25 30 26 31 27 //! Singleton Reference to the NewResourceManager 28 NewResourceManager* NewResourceManager::_singletonRef = NULL; 32 /** 33 * @brief standard constructor 34 */ 35 NewResourceManager::NewResourceManager () 36 { 37 this->registerObject(this, NewResourceManager::_objectList); 38 this->setName("NewResourceManager"); 39 40 //this->dataDir = "./"; 41 } 29 42 30 43 31 /**32 * @brief standard constructor33 */34 NewResourceManager::NewResourceManager ()35 {36 this->registerObject(this, NewResourceManager::_objectList);37 this->setName("NewResourceManager");44 /** 45 * @brief standard destructor 46 */ 47 NewResourceManager::~NewResourceManager () 48 { 49 // deleting the Resources-List 50 //this->unloadAllByPriority(RP_GAME); 38 51 39 //this->dataDir = "./";40 } 52 // if (!this->resourceList.empty()) 53 // PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 41 54 42 43 /** 44 * @brief standard destructor 45 */ 46 NewResourceManager::~NewResourceManager () 47 { 48 // deleting the Resources-List 49 //this->unloadAllByPriority(RP_GAME); 50 51 // if (!this->resourceList.empty()) 52 // PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 53 54 NewResourceManager::_singletonRef = NULL; 55 } 55 NewResourceManager::_singletonRef = NULL; 56 } 56 57 57 58 58 59 59 60 60 void NewResourceManager::registerType(Resources::Type* type) 61 { 62 if(type->id() == -1) 61 void NewResourceManager::registerType(Resources::Type* type) 63 62 { 64 type->setID(this->_resourceTypes.size()); 65 this->_resourceTypes.push_back(type); 66 PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id()); 63 if(type->id() == -1) 64 { 65 type->setID(this->_resourceTypes.size()); 66 this->_resourceTypes.push_back(type); 67 PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id()); 68 } 67 69 } 68 }69 70 70 void NewResourceManager::unregisterType(Resources::Type* type) 71 { 72 std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type); 73 if (it != this->_resourceTypes.end()) 71 void NewResourceManager::unregisterType(Resources::Type* type) 74 72 { 75 this->_resourceTypes.erase(it); 76 PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id()); 73 std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type); 74 if (it != this->_resourceTypes.end()) 75 { 76 this->_resourceTypes.erase(it); 77 PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id()); 78 } 77 79 } 78 }79 80 80 81 81 void NewResourceManager::setMainGlobalPath(const Directory& directory)82 {83 this->_mainGlobalPath = directory;84 this->_mainGlobalPath.open();85 }82 void NewResourceManager::setMainGlobalPath(const Directory& directory) 83 { 84 this->_mainGlobalPath = directory; 85 this->_mainGlobalPath.open(); 86 } 86 87 87 void NewResourceManager::addGlobalPath(const Directory& directory)88 {89 std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory);90 if (it == this->_globalPaths.end())91 this->_globalPaths.push_back(directory);92 }88 void NewResourceManager::addGlobalPath(const Directory& directory) 89 { 90 std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory); 91 if (it == this->_globalPaths.end()) 92 this->_globalPaths.push_back(directory); 93 } 93 94 94 95 95 bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)96 {97 std::vector<Resources::Type*>::iterator it;98 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)99 if (*(*it) == resourceName)100 return (*it)->addResourcePath(pathName);101 PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());102 return false;103 }96 bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName) 97 { 98 std::vector<Resources::Type*>::iterator it; 99 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 100 if (*(*it) == resourceName) 101 return (*it)->addResourcePath(pathName); 102 PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 103 return false; 104 } 104 105 105 bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)106 {107 std::vector<Resources::Type*>::iterator it;108 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)109 if (*(*it) == resourceName)110 return (*it)->addResourceSubPath(pathName);111 PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());112 return false;113 }106 bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName) 107 { 108 std::vector<Resources::Type*>::iterator it; 109 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 110 if (*(*it) == resourceName) 111 return (*it)->addResourceSubPath(pathName); 112 PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 113 return false; 114 } 114 115 115 116 116 117 117 bool NewResourceManager::checkFileInMainPath(const File& fileInside)118 {119 return (this->_mainGlobalPath + fileInside).exists();120 }118 bool NewResourceManager::checkFileInMainPath(const File& fileInside) 119 { 120 return (this->_mainGlobalPath + fileInside).exists(); 121 } 121 122 122 123 123 124 124 unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName)125 {126 this->_keepLevelNames.push_back(keepLevelName);127 return _keepLevelNames.size()-1;128 }125 unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName) 126 { 127 this->_keepLevelNames.push_back(keepLevelName); 128 return _keepLevelNames.size()-1; 129 } 129 130 130 unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const131 {132 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)133 if (this->_keepLevelNames[i] == keepLevelName)134 return i;131 unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const 132 { 133 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) 134 if (this->_keepLevelNames[i] == keepLevelName) 135 return i; 135 136 136 PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str());137 return 0;138 }137 PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str()); 138 return 0; 139 } 139 140 140 const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const141 {142 assert(keepLevelID < this->_keepLevelNames.size());143 return this->_keepLevelNames[keepLevelID];144 }141 const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const 142 { 143 assert(keepLevelID < this->_keepLevelNames.size()); 144 return this->_keepLevelNames[keepLevelID]; 145 } 145 146 146 147 147 /** 148 * @brief outputs debug information about the NewResourceManager 149 */ 150 void NewResourceManager::debug() const 151 { 152 PRINT(0)("=RM===================================\n"); 153 PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); 154 PRINT(0)("======================================\n"); 155 PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str()); 156 if(!this->_globalPaths.empty()) 148 /** 149 * @brief outputs debug information about the NewResourceManager 150 */ 151 void NewResourceManager::debug() const 157 152 { 158 PRINT(0)(" Additional Global search Paths are: "); 159 for (unsigned int i = 0; i < this->_globalPaths.size(); ++i) 160 PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str()); 153 PRINT(0)("=RM===================================\n"); 154 PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); 155 PRINT(0)("======================================\n"); 156 PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str()); 157 if(!this->_globalPaths.empty()) 158 { 159 PRINT(0)(" Additional Global search Paths are: "); 160 for (unsigned int i = 0; i < this->_globalPaths.size(); ++i) 161 PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str()); 162 PRINT(0)("\n"); 163 } 164 PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size()); 165 std::vector<Resources::Type*>::const_iterator it; 166 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 167 { 168 (*it)->debug(); 169 if (it != --this->_resourceTypes.end()) 170 PRINT(0)(" ------------------------------------\n "); 171 } 172 173 PRINT(0)("KeepLevels are: "); 174 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) 175 PRINT(0)("%d:'%s' ", i, this->_keepLevelNames[i].c_str()); 161 176 PRINT(0)("\n"); 177 PRINT(0)("==================================RM==\n"); 162 178 } 163 PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size());164 std::vector<Resources::Type*>::const_iterator it;165 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)166 {167 (*it)->debug();168 if (it != --this->_resourceTypes.end())169 PRINT(0)(" ------------------------------------\n ");170 }171 172 PRINT(0)("KeepLevels are: ");173 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)174 PRINT(0)("%d:'%s' ", i, this->_keepLevelNames[i].c_str());175 PRINT(0)("\n");176 PRINT(0)("==================================RM==\n");177 179 }
Note: See TracChangeset
for help on using the changeset viewer.