Changeset 9791 in orxonox.OLD
- Timestamp:
- Sep 23, 2006, 11:10:04 AM (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.cc
r9790 r9791 8 8 : NewResource(&ResourceTexture::type) 9 9 { 10 NewResource::StorePointer* ptr = this->acquireResource(imageName + ',' + "TEST");10 Resources::StorePointer* ptr = this->acquireResource(imageName + ',' + "TEST"); 11 11 12 12 if (ptr) … … 20 20 std::string fileName = this->NewResource::locateFile(imageName); 21 21 this->Texture::loadImage(fileName, target); 22 this->NewResource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + "TEST", KeepLevel(0), this->Texture::dataPointer()));22 this->NewResource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + "TEST", Resources::KeepLevel(0), this->Texture::dataPointer())); 23 23 } 24 24 } 25 25 26 26 27 NewResource::Type ResourceTexture::type(Texture::staticClassID());27 Resources::Type ResourceTexture::type(Texture::staticClassID()); 28 28 29 29 … … 31 31 32 32 33 ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const NewResource::KeepLevel& keepLevel, const TextureData::Pointer& data)34 : NewResource::StorePointer(loadString, keepLevel) , pointer(data)33 ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data) 34 : Resources::StorePointer(loadString, keepLevel) , pointer(data) 35 35 {} 36 36 -
branches/new_class_id/src/lib/graphics/importer/resource_texture.h
r9789 r9791 19 19 20 20 private: 21 class TextureResourcePointer : public NewResource::StorePointer21 class TextureResourcePointer : public Resources::StorePointer 22 22 { 23 23 public: 24 TextureResourcePointer(const std::string& loadString, const NewResource::KeepLevel& keepLevel, const TextureData::Pointer& data);24 TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data); 25 25 inline const TextureData::Pointer& ptr() const { return pointer; } 26 26 private: … … 29 29 30 30 private: 31 static NewResource::Type type;31 static Resources::Type type; 32 32 }; 33 33 -
branches/new_class_id/src/lib/util/loading/new_resource_manager.cc
r9790 r9791 22 22 #include <assert.h> 23 23 24 ObjectListDefinition(NewResourceManager); 24 //ObjectListDefinition(NewResourceManager); 25 26 27 //! Singleton Reference to the NewResourceManager 28 NewResourceManager* NewResourceManager::_singletonRef = NULL; 29 25 30 26 31 /** … … 29 34 NewResourceManager::NewResourceManager () 30 35 { 31 this->registerObject(this, NewResourceManager::_objectList);36 // this->registerObject(this, NewResourceManager::_objectList); 32 37 this->setName("NewResourceManager"); 33 38 34 39 //this->dataDir = "./"; 35 this->tryDataDir("./data");36 40 } 37 41 38 //! Singleton Reference to the NewResourceManager39 NewResourceManager* NewResourceManager::singletonRef = NULL;40 42 41 43 /** … … 50 52 // PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); 51 53 52 NewResourceManager:: singletonRef = NULL;54 NewResourceManager::_singletonRef = NULL; 53 55 } 54 56 57 58 59 60 void NewResourceManager::registerType(Resources::Type* type) 61 { 62 if(type->id() == -1) 63 { 64 type->setID(this->_resourceTypes.size()); 65 this->_resourceTypes.push_back(type); 66 } 67 } 68 69 void NewResourceManager::setMainGlobalPath(const Directory& directory) 70 { 71 this->_mainGlobalPath = directory; 72 this->_mainGlobalPath.open(); 73 } 74 75 void NewResourceManager::addGlobalPath(const Directory& directory) 76 { 77 std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory); 78 if (it == this->_globalPaths.end()) 79 this->_globalPaths.push_back(directory); 80 } 81 82 83 bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName) 84 { 85 std::vector<Resources::Type*>::iterator it; 86 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 87 if (*(*it) == resourceName) 88 return (*it)->addResourcePath(pathName); 89 PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 90 return false; 91 } 92 93 bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName) 94 { 95 std::vector<Resources::Type*>::iterator it; 96 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 97 if (*(*it) == resourceName) 98 return (*it)->addResourceSubPath(pathName); 99 PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 100 return false; 101 } 55 102 56 103 … … 63 110 PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); 64 111 PRINT(0)("======================================\n"); 112 PRINT(0)("Listing %d Types: \n", this->_resourceTypes.size()); 113 std::vector<Resources::Type*>::const_iterator it; 114 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 115 PRINT(0)("ResourceType '%s'\n", (*it)->storedClassID().name().c_str()); 65 116 66 117 PRINT(0)("==================================RM==\n"); -
branches/new_class_id/src/lib/util/loading/new_resource_manager.h
r9790 r9791 12 12 class NewResourceManager : public BaseObject 13 13 { 14 ObjectListDeclaration(NewResourceManager);14 // ObjectListDeclaration(NewResourceManager); 15 15 public: 16 16 virtual ~NewResourceManager(); 17 17 /** @returns a Pointer to the only object of this Class */ 18 inline static NewResourceManager* getInstance() { if (! singletonRef) singletonRef = new NewResourceManager(); returnsingletonRef; };18 inline static NewResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new NewResourceManager(); return _singletonRef; }; 19 19 20 bool tryDataDir(const std::string& dataDir); 20 21 void setMainGlobalPath(const Directory& directory); 22 void addGlobalPath(const Directory& directory); 23 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 28 29 const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; }; 30 const Directory& mainGlobalPath() const { return _mainGlobalPath; }; 31 /** @returns all global paths without mainGlobalPath */ 32 const std::vector<Directory>& globalPaths() const { return _globalPaths; }; 33 34 21 35 bool verifyDataDir(const std::string& fileInside); 22 36 … … 28 42 static std::string getFullName(const std::string& fileName); 29 43 static bool isInDataDir(const std::string& fileName); 30 31 44 private: 32 45 NewResourceManager(); 33 46 34 47 private: 35 static NewResourceManager* singletonRef; //!< singleton Reference 48 static NewResourceManager* _singletonRef; //!< singleton Reference 49 50 std::vector<Resources::Type*> _resourceTypes; 51 //! GLOBALS 52 Directory _mainGlobalPath; 53 std::vector<Directory> _globalPaths; 54 36 55 37 56 }; -
branches/new_class_id/src/lib/util/loading/resource.cc
r9790 r9791 17 17 18 18 #include "resource.h" 19 #include "filesys/file.h" 19 #include "new_resource_manager.h" 20 20 21 #include "debug.h" 21 22 22 23 ObjectListDefinition(NewResource); 23 std::vector<NewResource::Type*> NewResource::_resourceTypes;24 25 //! GLOBALS26 Directory NewResource::_mainGlobalPath;27 std::vector<Directory> NewResource::_globalPaths;28 24 29 25 … … 31 27 * standard constructor 32 28 */ 33 NewResource::NewResource ( NewResource::Type* type)29 NewResource::NewResource (Resources::Type* type) 34 30 : _pointer(NULL), _type(type) 35 31 { … … 50 46 if (File(fileName).exists()) 51 47 return fileName; 52 else if ((NewResource ::_mainGlobalPath+ File(fileName)).exists() )53 return (NewResource ::_mainGlobalPath+ File(fileName)).name();48 else if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 49 return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 54 50 55 51 printf("LOCATED %s\n", locateFileInSubDir(Directory("/home/bensch/svn/orxonox/data/"), fileName).c_str()); … … 80 76 81 77 82 NewResource::StorePointer* NewResource::acquireResource(const std::string& loadString)78 Resources::StorePointer* NewResource::acquireResource(const std::string& loadString) 83 79 { 84 //const NewResource::Type* const type = NewResource::_resourceTypes[this->_type->id()];80 //const Resources::Type* const type = Resources::_resourceTypes[this->_type->id()]; 85 81 86 82 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) … … 93 89 } 94 90 95 void NewResource::setMainGlobalPath(const Directory& directory)96 {97 NewResource::_mainGlobalPath = directory;98 NewResource::_mainGlobalPath.open();99 }100 91 101 void NewResource::addGlobalPath(const Directory& directory) 102 { 103 std::vector<Directory>::const_iterator it = std::find(NewResource::_globalPaths.begin(), NewResource::_globalPaths.end(), directory); 104 if (it == NewResource::_globalPaths.end()) 105 NewResource::_globalPaths.push_back(directory); 106 } 107 108 109 110 void NewResource::addResource(NewResource::StorePointer* pointer) 92 void NewResource::addResource(Resources::StorePointer* pointer) 111 93 { 112 94 this->_type->addResource(pointer); 113 }114 115 116 void NewResource::registerType(NewResource::Type* type)117 {118 NewResource::debug();119 if(type->id() == -1)120 {121 NewResource::_resourceTypes.push_back(type);122 type->setID(NewResource::_resourceTypes.size()-1);123 }124 NewResource::debug();125 }126 127 bool NewResource::addResourcePath(const std::string& resourceName, const std::string& pathName)128 {129 std::vector<NewResource::Type*>::iterator it;130 for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)131 if (*(*it) == resourceName)132 return (*it)->addResourcePath(pathName);133 PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());134 return false;135 }136 137 bool NewResource::addResourceSubPath(const std::string& resourceName, const std::string& pathName)138 {139 std::vector<NewResource::Type*>::iterator it;140 for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)141 if (*(*it) == resourceName)142 return (*it)->addResourceSubPath(pathName);143 PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str());144 return false;145 }146 147 148 149 void NewResource::debug()150 {151 PRINT(0)("==================================\n");152 PRINT(0)("DEBUG output for all Resources\n");153 PRINT(0)("==================================\n");154 155 PRINT(0)("Listing %d Types: \n", NewResource::_resourceTypes.size());156 std::vector<NewResource::Type*>::iterator it;157 for (it = NewResource::_resourceTypes.begin(); it != NewResource::_resourceTypes.end(); ++it)158 PRINT(0)("ResourceType '%s'\n", (*it)->storedClassID().name().c_str());159 160 PRINT(0)("==================================\n");161 162 95 } 163 96 … … 166 99 167 100 168 std::vector<std::string> NewResource::KeepLevel::_keepLevelNames; 169 void NewResource::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name) 101 102 /////////////////// 103 //// KEEPLEVEL //// 104 /////////////////// 105 std::vector<std::string> Resources::KeepLevel::_keepLevelNames; 106 void Resources::KeepLevel::defineKeepLevelName(unsigned int level, const std::string& name) 170 107 { 171 108 if (_keepLevelNames.size() <= level) … … 175 112 176 113 177 NewResource::Type::Type(const ClassID& classID) 114 /////////////////////// 115 //// STORE POINTER //// 116 /////////////////////// 117 Resources::StorePointer::StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel) 118 : _loadString(loadString), _keepLevel(keeplevel) 119 {} 120 121 122 123 124 ////////////// 125 //// TYPE //// 126 ////////////// 127 Resources::Type::Type(const ClassID& classID) 178 128 : _id(-1), _classID(classID) 179 129 { 180 NewResource ::registerType(this);130 NewResourceManager::getInstance()->registerType(this); 181 131 } 182 132 183 void NewResource::Type::addResource(NewResource::StorePointer* resource)133 void Resources::Type::addResource(Resources::StorePointer* resource) 184 134 { 185 135 this->_storedResources.push_back(resource); … … 187 137 } 188 138 189 bool NewResource::Type::addResourcePath(const std::string& path)139 bool Resources::Type::addResourcePath(const std::string& path) 190 140 { 191 141 std::vector<Directory>::const_iterator it; … … 198 148 } 199 149 200 bool NewResource::Type::addResourceSubPath(const std::string& subPath)150 bool Resources::Type::addResourceSubPath(const std::string& subPath) 201 151 { 202 152 std::vector<Directory>::const_iterator it; … … 209 159 210 160 211 212 NewResource::StorePointer::StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel) 213 : _loadString(loadString), _keepLevel(keeplevel) 214 {} 215 216 217 void NewResource::Type::setID(int id) 161 void Resources::Type::setID(int id) 218 162 { 219 163 this->_id = id; -
branches/new_class_id/src/lib/util/loading/resource.h
r9790 r9791 14 14 #include "filesys/directory.h" 15 15 16 //! A NewResource is an Object, that can be loaded from Disk 17 /** 18 * 19 */ 20 class NewResource : virtual public BaseObject 16 namespace Resources 21 17 { 22 ObjectListDeclaration(NewResource);23 public:24 18 class KeepLevel 25 19 { … … 35 29 }; 36 30 37 38 protected:39 31 class StorePointer 40 32 { 41 public:42 StorePointer(const std::string& loadString, const NewResource::KeepLevel& keeplevel);43 const std::string& loadString() const { return _loadString; };44 const NewResource::KeepLevel& keepLevel() const { return _keepLevel; };33 public: 34 StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel); 35 const std::string& loadString() const { return _loadString; }; 36 const Resources::KeepLevel& keepLevel() const { return _keepLevel; }; 45 37 46 private:47 std::string _loadString; //!< An identifier, to match when loading a File.48 NewResource::KeepLevel_keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this)38 private: 39 std::string _loadString; //!< An identifier, to match when loading a File. 40 Resources::KeepLevel _keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this) 49 41 }; 50 51 42 52 43 class Type … … 67 58 const std::vector<Directory>& resourcePaths() const { return _resourcePaths; }; 68 59 const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; }; 69 const std::vector< NewResource::StorePointer*>& storedResources() const { return _storedResources; };60 const std::vector<Resources::StorePointer*>& storedResources() const { return _storedResources; }; 70 61 71 62 void setID(int id); 72 void addResource( NewResource::StorePointer* resource);63 void addResource(Resources::StorePointer* resource); 73 64 74 65 private: … … 79 70 std::vector<std::string> _fileExtensions; 80 71 81 std::vector< NewResource::StorePointer*> _storedResources;72 std::vector<Resources::StorePointer*> _storedResources; 82 73 }; 74 } 83 75 76 //! A NewResource is an Object, that can be loaded from Disk 77 /** 78 * 79 */ 80 class NewResource : virtual public BaseObject 81 { 82 ObjectListDeclaration(NewResource); 84 83 85 84 public: 86 NewResource( NewResource::Type* type);85 NewResource(Resources::Type* type); 87 86 virtual ~NewResource(); 88 87 … … 94 93 95 94 public: 96 static void setMainGlobalPath(const Directory& directory);97 static void addGlobalPath(const Directory& directory);98 99 static bool addResourcePath(const std::string& resourceName, const std::string& pathName);100 static bool addResourceSubPath(const std::string& resourceName, const std::string& pathName);101 102 static void registerType(NewResource::Type* type);103 104 static void debug();105 95 protected: 106 NewResource::StorePointer* acquireResource(const std::string& loadString);107 void addResource( NewResource::StorePointer* pointer);96 Resources::StorePointer* acquireResource(const std::string& loadString); 97 void addResource(Resources::StorePointer* pointer); 108 98 109 99 private: … … 111 101 112 102 private: 113 NewResource::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData. 114 NewResource::Type* _type; //!< Type of the NewResource. 115 116 117 static std::vector<NewResource::Type*> _resourceTypes; 118 119 //! GLOBALS 120 static Directory _mainGlobalPath; 121 static std::vector<Directory> _globalPaths; 103 Resources::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData. 104 Resources::Type* _type; //!< Type of the NewResource. 122 105 }; 123 106 -
branches/new_class_id/src/orxonox.cc
r9790 r9791 327 327 328 328 //#include "util/loading/dynamic_loader.h" 329 #include "loading/ resource.h"329 #include "loading/new_resource_manager.h" 330 330 /** 331 331 * initializes and loads resource files … … 367 367 } 368 368 369 NewResource::debug();370 369 //! @todo this is a hack and should be loadable 371 NewResource ::addResourceSubPath("Texture", "maps");372 NewResource ::addResourceSubPath("Texture", "pictures");370 NewResourceManager::getInstance()->addResourceSubPath("Texture", "maps"); 371 NewResourceManager::getInstance()->addResourceSubPath("Texture", "pictures"); 373 372 374 373 // DynamicLoader::loadDyLib("libtest.so");
Note: See TracChangeset
for help on using the changeset viewer.