Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/new_resource_manager.cc @ 9799

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

ResourceManager now cleans up too

File size: 5.2 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: Patrick Boenzli
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
17
18#include "new_resource_manager.h"
19#include "debug.h"
20
21#include <algorithm>
22#include <cassert>
23
24ObjectListDefinition(NewResourceManager);
25
26
27//! Singleton Reference to the NewResourceManager
28NewResourceManager* NewResourceManager::_singletonRef = NULL;
29
30
31/**
32 * @brief standard constructor
33*/
34NewResourceManager::NewResourceManager ()
35{
36  this->registerObject(this, NewResourceManager::_objectList);
37  this->setName("NewResourceManager");
38
39  //this->dataDir = "./";
40}
41
42
43/**
44 * @brief standard destructor
45*/
46NewResourceManager::~NewResourceManager ()
47{
48  // deleting the Resources-List
49  //this->unloadAllByPriority(RP_GAME);
50
51  //   if (!this->resourceList.empty())
52  //     PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());
53
54  NewResourceManager::_singletonRef = NULL;
55}
56
57
58
59
60void 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    PRINTF(5)("ResourceType '%s' with ID %d added\n", type->storedClassName().c_str(), type->id());
67  }
68}
69
70void NewResourceManager::unregisterType(Resources::Type* type)
71{
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  }
78}
79
80
81void NewResourceManager::setMainGlobalPath(const Directory& directory)
82{
83  this->_mainGlobalPath = directory;
84  this->_mainGlobalPath.open();
85}
86
87void NewResourceManager::addGlobalPath(const Directory& directory)
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}
93
94
95bool NewResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName)
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}
104
105bool NewResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName)
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}
114
115
116
117bool NewResourceManager::checkFileInMainPath(const File& fileInside)
118{
119  return (this->_mainGlobalPath + fileInside).exists();
120}
121
122
123
124unsigned int NewResourceManager::addKeepLevelName(const std::string& keepLevelName)
125{
126  this->_keepLevelNames.push_back(keepLevelName);
127  return _keepLevelNames.size()-1;
128}
129
130unsigned int NewResourceManager::getKeepLevelID(const std::string& keepLevelName) const
131{
132  for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
133    if (this->_keepLevelNames[i] == keepLevelName)
134      return i;
135
136  PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str());
137  return 0;
138}
139
140const std::string& NewResourceManager::getKeepLevelName(unsigned int keepLevelID) const
141{
142  assert(keepLevelID < this->_keepLevelNames.size());
143  return this->_keepLevelNames[keepLevelID];
144}
145
146
147/**
148 * @brief outputs debug information about the NewResourceManager
149 */
150void NewResourceManager::debug() const
151{
152  PRINT(0)("=RM===================================\n");
153  PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
154  PRINT(0)("======================================\n");
155  PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str());
156  if(!this->_globalPaths.empty())
157  {
158    PRINT(0)(" Additional Global search Paths are: ");
159    for (unsigned int i = 0; i < this->_globalPaths.size(); ++i)
160      PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str());
161    PRINT(0)("\n");
162  }
163  PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size());
164  std::vector<Resources::Type*>::const_iterator it;
165  for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it)
166  {
167    (*it)->debug();
168    if (it != --this->_resourceTypes.end())
169      PRINT(0)(" ------------------------------------\n ");
170  }
171
172  PRINT(0)("KeepLevels are: ");
173  for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i)
174    PRINT(0)("%d:'%s'  ", i, this->_keepLevelNames[i].c_str());
175  PRINT(0)("\n");
176  PRINT(0)("==================================RM==\n");
177}
Note: See TracBrowser for help on using the repository browser.