/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD #include "new_resource_manager.h" #include "debug.h" #include #include ObjectListDefinition(NewResourceManager); //! Singleton Reference to the NewResourceManager NewResourceManager* NewResourceManager::_singletonRef = NULL; /** * @brief standard constructor */ NewResourceManager::NewResourceManager () { this->registerObject(this, NewResourceManager::_objectList); this->setName("NewResourceManager"); //this->dataDir = "./"; } /** * @brief standard destructor */ NewResourceManager::~NewResourceManager () { // deleting the Resources-List //this->unloadAllByPriority(RP_GAME); // if (!this->resourceList.empty()) // PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size()); NewResourceManager::_singletonRef = NULL; } void NewResourceManager::registerType(Resources::Type* type) { if(type->id() == -1) { type->setID(this->_resourceTypes.size()); this->_resourceTypes.push_back(type); PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id()); } } void NewResourceManager::unregisterType(Resources::Type* type) { std::vector::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type); if (it != this->_resourceTypes.end()) { this->_resourceTypes.erase(it); PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id()); } } void NewResourceManager::setMainGlobalPath(const Directory& directory) { this->_mainGlobalPath = directory; this->_mainGlobalPath.open(); } void NewResourceManager::addGlobalPath(const Directory& directory) { std::vector::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory); if (it == this->_globalPaths.end()) this->_globalPaths.push_back(directory); } bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName) { std::vector::iterator it; for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) if (*(*it) == resourceName) return (*it)->addResourcePath(pathName); PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); return false; } bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName) { std::vector::iterator it; for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) if (*(*it) == resourceName) return (*it)->addResourceSubPath(pathName); PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); return false; } bool NewResourceManager::checkFileInMainPath(const File& fileInside) { return (this->_mainGlobalPath + fileInside).exists(); } unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName) { this->_keepLevelNames.push_back(keepLevelName); return _keepLevelNames.size()-1; } unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const { for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) if (this->_keepLevelNames[i] == keepLevelName) return i; PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str()); return 0; } const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const { assert(keepLevelID < this->_keepLevelNames.size()); return this->_keepLevelNames[keepLevelID]; } /** * @brief outputs debug information about the NewResourceManager */ void NewResourceManager::debug() const { PRINT(0)("=RM===================================\n"); PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n"); PRINT(0)("======================================\n"); PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str()); if(!this->_globalPaths.empty()) { PRINT(0)(" Additional Global search Paths are: "); for (unsigned int i = 0; i < this->_globalPaths.size(); ++i) PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str()); PRINT(0)("\n"); } PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size()); std::vector::const_iterator it; for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) { (*it)->debug(); if (it != --this->_resourceTypes.end()) PRINT(0)(" ------------------------------------\n "); } PRINT(0)("KeepLevels are: "); for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) PRINT(0)("%d:'%s' ", i, this->_keepLevelNames[i].c_str()); PRINT(0)("\n"); PRINT(0)("==================================RM==\n"); }