Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/resource_manager.cc @ 9836

Last change on this file since 9836 was 9836, checked in by bensch, 18 years ago

orxonox/new_class_id: Taken out the old ResourceManager.
On the way, i had to desintegrate the old MD3-model loading process (via ResourceManager) MD3 is untouched, but also not loaded anymore neither from ResourceMangers nor from the WorldEntity

@patrick: MD3-ModelLoading class must be implemented… this should be quite easy, with the way MD3 is, and the new Resource-paradigm
cheers

File size: 5.5 KB
RevLine 
[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
[9836]18#include "resource_manager.h"
[4642]19#include "debug.h"
20
[6222]21#include <algorithm>
[9797]22#include <cassert>
[6222]23
[1853]24
[9800]25namespace Resources
26{
[9836]27  ObjectListDefinition(ResourceManager);
28  //! Singleton Reference to the ResourceManager
29  ResourceManager* ResourceManager::_singletonRef = NULL;
[9791]30
31
[9800]32  /**
33   * @brief standard constructor
34  */
[9836]35  ResourceManager::ResourceManager ()
[9800]36  {
[9836]37    this->registerObject(this, ResourceManager::_objectList);
38    this->setName("ResourceManager");
[9802]39    this->_mainGlobalPath = Directory("./");
[9800]40  }
[4597]41
[1853]42
[9800]43  /**
44   * @brief standard destructor
45  */
[9836]46  ResourceManager::~ResourceManager ()
[9800]47  {
48    // deleting the Resources-List
49    //this->unloadAllByPriority(RP_GAME);
[3655]50
[9800]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
[9836]54    ResourceManager::_singletonRef = NULL;
[9800]55  }
[5303]56
[1853]57
[7661]58
[5480]59
[9836]60  void ResourceManager::registerType(Resources::Type* type)
[9791]61  {
[9800]62    if(type->id() == -1)
63    {
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());
67    }
[9791]68  }
69
[9836]70  void ResourceManager::unregisterType(Resources::Type* type)
[9799]71  {
[9800]72    std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type);
73    if (it != this->_resourceTypes.end())
74    {
75      this->_resourceTypes.erase(it);
76      PRINTF(5)("ResourceType '%s' with ID %d removed\n", type->storedClassName().c_str(), type->id());
77    }
[9799]78  }
79
80
[9836]81  void ResourceManager::setMainGlobalPath(const Directory& directory)
[9800]82  {
83    this->_mainGlobalPath = directory;
84    this->_mainGlobalPath.open();
85  }
[9791]86
[9836]87  void ResourceManager::addGlobalPath(const Directory& directory)
[9800]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  }
[9791]93
94
[9836]95  bool ResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)
[9800]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  }
[9791]104
[9836]105  bool ResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
[9800]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  }
[9791]114
115
[9795]116
[9836]117  bool ResourceManager::checkFileInMainPath(const File& fileInside)
[9800]118  {
119    return (this->_mainGlobalPath + fileInside).exists();
120  }
[9795]121
[9836]122  std::string ResourceManager::prependAbsoluteMainPath(const std::string& fileName)
[9833]123  {
124    return (this->_mainGlobalPath + File(fileName)).name();
125  }
[9795]126
[9798]127
[9836]128  unsigned int ResourceManager::addKeepLevelName(const std::string& keepLevelName)
[9800]129  {
130    this->_keepLevelNames.push_back(keepLevelName);
131    return _keepLevelNames.size()-1;
132  }
[9798]133
[9836]134  unsigned int ResourceManager::getKeepLevelID(const std::string& keepLevelName) const
[9800]135  {
136    for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
137      if (this->_keepLevelNames[i] == keepLevelName)
138        return i;
[9798]139
[9800]140    PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str());
141    return 0;
142  }
[9798]143
[9836]144  const std::string& ResourceManager::getKeepLevelName(unsigned int keepLevelID) const
[9800]145  {
146    assert(keepLevelID < this->_keepLevelNames.size());
147    return this->_keepLevelNames[keepLevelID];
148  }
[9798]149
150
[9800]151  /**
[9836]152   * @brief outputs debug information about the ResourceManager
[9800]153   */
[9836]154  void ResourceManager::debug() const
[9798]155  {
[9800]156    PRINT(0)("=RM===================================\n");
157    PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
158    PRINT(0)("======================================\n");
159    PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str());
160    if(!this->_globalPaths.empty())
161    {
162      PRINT(0)(" Additional Global search Paths are: ");
163      for (unsigned int i = 0; i < this->_globalPaths.size(); ++i)
164        PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str());
165      PRINT(0)("\n");
166    }
167    PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size());
168    std::vector<Resources::Type*>::const_iterator it;
169    for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
170    {
171      (*it)->debug();
172      if (it != --this->_resourceTypes.end())
173        PRINT(0)(" ------------------------------------\n ");
174    }
175
176    PRINT(0)("KeepLevels are: ");
177    for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
178      PRINT(0)("%d:'%s'  ", i, this->_keepLevelNames[i].c_str());
[9798]179    PRINT(0)("\n");
[9800]180    PRINT(0)("==================================RM==\n");
[9798]181  }
[3676]182}
Note: See TracBrowser for help on using the repository browser.