Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

modular KeepLevel implementation

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