[4597] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[3655] | 12 | main-programmer: Benjamin Grauer |
---|
[3672] | 13 | co-programmer: Patrick Boenzli |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3655] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD |
---|
[1853] | 17 | |
---|
[9790] | 18 | #include "new_resource_manager.h" |
---|
[4642] | 19 | #include "debug.h" |
---|
| 20 | |
---|
[6222] | 21 | #include <algorithm> |
---|
[6655] | 22 | #include <assert.h> |
---|
[6222] | 23 | |
---|
[9794] | 24 | ObjectListDefinition(NewResourceManager); |
---|
[1853] | 25 | |
---|
[9791] | 26 | |
---|
| 27 | //! Singleton Reference to the NewResourceManager |
---|
| 28 | NewResourceManager* NewResourceManager::_singletonRef = NULL; |
---|
| 29 | |
---|
| 30 | |
---|
[3245] | 31 | /** |
---|
[6647] | 32 | * @brief standard constructor |
---|
[3245] | 33 | */ |
---|
[9790] | 34 | NewResourceManager::NewResourceManager () |
---|
[3365] | 35 | { |
---|
[9794] | 36 | //this->registerObject(this, NewResourceManager::_objectList); |
---|
[9790] | 37 | this->setName("NewResourceManager"); |
---|
[4597] | 38 | |
---|
[9790] | 39 | //this->dataDir = "./"; |
---|
[3365] | 40 | } |
---|
[1853] | 41 | |
---|
[3655] | 42 | |
---|
[3245] | 43 | /** |
---|
[6647] | 44 | * @brief standard destructor |
---|
[3655] | 45 | */ |
---|
[9790] | 46 | NewResourceManager::~NewResourceManager () |
---|
[3655] | 47 | { |
---|
[3660] | 48 | // deleting the Resources-List |
---|
[9790] | 49 | //this->unloadAllByPriority(RP_GAME); |
---|
[5303] | 50 | |
---|
[9790] | 51 | // if (!this->resourceList.empty()) |
---|
| 52 | // PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); |
---|
[5303] | 53 | |
---|
[9791] | 54 | NewResourceManager::_singletonRef = NULL; |
---|
[3655] | 55 | } |
---|
[1853] | 56 | |
---|
[7661] | 57 | |
---|
[5480] | 58 | |
---|
[9791] | 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); |
---|
[9793] | 66 | PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id()); |
---|
[9791] | 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void NewResourceManager::setMainGlobalPath(const Directory& directory) |
---|
| 71 | { |
---|
| 72 | this->_mainGlobalPath = directory; |
---|
| 73 | this->_mainGlobalPath.open(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void NewResourceManager::addGlobalPath(const Directory& directory) |
---|
| 77 | { |
---|
| 78 | std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory); |
---|
| 79 | if (it == this->_globalPaths.end()) |
---|
| 80 | this->_globalPaths.push_back(directory); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName) |
---|
| 85 | { |
---|
| 86 | std::vector<Resources::Type*>::iterator it; |
---|
| 87 | for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) |
---|
| 88 | if (*(*it) == resourceName) |
---|
| 89 | return (*it)->addResourcePath(pathName); |
---|
| 90 | PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); |
---|
| 91 | return false; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName) |
---|
| 95 | { |
---|
| 96 | std::vector<Resources::Type*>::iterator it; |
---|
| 97 | for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) |
---|
| 98 | if (*(*it) == resourceName) |
---|
| 99 | return (*it)->addResourceSubPath(pathName); |
---|
| 100 | PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); |
---|
| 101 | return false; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
[5480] | 105 | /** |
---|
[9790] | 106 | * @brief outputs debug information about the NewResourceManager |
---|
[5480] | 107 | */ |
---|
[9790] | 108 | void NewResourceManager::debug() const |
---|
[5480] | 109 | { |
---|
[3676] | 110 | PRINT(0)("=RM===================================\n"); |
---|
| 111 | PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); |
---|
| 112 | PRINT(0)("======================================\n"); |
---|
[9791] | 113 | PRINT(0)("Listing %d Types: \n", this->_resourceTypes.size()); |
---|
| 114 | std::vector<Resources::Type*>::const_iterator it; |
---|
| 115 | for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) |
---|
[9793] | 116 | (*it)->debug(); |
---|
[3676] | 117 | |
---|
| 118 | PRINT(0)("==================================RM==\n"); |
---|
| 119 | } |
---|