Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

less debug

File size: 2.8 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: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
17
18#include "resource.h"
19#include "filesys/file.h"
20
21ObjectListDefinition(Resource);
22
23
24std::vector<Resource::Type*>    Resource::_resourceTypes;
25
26//! GLOBALS
27Directory Resource::_mainGlobalPath;
28std::vector<Directory>        Resource::_globalPaths;
29
30
31/**
32 * standard constructor
33*/
34Resource::Resource (Resource::Type* type)
35    : _pointer(NULL), _type(type)
36{
37  this->registerObject(this, Resource::_objectList);
38
39  if(this->_type->id() == -1)
40  {
41    Resource::_resourceTypes.push_back(this->_type);
42    this->_type->setID(Resource::_resourceTypes.size()-1);
43  }
44
45}
46
47/**
48 * standard deconstructor
49 */
50Resource::~Resource ()
51{
52  // delete what has to be deleted here
53}
54
55
56std::string Resource::locateFile(const std::string& fileName)
57{
58  if (File(fileName).exists())
59    return fileName;
60  else if ((Resource::_mainGlobalPath+File(fileName)) . exists() )
61    return (Resource::_mainGlobalPath + File(fileName)).name();
62
63  return std::string("/home/bensch/svn/orxonox/data/") + fileName;
64
65}
66
67
68Resource::Pointer* Resource::acquireResource(const std::string& loadString)
69{
70  //const Resource::Type* const type = Resource::_resourceTypes[this->_type->id()];
71
72  for (unsigned int i = 0; i < _type->storedResources().size(); ++i)
73  {
74    if (_type->storedResources()[i]->loadString() == loadString)
75      return _type->storedResources()[i];
76  }
77
78  return NULL;
79}
80
81void Resource::setMainGlobalPath(const Directory& directory)
82{
83  Resource::_mainGlobalPath = directory;
84  Resource::_mainGlobalPath.open();
85}
86
87void Resource::addGlobalPath(const Directory& directory)
88{
89  std::vector<Directory>::const_iterator it = std::find(Resource::_globalPaths.begin(), Resource::_globalPaths.end(), directory);
90  if (it == Resource::_globalPaths.end())
91    Resource::_globalPaths.push_back(directory);
92}
93
94
95
96void Resource::addResource(Resource::Pointer* pointer)
97{
98  this->_type->addResource(pointer);
99}
100
101
102
103
104
105
106
107
108
109
110void Resource::KeepLevel::setKeepLevelName(unsigned int level, const std::string& name)
111{
112  if (_keepLevelName.size() <= level)
113    _keepLevelName.resize(level+1);
114  _keepLevelName[level] = name;
115}
116
117
118
119void Resource::Type::addResource(Resource::Pointer* resource)
120{
121  this->_storedResources.push_back(resource);
122
123}
124
125
126Resource::Pointer::Pointer(const std::string& loadString, const Resource::KeepLevel& keeplevel)
127  : _loadString(loadString), _keepLevel(keeplevel)
128{}
129
130
131void Resource::Type::setID(int id)
132{
133  this->_id = id;
134}
Note: See TracBrowser for help on using the repository browser.