/* 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: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD #include "resource.h" #include "new_resource_manager.h" #include "debug.h" namespace Resources { ObjectListDefinition(NewResource); /** * standard constructor */ NewResource::NewResource (Type* type) : _pointer(NULL), _type(type) { this->registerObject(this, NewResource::_objectList); } /** * standard deconstructor */ NewResource::~NewResource () { // delete what has to be deleted here } std::string NewResource::locateFile(const std::string& fileName) const { if ((NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); std::string locatedFile; locatedFile = locateFileInSubDir(NewResourceManager::getInstance()->mainGlobalPath(), fileName); if (!locatedFile.empty()) { printf("FILE found %s\n", locatedFile.c_str()); return locatedFile; } if (File(fileName).exists()) return fileName; return (NewResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); } /** * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. * @param directory the directory to in what to search for all subdirectories for. * @param fileName the Name of the File to query for * @return true on success. */ std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const { std::vector::const_iterator it; for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) { Directory dir = directory + (*it); File file = dir + File(fileName); printf("Testing %s (from %s in directory %s)\n", file.name().c_str(), fileName.c_str(), dir.name().c_str()); if ((dir+ File(fileName)).exists()) return (dir+File(fileName)).name(); } return ""; } StorePointer* NewResource::acquireResource(const std::string& loadString) { //const Type* const type = _resourceTypes[this->_type->id()]; for (unsigned int i = 0; i < _type->storedResources().size(); ++i) { if (_type->storedResources()[i]->loadString() == loadString) return _type->storedResources()[i]; } return NULL; } void NewResource::addResource(StorePointer* pointer) { this->_type->addResource(pointer); } /////////////////// //// KEEPLEVEL //// /////////////////// KeepLevel::KeepLevel(const std::string& keepLevelName) { this->_keepLevel = NewResourceManager::getInstance()->getKeepLevelID(keepLevelName); } const std::string& KeepLevel::name() const { return NewResourceManager::getInstance()->getKeepLevelName(this->_keepLevel); } /////////////////////// //// STORE POINTER //// /////////////////////// StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel) : _loadString(loadString), _keepLevel(keeplevel) {} ////////////// //// TYPE //// ////////////// Type::Type(const std::string& typeName) : _id(-1), _typeName(typeName) { NewResourceManager::getInstance()->registerType(this); PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str()); } Type::~Type() { NewResourceManager::getInstance()->unregisterType(this); } void Type::addResource(StorePointer* resource) { this->_storedResources.push_back(resource); } bool Type::addResourcePath(const std::string& path) { std::vector::const_iterator it; for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it) if ((*it) == path) return false; this->_resourcePaths.push_back(path); return true; } bool Type::addResourceSubPath(const std::string& subPath) { std::vector::const_iterator it; for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it) if ((*it) == subPath) return false; this->_resourceSubPaths.push_back(subPath); return true; } void Type::setID(int id) { this->_id = id; } void Type::debug() const { PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size()); PRINT(0)(" Paths:\n"); for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i) PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str()); PRINT(0)(" Sub-Paths:"); for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i) PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str()); PRINT(0)("\n"); } }