Changeset 9800 in orxonox.OLD for branches/new_class_id/src
- Timestamp:
- Sep 24, 2006, 12:12:14 PM (18 years ago)
- Location:
- branches/new_class_id/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/graphics/importer/resource_texture.h
r9791 r9800 12 12 13 13 14 class ResourceTexture : public Texture, public NewResource14 class ResourceTexture : public Texture, public Resources::NewResource 15 15 { 16 16 public: -
branches/new_class_id/src/lib/shell/some_shell_commands.cc
r9794 r9800 53 53 54 54 #include "loading/new_resource_manager.h" 55 SHELL_COMMAND(debug, NewResourceManager, debug); 56 55 namespace Resources 56 {SHELL_COMMAND(debug, NewResourceManager, debug);} 57 57 58 58 #include "loading/load_param_class_description.h" -
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 } -
branches/new_class_id/src/lib/util/loading/new_resource_manager.h
r9799 r9800 10 10 #include "filesys/directory.h" 11 11 12 class NewResourceManager : public BaseObject 12 namespace Resources 13 13 { 14 ObjectListDeclaration(NewResourceManager); 15 public: 16 /** @returns a Pointer to the only object of this Class */ 17 inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager(); return _singletonRef; }; 14 15 class NewResourceManager : public BaseObject 16 { 17 ObjectListDeclaration(NewResourceManager); 18 public: 19 /** @returns a Pointer to the only object of this Class */ 20 inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager(); return _singletonRef; }; 18 21 inline static void deleteInstance() { if (_singletonRef) delete _singletonRef; }; 19 22 20 23 21 void setMainGlobalPath(const Directory& directory);22 void addGlobalPath(const Directory& directory);24 void setMainGlobalPath(const Directory& directory); 25 void addGlobalPath(const Directory& directory); 23 26 24 bool addResourcePath(const std::string& resourceName, const std::string& pathName);25 bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);26 void registerType(Resources::Type* type);27 void unregisterType(Resources::Type* type);27 bool addResourcePath(const std::string& resourceName, const std::string& pathName); 28 bool addResourceSubPath(const std::string& resourceName, const std::string& pathName); 29 void registerType(Resources::Type* type); 30 void unregisterType(Resources::Type* type); 28 31 29 unsigned int addKeepLevelName(const std::string& keepLevelName);30 unsigned int getKeepLevelID(const std::string& keepLevelName) const;31 const std::string& getKeepLevelName(unsigned int keepLevelID) const;32 unsigned int addKeepLevelName(const std::string& keepLevelName); 33 unsigned int getKeepLevelID(const std::string& keepLevelName) const; 34 const std::string& getKeepLevelName(unsigned int keepLevelID) const; 32 35 33 36 const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; }; 34 const Directory& mainGlobalPath() const { return _mainGlobalPath; };35 /** @returns all global paths without mainGlobalPath */36 const std::vector<Directory>& globalPaths() const { return _globalPaths; };37 const Directory& mainGlobalPath() const { return _mainGlobalPath; }; 38 /** @returns all global paths without mainGlobalPath */ 39 const std::vector<Directory>& globalPaths() const { return _globalPaths; }; 37 40 38 41 39 bool checkFileInMainPath(const File& fileInside);42 bool checkFileInMainPath(const File& fileInside); 40 43 41 bool unloadAllByPriority();44 bool unloadAllByKeepLevel(const Resources::KeepLevel& keepLevel); 42 45 43 void debug() const;46 void debug() const; 44 47 45 // utility functions for handling files in and around the data-directory46 static std::string getFullName(const std::string& fileName);47 static bool isInDataDir(const std::string& fileName);48 private:49 NewResourceManager();50 virtual ~NewResourceManager();48 // utility functions for handling files in and around the data-directory 49 static std::string getFullName(const std::string& fileName); 50 static bool isInDataDir(const std::string& fileName); 51 private: 52 NewResourceManager(); 53 virtual ~NewResourceManager(); 51 54 52 private:53 static NewResourceManager* _singletonRef; //!< singleton Reference55 private: 56 static NewResourceManager* _singletonRef; //!< singleton Reference 54 57 55 std::vector<Resources::Type*> _resourceTypes;56 //! GLOBALS57 Directory _mainGlobalPath;58 std::vector<Directory> _globalPaths;58 std::vector<Resources::Type*> _resourceTypes; 59 //! GLOBALS 60 Directory _mainGlobalPath; 61 std::vector<Directory> _globalPaths; 59 62 60 std::vector<std::string> _keepLevelNames; 61 }; 63 std::vector<std::string> _keepLevelNames; 64 }; 65 66 } 62 67 63 68 #endif /* _RESOURCE_MANAGER_H */ -
branches/new_class_id/src/lib/util/loading/resource.cc
r9799 r9800 21 21 #include "debug.h" 22 22 23 ObjectListDefinition(NewResource); 23 24 namespace Resources 25 { 26 ObjectListDefinition(NewResource); 24 27 25 28 26 /**27 * standard constructor28 */29 NewResource::NewResource (Resources::Type* type)30 : _pointer(NULL), _type(type)31 {32 this->registerObject(this, NewResource::_objectList);33 }29 /** 30 * standard constructor 31 */ 32 NewResource::NewResource (Type* type) 33 : _pointer(NULL), _type(type) 34 { 35 this->registerObject(this, NewResource::_objectList); 36 } 34 37 35 /**36 * standard deconstructor37 */38 NewResource::~NewResource ()39 {40 // delete what has to be deleted here41 }38 /** 39 * standard deconstructor 40 */ 41 NewResource::~NewResource () 42 { 43 // delete what has to be deleted here 44 } 42 45 43 46 44 std::string NewResource::locateFile(const std::string& fileName) const 45 { 46 if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 47 std::string NewResource::locateFile(const std::string& fileName) const 48 { 49 if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 50 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 51 52 std::string locatedFile; 53 locatedFile = locateFileInSubDir(NewResourceManager::getInstance()->mainGlobalPath(), fileName); 54 if (!locatedFile.empty()) 55 { 56 printf("FILE found %s\n", locatedFile.c_str()); 57 return locatedFile; 58 } 59 60 if (File(fileName).exists()) 61 return fileName; 62 47 63 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 48 49 std::string locatedFile;50 locatedFile = locateFileInSubDir(NewResourceManager::getInstance()->mainGlobalPath(), fileName);51 if (!locatedFile.empty())52 {53 printf("FILE found %s\n", locatedFile.c_str());54 return locatedFile;55 64 } 56 65 57 if (File(fileName).exists()) 58 return fileName; 59 60 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 61 } 62 63 /** 64 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. 65 * @param directory the directory to in what to search for all subdirectories for. 66 * @param fileName the Name of the File to query for 67 * @return true on success. 68 */ 69 std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const 70 { 71 std::vector<Directory>::const_iterator it; 72 for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) 66 /** 67 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. 68 * @param directory the directory to in what to search for all subdirectories for. 69 * @param fileName the Name of the File to query for 70 * @return true on success. 71 */ 72 std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const 73 73 { 74 Directory dir = directory + (*it); 75 File file = dir + File(fileName); 76 printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); 77 if ((dir+ File(fileName)).exists()) 78 return (dir+File(fileName)).name(); 74 std::vector<Directory>::const_iterator it; 75 for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) 76 { 77 Directory dir = directory + (*it); 78 File file = dir + File(fileName); 79 printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); 80 if ((dir+ File(fileName)).exists()) 81 return (dir+File(fileName)).name(); 82 } 83 return ""; 79 84 } 80 return "";81 }82 85 83 86 84 87 85 Resources::StorePointer* NewResource::acquireResource(const std::string& loadString)86 {87 //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()];88 StorePointer* NewResource::acquireResource(const std::string& loadString) 89 { 90 //const Type* const type = _resourceTypes[this->_type->id()]; 88 91 89 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) 90 { 91 if (_type->storedResources()[i]->loadString() == loadString) 92 return _type->storedResources()[i]; 92 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) 93 { 94 if (_type->storedResources()[i]->loadString() == loadString) 95 return _type->storedResources()[i]; 96 } 97 98 return NULL; 93 99 } 94 100 95 return NULL;96 }97 101 98 99 void NewResource::addResource(Resources::StorePointer* pointer) 100 { 101 this->_type->addResource(pointer); 102 } 102 void NewResource::addResource(StorePointer* pointer) 103 { 104 this->_type->addResource(pointer); 105 } 103 106 104 107 … … 107 110 108 111 109 ///////////////////110 //// KEEPLEVEL ////111 ///////////////////112 Resources::KeepLevel::KeepLevel(const std::string& keepLevelName)113 {114 this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName);115 }112 /////////////////// 113 //// KEEPLEVEL //// 114 /////////////////// 115 KeepLevel::KeepLevel(const std::string& keepLevelName) 116 { 117 this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName); 118 } 116 119 117 const std::string& Resources::KeepLevel::name() const118 {119 return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);120 }120 const std::string& KeepLevel::name() const 121 { 122 return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel); 123 } 121 124 122 125 123 126 124 ///////////////////////125 //// STORE POINTER ////126 ///////////////////////127 Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel)128 : _loadString(loadString), _keepLevel(keeplevel)129 {}127 /////////////////////// 128 //// STORE POINTER //// 129 /////////////////////// 130 StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel) 131 : _loadString(loadString), _keepLevel(keeplevel) 132 {} 130 133 131 134 132 135 133 136 134 //////////////135 //// TYPE ////136 //////////////137 Resources::Type::Type(const std::string& typeName)138 : _id(-1), _typeName(typeName)139 {140 NewResourceManager::getInstance()->registerType(this);141 PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str());142 }137 ////////////// 138 //// TYPE //// 139 ////////////// 140 Type::Type(const std::string& typeName) 141 : _id(-1), _typeName(typeName) 142 { 143 NewResourceManager::getInstance()->registerType(this); 144 PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str()); 145 } 143 146 144 Resources::Type::~Type()145 {146 NewResourceManager::getInstance()->unregisterType(this);147 }147 Type::~Type() 148 { 149 NewResourceManager::getInstance()->unregisterType(this); 150 } 148 151 149 void Resources::Type::addResource(Resources::StorePointer* resource)150 {151 this->_storedResources.push_back(resource);152 void Type::addResource(StorePointer* resource) 153 { 154 this->_storedResources.push_back(resource); 152 155 153 }156 } 154 157 155 bool Resources::Type::addResourcePath(const std::string& path)156 {157 std::vector<Directory>::const_iterator it;158 for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)159 if ((*it) == path)160 return false;161 this->_resourcePaths.push_back(path);162 return true;158 bool Type::addResourcePath(const std::string& path) 159 { 160 std::vector<Directory>::const_iterator it; 161 for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it) 162 if ((*it) == path) 163 return false; 164 this->_resourcePaths.push_back(path); 165 return true; 163 166 164 }167 } 165 168 166 bool Resources::Type::addResourceSubPath(const std::string& subPath)167 {168 std::vector<Directory>::const_iterator it;169 for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)170 if ((*it) == subPath)171 return false;172 this->_resourceSubPaths.push_back(subPath);173 return true;174 }169 bool Type::addResourceSubPath(const std::string& subPath) 170 { 171 std::vector<Directory>::const_iterator it; 172 for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it) 173 if ((*it) == subPath) 174 return false; 175 this->_resourceSubPaths.push_back(subPath); 176 return true; 177 } 175 178 176 179 177 void Resources::Type::setID(int id)178 {179 this->_id = id;180 }180 void Type::setID(int id) 181 { 182 this->_id = id; 183 } 181 184 182 185 183 void Resources::Type::debug() const184 {185 PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size());186 PRINT(0)(" Paths:\n");187 for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i)188 PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str());189 PRINT(0)(" Sub-Paths:");190 for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i)191 PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str());192 PRINT(0)("\n");186 void Type::debug() const 187 { 188 PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size()); 189 PRINT(0)(" Paths:\n"); 190 for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i) 191 PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str()); 192 PRINT(0)(" Sub-Paths:"); 193 for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i) 194 PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str()); 195 PRINT(0)("\n"); 193 196 197 } 194 198 } -
branches/new_class_id/src/lib/util/loading/resource.h
r9799 r9800 30 30 class StorePointer 31 31 { 32 33 34 35 32 public: 33 StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel); 34 const std::string& loadString() const { return _loadString; }; 35 const Resources::KeepLevel& keepLevel() const { return _keepLevel; }; 36 36 37 38 39 37 private: 38 std::string _loadString; //!< An identifier, to match when loading a File. 39 Resources::KeepLevel _keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this) 40 40 }; 41 41 … … 73 73 std::vector<Resources::StorePointer*> _storedResources; 74 74 }; 75 76 77 //! A NewResource is an Object, that can be loaded from Disk 78 /** 79 * 80 */ 81 class NewResource : virtual public BaseObject 82 { 83 ObjectListDeclaration(NewResource); 84 85 public: 86 NewResource(Resources::Type* type); 87 virtual ~NewResource(); 88 89 virtual bool reload() { return false; }; 90 virtual bool unload() { return false; }; 91 92 std::string locateFile(const std::string& fileName) const; 93 94 95 public: 96 protected: 97 Resources::StorePointer* acquireResource(const std::string& loadString); 98 void addResource(Resources::StorePointer* pointer); 99 100 private: 101 std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const; 102 103 private: 104 Resources::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData. 105 Resources::Type* _type; //!< Type of the NewResource. 106 }; 75 107 } 76 108 77 //! A NewResource is an Object, that can be loaded from Disk78 /**79 *80 */81 class NewResource : virtual public BaseObject82 {83 ObjectListDeclaration(NewResource);84 85 public:86 NewResource(Resources::Type* type);87 virtual ~NewResource();88 89 virtual bool reload() { return false; };90 virtual bool unload() { return false; };91 92 std::string locateFile(const std::string& fileName) const;93 94 95 public:96 protected:97 Resources::StorePointer* acquireResource(const std::string& loadString);98 void addResource(Resources::StorePointer* pointer);99 100 private:101 std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const;102 103 private:104 Resources::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData.105 Resources::Type* _type; //!< Type of the NewResource.106 };107 108 109 #endif /* _RESOURCE_H */ -
branches/new_class_id/src/orxonox.cc
r9798 r9800 129 129 130 130 // handlers 131 NewResourceManager::deleteInstance(); // deletes the Resource Manager131 Resources::NewResourceManager::deleteInstance(); // deletes the Resource Manager 132 132 133 133 // engines … … 341 341 if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, ""))!= "") 342 342 { 343 NewResourceManager::getInstance()->setMainGlobalPath(dataPath) ;344 if(! NewResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE)))343 Resources::NewResourceManager::getInstance()->setMainGlobalPath(dataPath) ; 344 if(!Resources::NewResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE))) 345 345 { 346 346 PRINTF(1)("Data Could not be located in %s\n", dataPath.c_str()); 347 347 } 348 348 } 349 while (! NewResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE)))349 while (!Resources::NewResourceManager::getInstance()->checkFileInMainPath(File(DEFAULT_DATA_DIR_CHECKFILE))) 350 350 { 351 351 352 352 PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \ 353 353 "!!! Please Change in File %s Section %s Entry %s to a suitable value !!!\n", 354 NewResourceManager::getInstance()->mainGlobalPath().name().c_str(),354 Resources::NewResourceManager::getInstance()->mainGlobalPath().name().c_str(), 355 355 this->configFileName.c_str(), 356 356 CONFIG_SECTION_GENERAL, … … 361 361 return(-1); 362 362 delete gui; 363 NewResourceManager::getInstance()->setMainGlobalPath(Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, ""));363 Resources::NewResourceManager::getInstance()->setMainGlobalPath(Preferences::getInstance()->getString(CONFIG_SECTION_GENERAL, CONFIG_NAME_DATADIR, "")); 364 364 } 365 365 … … 367 367 368 368 //! @todo this is a hack and should be loadable 369 NewResourceManager::getInstance()->addResourceSubPath("Texture", "maps");370 NewResourceManager::getInstance()->addResourceSubPath("Texture", "pictures");371 372 NewResourceManager::getInstance()->addKeepLevelName("Imediately");373 NewResourceManager::getInstance()->addKeepLevelName("LevelEnd");374 NewResourceManager::getInstance()->addKeepLevelName("CampaignEnd");375 NewResourceManager::getInstance()->addKeepLevelName("GameEnd");376 377 378 NewResourceManager::getInstance()->debug();369 Resources::NewResourceManager::getInstance()->addResourceSubPath("Texture", "maps"); 370 Resources::NewResourceManager::getInstance()->addResourceSubPath("Texture", "pictures"); 371 372 Resources::NewResourceManager::getInstance()->addKeepLevelName("Imediately"); 373 Resources::NewResourceManager::getInstance()->addKeepLevelName("LevelEnd"); 374 Resources::NewResourceManager::getInstance()->addKeepLevelName("CampaignEnd"); 375 Resources::NewResourceManager::getInstance()->addKeepLevelName("GameEnd"); 376 377 378 Resources::NewResourceManager::getInstance()->debug(); 379 379 // DynamicLoader::loadDyLib("libtest.so"); 380 380 return 0;
Note: See TracChangeset
for help on using the changeset viewer.