Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/resource.cc @ 9839

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

Font completely ported to the new Resource-Format.
Now all the Basic Resources previously loaded from a central ResourceManager are Distributed over the Resource-Types

File size: 4.8 KB
RevLine 
[4744]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:
[7195]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[9790]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
[1853]17
[7193]18#include "resource.h"
[9836]19#include "resource_manager.h"
[9791]20
[9790]21#include "debug.h"
[1853]22
[9785]23
[9800]24namespace Resources
[3365]25{
[9800]26  ObjectListDefinition(NewResource);
[1853]27
[9783]28
[9800]29  /**
30   * standard constructor
31  */
32  NewResource::NewResource (Type* type)
33      : _pointer(NULL), _type(type)
34  {
35    this->registerObject(this, NewResource::_objectList);
36  }
[9783]37
[9800]38  /**
39   * standard deconstructor
40   */
41  NewResource::~NewResource ()
42  {
43    // delete what has to be deleted here
44  }
45
46
47  std::string NewResource::locateFile(const std::string& fileName) const
48  {
[9836]49    if ((ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() )
50      return (ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name();
[9800]51
52    std::string locatedFile;
[9836]53    locatedFile = locateFileInSubDir(ResourceManager::getInstance()->mainGlobalPath(), fileName);
[9800]54    if (!locatedFile.empty())
55    {
56      return locatedFile;
57    }
58
59    if (File(fileName).exists())
60      return fileName;
61
[9836]62    return (ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name();
[9800]63  }
[9783]64
[9800]65  /**
66   * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists.
67   * @param directory the directory to in what to search for all subdirectories for.
68   * @param fileName the Name of the File to query for
69   * @return true on success.
70   */
71  std::string NewResource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const
[9793]72  {
[9800]73    std::vector<Directory>::const_iterator it;
74    for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it)
75    {
76      Directory dir = directory + (*it);
77      File file = dir + File(fileName);
78      if ((dir+ File(fileName)).exists())
79        return (dir+File(fileName)).name();
80    }
81    return "";
[9793]82  }
[9795]83
[9799]84
[9785]85
[9800]86  StorePointer* NewResource::acquireResource(const std::string& loadString)
[9790]87  {
[9800]88    //const Type* const type = _resourceTypes[this->_type->id()];
[9785]89
[9800]90    for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
91    {
92      if (_type->storedResources()[i]->loadString() == loadString)
93        return _type->storedResources()[i];
94    }
[9785]95
[9800]96    return NULL;
97  }
[9790]98
[9783]99
[9800]100  void NewResource::addResource(StorePointer* pointer)
[9786]101  {
[9800]102    this->_type->addResource(pointer);
[9786]103  }
[9783]104
105
106
[9784]107
[9785]108
109
[9800]110  ///////////////////
111  //// KEEPLEVEL ////
112  ///////////////////
113  KeepLevel::KeepLevel(const std::string& keepLevelName)
114  {
[9836]115    this->_keepLevel = ResourceManager::getInstance()->getKeepLevelID(keepLevelName);
[9800]116  }
[9785]117
[9800]118  const std::string& KeepLevel::name() const
119  {
[9836]120    return ResourceManager::getInstance()->getKeepLevelName(this->_keepLevel);
[9800]121  }
[9785]122
123
[9790]124
[9800]125  ///////////////////////
126  //// STORE POINTER ////
127  ///////////////////////
128  StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel)
129      : _loadString(loadString), _keepLevel(keeplevel)
130  {}
[9790]131
[9798]132
[9799]133
[9790]134
[9800]135  //////////////
136  //// TYPE ////
137  //////////////
138  Type::Type(const std::string& typeName)
139      : _id(-1), _typeName(typeName)
140  {
[9836]141    ResourceManager::getInstance()->registerType(this);
[9800]142    PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str());
143  }
[9790]144
[9800]145  Type::~Type()
146  {
[9836]147    ResourceManager::getInstance()->unregisterType(this);
[9800]148  }
[9790]149
[9800]150  void Type::addResource(StorePointer* resource)
151  {
152    this->_storedResources.push_back(resource);
[9785]153
[9800]154  }
[9785]155
[9800]156  bool Type::addResourcePath(const std::string& path)
157  {
158    std::vector<Directory>::const_iterator it;
159    for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it)
160      if ((*it) == path)
161        return false;
162    this->_resourcePaths.push_back(path);
163    return true;
[9799]164
[9800]165  }
[9785]166
[9800]167  bool Type::addResourceSubPath(const std::string& subPath)
168  {
169    std::vector<Directory>::const_iterator it;
170    for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it)
171      if ((*it) == subPath)
172        return false;
173    this->_resourceSubPaths.push_back(subPath);
174    return true;
175  }
[9785]176
177
[9800]178  void Type::setID(int id)
179  {
180    this->_id = id;
181  }
[9790]182
183
[9800]184  void Type::debug() const
185  {
186    PRINT(0)(" ResourceType '%s' with ID %d stores %d Resources\n", this->_typeName.c_str(), this->_id, this->_storedResources.size());
187    PRINT(0)("  Paths:\n");
188    for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i)
189      PRINT(0)("    %s\n", this->_resourcePaths[i].name().c_str());
190    PRINT(0)("  Sub-Paths:");
191    for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i)
192      PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str());
193    PRINT(0)("\n");
[9790]194
[9800]195  }
[9785]196}
Note: See TracBrowser for help on using the repository browser.